Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • uba-ki-lab/ubair
1 result
Show changes
Commits on Source (3)
......@@ -25,7 +25,7 @@ knitr::opts_chunk$set(
## Installation
Install via cran or if you have access to
[https://gitlab.ai-env.de/use-case-luft/ubair](https://gitlab.ai-env.de/use-case-luft/ubair)
[https://gitlab.opencode.de/uba-ki-lab/ubair](https://gitlab.opencode.de/uba-ki-lab/ubair)
you can use one of the following options:
#### Using an archive file
......@@ -41,7 +41,7 @@ Recommended if you do not have git installed.
- 'Install'
- alternatively, type in console:
```{r install_package_local}
install.packages("<path-to-zip>/ubair-master.zip", repos = NULL, type = "source")
remotes::install_local("<path-to-zip>/ubair-main.zip")
```
#### Using remote package
......@@ -49,9 +49,9 @@ Git needs to be installed.
```{r install_package_remote}
install.packages("remotes")
# requires a configures ssh-key
remotes::install_git("git@gitlab.ai-env.de:use-case-luft/ubair.git")
remotes::install_git("git@gitlab.opencode.de:uba-ki-lab/ubair.git")
# alternative via password
remotes::install_git("https://gitlab.ai-env.de/use-case-luft/ubair.git")
remotes::install_git("https://gitlab.opencode.de/uba-ki-lab/ubair.git")
```
## Sample Usage of package
......
<!-- README.md is generated from README.Rmd. Please edit that file -->
# ubair <img src="inst/sticker/stickers-ubair-1.png" align="right" width="20%"/>
**ubair** is an R package for Statistical Investigation of the Impact of External Conditions on Air Quality: it uses the statistical software R to analyze and visualize the impact of external factors, such as traffic restrictions, hazards, and political measures, on air quality. It aims to provide experts with a transparent comparison of modeling approaches and to support data-driven evaluations for policy advisory purposes.
**ubair** is an R package for Statistical Investigation of the Impact of
External Conditions on Air Quality: it uses the statistical software R
to analyze and visualize the impact of external factors, such as traffic
restrictions, hazards, and political measures, on air quality. It aims
to provide experts with a transparent comparison of modeling approaches
and to support data-driven evaluations for policy advisory purposes.
## Installation
Install via cran or if you have access to <https://gitlab.ai-env.de/use-case-luft/ubair> you can use one of the following options:
Install via cran or if you have access to
<https://gitlab.opencode.de/uba-ki-lab/ubair> you can use one of the
following options:
#### Using an archive file
Recommended if you do not have git installed.
- Download zip/tar.gz from GitLab
- Start a new R-Project or open an existing one
- in R-Studio:
- go to ‘Packages’-Tab (next to Help/Plots/Files)
- Click on ‘Install’ (left upper corner)
- Install from: choose “Package Archive File”
- Browse to zip-file
- ‘Install’
- alternatively, type in console:
- Download zip/tar.gz from GitLab
- Start a new R-Project or open an existing one
- in R-Studio:
- go to ‘Packages’-Tab (next to Help/Plots/Files)
- Click on ‘Install’ (left upper corner)
- Install from: choose “Package Archive File”
- Browse to zip-file
- ‘Install’
- alternatively, type in console:
``` r
install.packages("<path-to-zip>/ubair-master.zip", repos = NULL, type = "source")
remotes::install_local("<path-to-zip>/ubair-main.zip")
```
#### Using remote package
......@@ -33,17 +41,21 @@ Git needs to be installed.
``` r
install.packages("remotes")
# requires a configures ssh-key
remotes::install_git("git@gitlab.ai-env.de:use-case-luft/ubair.git")
remotes::install_git("git@gitlab.opencode.de:uba-ki-lab/ubair.git")
# alternative via password
remotes::install_git("https://gitlab.ai-env.de/use-case-luft/ubair.git")
remotes::install_git("https://gitlab.opencode.de/uba-ki-lab/ubair.git")
```
## Sample Usage of package
For a more detailed explanation of the package, you can access the vignettes:
For a more detailed explanation of the package, you can access the
vignettes:
- View user_sample source code directly in the [vignettes/](vignettes/) folder.
- Open vignette by function `vignette("user_sample_1", package = "ubair")`, if the package was installed with vignettes
- View user_sample source code directly in the [vignettes/](vignettes/)
folder.
- Open vignette by function
`vignette("user_sample_1", package = "ubair")`, if the package was
installed with vignettes
``` r
library(ubair)
......@@ -56,9 +68,10 @@ env_data <- sample_data_DESN025
plot_station_measurements(env_data, params$meteo_variables)
```
<img src="man/figures/README-plot-meteo-data-1.png" width="100%"/>
<img src="man/figures/README-plot-meteo-data-1.png" width="100%" />
- split data into training, reference and effect time intervals <img src="man/figures/time_split_overview.png" width="100%"/>
- split data into training, reference and effect time intervals
<img src="man/figures/time_split_overview.png" width="100%"/>
``` r
application_start <- lubridate::ymd("20191201") # This coincides with the start of the reference window
......@@ -83,13 +96,12 @@ res <- run_counterfactual(split_data,
)
```
```
#> [LightGBM] [Info] Auto-choosing col-wise multi-threading, the overhead of testing was 0.028078 seconds.
#> You can set `force_col_wise=true` to remove the overhead.
#> [LightGBM] [Info] Total Bins 1557
#> [LightGBM] [Info] Number of data points in the train set: 104486, number of used features: 9
#> [LightGBM] [Info] Start training from score -0.000000
```
#> [LightGBM] [Info] Auto-choosing row-wise multi-threading, the overhead of testing was 0.000597 seconds.
#> You can set `force_row_wise=true` to remove the overhead.
#> And if memory is not enough, you can set `force_col_wise=true`.
#> [LightGBM] [Info] Total Bins 1557
#> [LightGBM] [Info] Number of data points in the train set: 104486, number of used features: 9
#> [LightGBM] [Info] Start training from score -0.000000
``` r
predictions <- res$prediction
......@@ -102,26 +114,25 @@ plot_counterfactual(predictions, params,
)
```
<img src="man/figures/README-counterfactual-scenario-1.png" width="100%"/>
<img src="man/figures/README-counterfactual-scenario-1.png" width="100%" />
``` r
round(calc_performance_metrics(predictions, date_effect_start, buffer = buffer), 2)
```
```
#> RMSE MSE MAE MAPE Bias
#> 7.38 54.48 5.38 0.18 -2.73
#> R2 Coverage lower Coverage upper Coverage Correlation
#> 0.74 0.97 0.95 0.92 0.89
#> MFB FGE
#> -0.05 0.19
```
#> RMSE MSE MAE MAPE Bias
#> 7.38 54.48 5.38 0.18 -2.73
#> R2 Coverage lower Coverage upper Coverage Correlation
#> 0.74 0.97 0.95 0.92 0.89
#> MFB FGE
#> -0.05 0.19
``` r
round(calc_summary_statistics(predictions, date_effect_start, buffer = buffer), 2)
```
::: kable-table
<div class="kable-table">
| | true | prediction |
|:---------------------|-------:|-----------:|
| min | 3.36 | 5.58 |
......@@ -133,21 +144,20 @@ round(calc_summary_statistics(predictions, date_effect_start, buffer = buffer),
| median/50-percentile | 29.60 | 27.09 |
| 75-percentile | 40.54 | 36.27 |
| 95-percentile | 56.80 | 47.69 |
:::
</div>
``` r
estimate_effect_size(predictions, date_effect_start, buffer = buffer, verbose = TRUE)
```
```
#> The external effect changed the target value on average by -6.294 compared to the reference time window. This is a -26.37% relative change.
#> The external effect changed the target value on average by -6.294 compared to the reference time window. This is a -26.37% relative change.
#> $absolute_effect
#> [1] -6.294028
#>
#> $relative_effect
#> [1] -0.2637
```
#> $absolute_effect
#> [1] -6.294028
#>
#> $relative_effect
#> [1] -0.2637
### SHAP feature importances
......@@ -155,21 +165,23 @@ estimate_effect_size(predictions, date_effect_start, buffer = buffer, verbose =
shapviz::sv_importance(res$importance, kind = "bee")
```
<img src="man/figures/README-feature_importance-1.png" width="100%"/>
<img src="man/figures/README-feature_importance-1.png" width="100%" />
``` r
xvars <- c("TMP", "WIG", "GLO", "WIR")
shapviz::sv_dependence(res$importance, v = xvars)
```
<img src="man/figures/README-feature_importance-2.png" width="100%"/>
<img src="man/figures/README-feature_importance-2.png" width="100%" />
## Development
### Prerequisites
1. **R**: Make sure you have R installed (recommended version 4.4.1). You can download it from [CRAN](https://cran.r-project.org/).
2. **RStudio** (optional but recommended): Download from [RStudio](https://www.rstudio.com/).
1. **R**: Make sure you have R installed (recommended version 4.4.1).
You can download it from [CRAN](https://cran.r-project.org/).
2. **RStudio** (optional but recommended): Download from
[RStudio](https://www.rstudio.com/).
### Setting Up the Environment
......@@ -186,13 +198,12 @@ devtools::load_all()
#### Install pre-commit hook (required to ensure tidyverse code formatting)
```
pip install pre-commit
```
pip install pre-commit
#### Add new requirements
If you add new dependencies to *ubair* package, make sure to update the renv.lock file:
If you add new dependencies to *ubair* package, make sure to update the
renv.lock file:
``` r
renv::snapshot()
......@@ -200,7 +211,8 @@ renv::snapshot()
#### style and documentation
Before you commit your changes update documentation, ensure style complies with tidyverse styleguide and all tests run without error
Before you commit your changes update documentation, ensure style
complies with tidyverse styleguide and all tests run without error
``` r
# update documentation and check package integrity
......@@ -217,9 +229,13 @@ devtools::build_readme()
#### Pre-commit hook
in .pre-commit-hook.yaml pre-commit rules are defined and applied before each commmit. This includes: split - run styler to format code in tidyverse style - run roxygen to update doc - check if readme is up to date - run lintr to finally check code style format
in .pre-commit-hook.yaml pre-commit rules are defined and applied before
each commmit. This includes: split - run styler to format code in
tidyverse style - run roxygen to update doc - check if readme is up to
date - run lintr to finally check code style format
If precommit fails, check the automatically applied changes, stage them and retry to commit.
If precommit fails, check the automatically applied changes, stage them
and retry to commit.
#### Test Coverage
......@@ -240,8 +256,8 @@ covr::report(cov)
## Contacts
**Jore Noa Averbeck** [JoreNoa.Averbeck\@uba.de](mailto:JoreNoa.Averbeck@uba.de){.email}
**Jore Noa Averbeck** <JoreNoa.Averbeck@uba.de>
**Raphael Franke** [Raphael.Franke\@uba.de](mailto:Raphael.Franke@uba.de){.email}
**Raphael Franke** <Raphael.Franke@uba.de>
**Imke Voß** [imke.voss\@uba.de](mailto:imke.voss@uba.de){.email}
**Imke Voß** <imke.voss@uba.de>

Consent

On this website, we use the web analytics service Matomo to analyze and review the use of our website. Through the collected statistics, we can improve our offerings and make them more appealing for you. Here, you can decide whether to allow us to process your data and set corresponding cookies for these purposes, in addition to technically necessary cookies. Further information on data protection—especially regarding "cookies" and "Matomo"—can be found in our privacy policy. You can withdraw your consent at any time.