Skip to contents

Get daily PM2.5 model predictions

Usage

predict_pm25(x, dates, keep_predictors = FALSE)

Arguments

x

a vector of s2 cell identifers (s2_cell object)

dates

a list of date vectors for the predictions, must be the same length as x

keep_predictors

logical; return values for model predictors alongside PM2.5 estimates?

Value

a list of tibbles the same length as x, each containing columns for the predicted (pm25) and its standard error (pm25_se); with one row per date in dates. These numerics are the concentrations of fine particulate matter, measured in micrograms per cubic meter. See vignette("cv-model-performance")

for more details on the cross validated accuracy of the daily PM2.5 model predictions.

Details

Internally, loading the model file is cached, so repeated calls in the same R session will not require the overhead of loading the model file for a new prediction.

Examples

d <- list(
  "8841b39a7c46e25f" = as.Date(c("2023-05-18", "2023-11-06")),
  "8841a45555555555" = as.Date(c("2023-06-22", "2023-08-15"))
)

predict_pm25(x = s2::as_s2_cell(names(d)), dates = d)
#>  (down)loading random forest model
#> loaded rf_pm_v2 in 17s
#>  (down)loading random forest model [18.1s]
#> 
#>  checking that s2 are within the contiguous US
#>  checking that s2 are within the contiguous US [65ms]
#> 
#>  adding coordinates
#>  adding coordinates [23ms]
#> 
#>  adding elevation
#>  adding elevation [112ms]
#> 
#>  adding HMS smoke data
#>  adding HMS smoke data [10.2s]
#> 
#>  adding NARR
#>  adding NARR [684ms]
#> 
#>  adding gridMET
#>  adding gridMET [485ms]
#> 
#>  adding MERRA
#>  adding MERRA [855ms]
#> 
#>  adding time components
#>  adding time components [17ms]
#> 
#> [[1]]
#> # A tibble: 2 × 2
#>    pm25 pm25_se
#>   <dbl>   <dbl>
#> 1  7.97    1.01
#> 2  9.09    1.08
#> 
#> [[2]]
#> # A tibble: 2 × 2
#>    pm25 pm25_se
#>   <dbl>   <dbl>
#> 1  5.27   0.586
#> 2  5.68   0.567
#> 

# takes less time after called once because model file is cached in memory

d <- list(
  "8841b39a7c46e25f" = as.Date(c("2023-05-13", "2023-11-16")),
  "8841a45555555555" = as.Date(c("2023-06-21", "2023-08-25"))
)
predict_pm25(x = s2::as_s2_cell(names(d)), dates = d)
#>  (down)loading random forest model
#> loaded rf_pm_v2 in 0s
#>  (down)loading random forest model [7ms]
#> 
#>  checking that s2 are within the contiguous US
#>  checking that s2 are within the contiguous US [57ms]
#> 
#>  adding coordinates
#>  adding coordinates [37ms]
#> 
#>  adding elevation
#>  adding elevation [144ms]
#> 
#>  adding HMS smoke data
#>  adding HMS smoke data [1.6s]
#> 
#>  adding NARR
#>  adding NARR [645ms]
#> 
#>  adding gridMET
#>  adding gridMET [341ms]
#> 
#>  adding MERRA
#>  adding MERRA [515ms]
#> 
#>  adding time components
#>  adding time components [16ms]
#> 
#> [[1]]
#> # A tibble: 2 × 2
#>    pm25 pm25_se
#>   <dbl>   <dbl>
#> 1  8.33   0.681
#> 2 15.5    2.67 
#> 
#> [[2]]
#> # A tibble: 2 × 2
#>    pm25 pm25_se
#>   <dbl>   <dbl>
#> 1  10.5    1.15
#> 2  16.5    1.22
#>