diff --git a/articles/preprocessing-and-models.html b/articles/preprocessing-and-models.html index 1ad7c1277..58f1e4b36 100644 --- a/articles/preprocessing-and-models.html +++ b/articles/preprocessing-and-models.html @@ -254,7 +254,7 @@

End aside#> An `epi_df` object, 5 x 3 with metadata: #> * geo_type = state #> * time_type = day -#> * as_of = 2023-09-14 20:55:43.763975 +#> * as_of = 2023-10-04 21:31:33.762729 #> #> # A tibble: 5 × 3 #> geo_value time_value .pred @@ -410,23 +410,23 @@

Linear Regressionglimpse(slice_sample(bake(prep(r, jhu), jhu), n = 6))
#> Rows: 6
 #> Columns: 17
-#> $ time_value          <date> 2021-08-02, 2021-08-27, 2021-10-07, 2021-11-24, 2…
-#> $ geo_value           <chr> "tx", "nj", "nj", "tx", "ca", "ny"
-#> $ case_rate           <dbl> 32.01795, 22.27205, 19.09561, 11.24046, 18.86626, …
-#> $ death_rate          <dbl> 0.1420750, 0.1399240, 0.1994320, 0.2758784, 0.2696…
-#> $ masking             <fct> "[42.7,52.8]", "(60.2,63.9]", "(60.2,63.9]", "(52.…
-#> $ distancing          <fct> "(18.4,19.8]", "(21.1,27]", "(18.4,19.8]", "[13.9,…
-#> $ geo_value_factor_fl <dbl> 0, 0, 0, 0, 0, 0
-#> $ geo_value_factor_nj <dbl> 0, 1, 1, 0, 0, 0
-#> $ geo_value_factor_ny <dbl> 0, 0, 0, 0, 0, 1
-#> $ geo_value_factor_tx <dbl> 1, 0, 0, 1, 0, 0
-#> $ lag_0_case_rate     <dbl> 5.076291, -4.669617, -7.846053, -15.701198, -8.075…
-#> $ lag_7_case_rate     <dbl> -9.264035, -5.065264, -6.112282, -16.196514, -5.30…
-#> $ lag_14_case_rate    <dbl> -15.8578696, -9.9223972, -2.3391581, -16.2364118, …
-#> $ lag_0_death_rate    <dbl> -0.139798604, -0.141949604, -0.082441604, -0.00599…
-#> $ lag_7_death_rate    <dbl> -0.1855351035, -0.1885909035, -0.0583168035, 0.159…
-#> $ lag_14_death_rate   <dbl> -0.195266304, -0.209499104, -0.056708504, 0.006655…
-#> $ ahead_7_death_rate  <dbl> 0.1936501, 0.1656572, 0.1962153, 0.1571583, 0.2405…
+#> $ time_value <date> 2021-11-25, 2021-12-13, 2021-08-21, 2021-11-09, 2… +#> $ geo_value <chr> "tx", "fl", "ny", "fl", "ca", "ny" +#> $ case_rate <dbl> 11.129043, 8.534627, 23.356678, 6.900533, 21.08597… +#> $ death_rate <dbl> 0.2087334, 0.1866785, 0.1145116, 0.4916745, 0.0729… +#> $ masking <fct> "(52.8,60.2]", "[42.7,52.8]", "(52.8,60.2]", "(52.… +#> $ distancing <fct> "[13.9,18.4]", "[13.9,18.4]", "(19.8,21.1]", "[13.… +#> $ geo_value_factor_fl <dbl> 0, 1, 0, 1, 0, 0 +#> $ geo_value_factor_nj <dbl> 0, 0, 0, 0, 0, 0 +#> $ geo_value_factor_ny <dbl> 0, 0, 1, 0, 0, 1 +#> $ geo_value_factor_tx <dbl> 1, 0, 0, 0, 0, 0 +#> $ lag_0_case_rate <dbl> -15.81261965, -18.40703535, -3.58498415, -20.04112… +#> $ lag_7_case_rate <dbl> -15.771262, -14.087794, -5.969042, -18.954582, -11… +#> $ lag_14_case_rate <dbl> -15.960047, -26.941662, -10.178638, -17.368472, -1… +#> $ lag_0_death_rate <dbl> -0.0731402, -0.0951951, -0.1673620, 0.2098009, -0.… +#> $ lag_7_death_rate <dbl> 0.0874240, -0.1168866, -0.1873092, 0.2025703, -0.2… +#> $ lag_14_death_rate <dbl> 0.0835315, -0.0248620, -0.2168605, 0.2374082, -0.1… +#> $ ahead_7_death_rate <dbl> 0.2082469, 0.1255479, 0.1086014, 0.2813324, 0.1114…

Before directly predicting the results, we need to add postprocessing layers to obtain the death counts instead of death rates. Note that the rates used so far are “per 100K people” rather than “per person”. We’ll diff --git a/articles/sliding_files/figure-html/plot-arx-1.png b/articles/sliding_files/figure-html/plot-arx-1.png index 063fc1ecb..a894f063a 100644 Binary files a/articles/sliding_files/figure-html/plot-arx-1.png and b/articles/sliding_files/figure-html/plot-arx-1.png differ diff --git a/pkgdown.yml b/pkgdown.yml index ea8301dad..fe0a86d80 100644 --- a/pkgdown.yml +++ b/pkgdown.yml @@ -5,7 +5,7 @@ articles: sliding: sliding.html epipredict: epipredict.html preprocessing-and-models: preprocessing-and-models.html -last_built: 2023-09-14T20:45Z +last_built: 2023-10-04T21:21Z urls: reference: https://cmu-delphi.github.io/epipredict/reference article: https://cmu-delphi.github.io/epipredict/articles diff --git a/reference/smooth_quantile_reg-1.png b/reference/smooth_quantile_reg-1.png index 359ad7897..97e3342a2 100644 Binary files a/reference/smooth_quantile_reg-1.png and b/reference/smooth_quantile_reg-1.png differ diff --git a/reference/step_training_window.html b/reference/step_training_window.html index 0070b0f2a..d3885cbc1 100644 --- a/reference/step_training_window.html +++ b/reference/step_training_window.html @@ -142,7 +142,7 @@

Examples#> An `epi_df` object, 6 x 4 with metadata: #> * geo_type = state #> * time_type = day -#> * as_of = 2023-09-14 20:46:07.790956 +#> * as_of = 2023-10-04 21:22:11.340354 #> #> # A tibble: 6 × 4 #> time_value geo_value x y @@ -162,7 +162,7 @@

Examples#> An `epi_df` object, 6 x 4 with metadata: #> * geo_type = state #> * time_type = day -#> * as_of = 2023-09-14 20:46:07.790956 +#> * as_of = 2023-10-04 21:22:11.340354 #> #> # A tibble: 6 × 4 #> time_value geo_value x y diff --git a/search.json b/search.json index 0f382d93d..ad773fa8f 100644 --- a/search.json +++ b/search.json @@ -1 +1 @@ -[{"path":"https://cmu-delphi.github.io/epipredict/LICENSE.html","id":null,"dir":"","previous_headings":"","what":"MIT License","title":"MIT License","text":"Copyright (c) 2022 epipredict authors Permission hereby granted, free charge, person obtaining copy software associated documentation files (“Software”), deal Software without restriction, including without limitation rights use, copy, modify, merge, publish, distribute, sublicense, /sell copies Software, permit persons Software furnished , subject following conditions: copyright notice permission notice shall included copies substantial portions Software. SOFTWARE PROVIDED “”, WITHOUT WARRANTY KIND, EXPRESS IMPLIED, INCLUDING LIMITED WARRANTIES MERCHANTABILITY, FITNESS PARTICULAR PURPOSE NONINFRINGEMENT. EVENT SHALL AUTHORS COPYRIGHT HOLDERS LIABLE CLAIM, DAMAGES LIABILITY, WHETHER ACTION CONTRACT, TORT OTHERWISE, ARISING , CONNECTION SOFTWARE USE DEALINGS SOFTWARE.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/articles/epipredict.html","id":"goals-for-the-package","dir":"Articles","previous_headings":"","what":"Goals for the package","title":"Get started with epipredict","text":"high level, goal epipredict make running simple Machine Learning / Statistical forecasters epidemiology easy. However, package extremely extensible, part utility. hope easy users epi training statistics fit baseline models still allowing nuanced statistical understanding create complicated specializations using framework. Serving populations main motivation efforts, time, tried hard make useful.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/articles/epipredict.html","id":"baseline-models","dir":"Articles","previous_headings":"Goals for the package","what":"Baseline models","title":"Get started with epipredict","text":"provide set basic, easy--use forecasters work box. able reasonably limited amount customization . serious customization happens framework discussed ). basic forecasters, provide: Baseline flat-line forecaster Autoregressive forecaster Autoregressive classifier forcasters provide built framework. use basic models illustrate flexibility.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/articles/epipredict.html","id":"forecasting-framework","dir":"Articles","previous_headings":"Goals for the package","what":"Forecasting framework","title":"Get started with epipredict","text":"framework creating custom forecasters views prediction task set modular components. four types components: Preprocessor: make transformations data model training Trainer: train model data, resulting fitted model object Predictor: make predictions, using fitted model object processed test data Postprocessor: manipulate transform predictions returning Users familiar {tidymodels} especially {workflows} package notice lot overlap. design, fact feature. truth epipredict wrapper around much contained packages. Therefore, want something -verse, “just work” (hope). reason overlap workflows already implements first three steps. well. However, missing postprocessing stage currently plans implementation. feature important. baseline forecaster provide requires postprocessing. Anything complicated needs well. second omission tidymodels support panel data. Besides epidemiological data, economics, psychology, sociology, many areas frequently deal data type. framework behind epipredict implements . principle, nothing epidemiology, one simply use package solution missing functionality tidymodels. , “just work”. panel data functionality implemented epi_df data type companion {epiprocess} package. much see , moment, ’s enough look simple one: data built package contains measured variables case_rate death_rate COVID-19 daily level US state year 2021. “panel” part repeated measurements across number locations. epi_df encodes time stamp time_value key geo_value. 2 names required, values don’t need actually represent objects. Additional key’s also supported (like age group, ethnicity, taxonomy, etc.). epi_df also contains metadata describes keys well vintage data. ’s possible data collected different times set geo_value’s time_value’s actually different. details, see {epiprocess}.","code":"jhu <- case_death_rate_subset jhu #> An `epi_df` object, 20,496 x 4 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 20,496 × 4 #> geo_value time_value case_rate death_rate #> * #> 1 ak 2020-12-31 35.9 0.158 #> 2 al 2020-12-31 65.1 0.438 #> 3 ar 2020-12-31 66.0 1.27 #> 4 as 2020-12-31 0 0 #> 5 az 2020-12-31 76.8 1.10 #> 6 ca 2020-12-31 96.0 0.751 #> 7 co 2020-12-31 35.8 0.649 #> 8 ct 2020-12-31 52.1 0.819 #> 9 dc 2020-12-31 31.0 0.601 #> 10 de 2020-12-31 65.2 0.807 #> # ℹ 20,486 more rows"},{"path":"https://cmu-delphi.github.io/epipredict/articles/epipredict.html","id":"why-doesnt-this-package-already-exist","dir":"Articles","previous_headings":"Goals for the package","what":"Why doesn’t this package already exist?","title":"Get started with epipredict","text":"described : Parts actually exist. ’s universe called tidymodels. handles preprocessing, training, prediction, bound together, package called workflows. built epipredict top setup. way, CAN use almost everything provide. However, workflows doesn’t postprocessing. nothing -verse handles panel data. tidy-team doesn’t plans either things. (checked). two packages time series built tidymodels, ’s “basic” time series: 1-step AR models, exponential smoothing, STL decomposition, etc.1 group prioritized sorts models epidemic forecasting, one also integrate methods framework.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/articles/epipredict.html","id":"show-me-the-basics","dir":"Articles","previous_headings":"","what":"Show me the basics","title":"Get started with epipredict","text":"start jhu data displayed . One “canned” forecasters provide autoregressive forecaster (without) covariates directly trains response. contrast typical “iterative” AR model trains predict one-step-ahead, plugs predictions “leverage ” longer horizons. ’ll estimate model jointly across locations using recent 30 days. call produces warning, ’ll ignore now. essentially, ’s telling us data comes May 2022 ’re trying forecast January 2022. result likely accurate measure real-time forecast performance, data revised time. object two components: predictions just another epi_df. contains predictions location along additional columns. default, 90% predictive interval, forecast_date (date forecast putatively made) target_date (date forecast made). list object class epi_workflow. object encapsulates instructions necessary create prediction. details . Note time_value predictions necessarily meaningful, required column epi_df, remains . default, forecaster predicts outcome (death_rate) 1-week ahead, using 3 lags predictor (case_rate death_rate) 0 (today), 1 week back 2 weeks back. predictors outcome can changed directly. rest defaults encapsulated list arguments. list produced arx_args_list().","code":"jhu <- jhu %>% filter(time_value >= max(time_value) - 30) out <- arx_forecaster( jhu, outcome = \"death_rate\", predictors = c(\"case_rate\", \"death_rate\") ) #> Warning: The forecast_date is less than the most recent update date of the #> data: forecast_date = 2021-12-31 while data is from 2022-05-31. out$predictions #> # A tibble: 56 × 5 #> geo_value .pred .pred_distn forecast_date target_date #> #> 1 ak 0.355 [0.05, 0.95] 2021-12-31 2022-01-07 #> 2 al 0.325 [0.05, 0.95] 2021-12-31 2022-01-07 #> 3 ar 0.496 [0.05, 0.95] 2021-12-31 2022-01-07 #> 4 as 0.0836 [0.05, 0.95] 2021-12-31 2022-01-07 #> 5 az 0.614 [0.05, 0.95] 2021-12-31 2022-01-07 #> 6 ca 0.327 [0.05, 0.95] 2021-12-31 2022-01-07 #> 7 co 0.567 [0.05, 0.95] 2021-12-31 2022-01-07 #> 8 ct 0.544 [0.05, 0.95] 2021-12-31 2022-01-07 #> 9 dc 0.831 [0.05, 0.95] 2021-12-31 2022-01-07 #> 10 de 0.607 [0.05, 0.95] 2021-12-31 2022-01-07 #> # ℹ 46 more rows out$epi_workflow #> ══ Epi Workflow [trained] ══════════════════════════════════════════════════════ #> Preprocessor: Recipe #> Model: linear_reg() #> Postprocessor: Frosting #> #> ── Preprocessor ──────────────────────────────────────────────────────────────── #> 6 Recipe Steps #> #> • step_epi_lag() #> • step_epi_lag() #> • step_epi_ahead() #> • step_naomit() #> • step_naomit() #> • step_training_window() #> #> ── Model ─────────────────────────────────────────────────────────────────────── #> #> Call: #> stats::lm(formula = ..y ~ ., data = data) #> #> Coefficients: #> (Intercept) lag_0_case_rate lag_7_case_rate lag_14_case_rate #> 0.0829475 0.0009830 0.0027035 -0.0005651 #> lag_0_death_rate lag_7_death_rate lag_14_death_rate #> 0.2466110 0.1964921 0.0752998 #> #> ── Postprocessor ─────────────────────────────────────────────────────────────── #> 5 Frosting Layers #> #> • layer_predict() #> • layer_residual_quantiles() #> • layer_add_forecast_date() #> • layer_add_target_date() #> • layer_threshold()"},{"path":"https://cmu-delphi.github.io/epipredict/articles/epipredict.html","id":"simple-adjustments","dir":"Articles","previous_headings":"Show me the basics","what":"Simple adjustments","title":"Get started with epipredict","text":"Basic adjustments can made args_list. , ’ve used different lags case_rate now predicting 2 weeks ahead. example also illustrates major difficulty “iterative” versions AR models. model doesn’t produce forecasts case_rate, , data “plug ” necessary lags.2 Another property basic model predictive interval. describe detail different vignette, easy request multiple quantiles. column .pred_dstn predictions object actually “distribution” parameterized quantiles. default forecaster, created using quantiles residuals predictive model (possibly symmetrized). , used 23 quantiles, one can grab particular quantile, extract entire distribution “long” epi_df tau probability q value associated quantile. Additional simple adjustments basic forecaster can made using function:","code":"out2week <- arx_forecaster( jhu, outcome = \"death_rate\", predictors = c(\"case_rate\", \"death_rate\"), args_list = arx_args_list( lags = list(c(0, 1, 2, 3, 7, 14), c(0, 7, 14)), ahead = 14 ) ) out_q <- arx_forecaster(jhu, \"death_rate\", c(\"case_rate\", \"death_rate\"), args_list = arx_args_list( levels = c(.01, .025, seq(.05, .95, by = .05), .975, .99) ) ) head(quantile(out_q$predictions$.pred_distn, p = .4)) #> 40% 40% 40% 40% 40% 40% #> 0.30277798 0.27213225 0.44345734 0.03120647 0.56121844 0.27492711 out_q$predictions %>% # first create a \"nested\" list-column mutate(.pred_distn = nested_quantiles(.pred_distn)) %>% unnest(.pred_distn) # then unnest it #> # A tibble: 1,288 × 6 #> geo_value .pred q tau forecast_date target_date #> #> 1 ak 0.355 0 0.01 2021-12-31 2022-01-07 #> 2 ak 0.355 0 0.025 2021-12-31 2022-01-07 #> 3 ak 0.355 0.0371 0.05 2021-12-31 2022-01-07 #> 4 ak 0.355 0.123 0.1 2021-12-31 2022-01-07 #> 5 ak 0.355 0.174 0.15 2021-12-31 2022-01-07 #> 6 ak 0.355 0.211 0.2 2021-12-31 2022-01-07 #> 7 ak 0.355 0.237 0.25 2021-12-31 2022-01-07 #> 8 ak 0.355 0.260 0.3 2021-12-31 2022-01-07 #> 9 ak 0.355 0.282 0.35 2021-12-31 2022-01-07 #> 10 ak 0.355 0.303 0.4 2021-12-31 2022-01-07 #> # ℹ 1,278 more rows arx_args_list( lags = c(0L, 7L, 14L), ahead = 7L, n_training = Inf, forecast_date = NULL, target_date = NULL, levels = c(0.05, 0.95), symmetrize = TRUE, nonneg = TRUE, quantile_by_key = character(0L), nafill_buffer = Inf )"},{"path":"https://cmu-delphi.github.io/epipredict/articles/epipredict.html","id":"changing-the-engine","dir":"Articles","previous_headings":"Show me the basics","what":"Changing the engine","title":"Get started with epipredict","text":"far, forecasts produced using simple linear regression. way estimate model. trainer argument determines type model want. takes {parsnip} model. default linear regression, instead use random forest ranger package: boosted regression trees xgboost: quantile regression, using custom forecasting engine quantile_reg(): FWIW, last case (using quantile regression), far Delphi production forecast team used Covid forecasts past years.","code":"out_rf <- arx_forecaster( jhu, \"death_rate\", c(\"case_rate\", \"death_rate\"), rand_forest(mode = \"regression\") ) out_gb <- arx_forecaster( jhu, \"death_rate\", c(\"case_rate\", \"death_rate\"), boost_tree(mode = \"regression\", trees = 20) ) out_gb <- arx_forecaster( jhu, \"death_rate\", c(\"case_rate\", \"death_rate\"), quantile_reg() )"},{"path":"https://cmu-delphi.github.io/epipredict/articles/epipredict.html","id":"inner-workings","dir":"Articles","previous_headings":"Show me the basics","what":"Inner workings","title":"Get started with epipredict","text":"Underneath hood, forecaster creates (returns) epi_workflow. Essentially, big S3 object wraps 4 modular steps (preprocessing - postprocessing) described .","code":""},{"path":"https://cmu-delphi.github.io/epipredict/articles/epipredict.html","id":"preprocessing","dir":"Articles","previous_headings":"Show me the basics > Inner workings","what":"Preprocessing","title":"Get started with epipredict","text":"Preprocessing accomplished recipe (imagine baking cake) provided {recipes} package. ’ve made modifications (handle panel data) well added additional options. recipe gives specification handle training data. Think like fancified formula pass lm(): y ~ x1 + log(x2). general, 2 extensions formula recipes handles: transformations training test data can always applied. things like taking log variable, leading lagging, filtering rows, handling dummy variables, etc. Using statistics training data eventually process test data. major benefit recipes. prevents tidy team calls “data leakage”. simple example centering predictor mean. need store mean predictor training data use value test data rather accidentally calculating mean test predictor centering. recipe processed 2 steps, first “prepped”. calculates stores intermediate statistics necessary use test data. “baked” resulting training data ready passing statistical model (like lm). introduced epi_recipe. ’s just recipe knows handle time_value, geo_value, additional keys available necessary. epi_recipe out_gb can extracted result: “Inputs” original epi_df “roles” assigned. None predictors outcomes. created recipe prepped. “Operations” sequence instructions create cake (baked training data). create lagged predictors, lead outcome, remove NAs. models like lm internally handle NAs, everything , deal explicitly. code (inside forecaster) recipes provides function step_lag(), assumes data breaks sequence time_values. bit dangerous, avoid behaviour. lag/ahead functions also appropriately adjust amount data avoid accidentally dropping recent predictors test data.","code":"extract_recipe(out_gb$epi_workflow) er <- epi_recipe(jhu) %>% step_epi_lag(case_rate, death_rate, lag = c(0, 7, 14)) %>% step_epi_ahead(death_rate, ahead = 7) %>% step_epi_naomit()"},{"path":"https://cmu-delphi.github.io/epipredict/articles/epipredict.html","id":"the-model-specification","dir":"Articles","previous_headings":"Show me the basics > Inner workings","what":"The model specification","title":"Get started with epipredict","text":"Users familiarity parsnip package trouble . Basically, parsnip unifies function signature across statistical models. example, lm() “likes” work formulas, glmnet::glmnet() uses x y predictors response. parsnip agnostic. “linear regression”. switched lm() xgboost() without issue despite fact functions couldn’t different. epipredict provides engines/modules (flatline forecaster quantile regression), able use available models listed . estimate (fit) preprocessed model, one calls fit() epi_workflow.","code":"lm(formula, data, subset, weights, na.action, method = \"qr\", model = TRUE, x = FALSE, y = FALSE, qr = TRUE, singular.ok = TRUE, contrasts = NULL, offset, ... ) xgboost( data = NULL, label = NULL, missing = NA, weight = NULL, params = list(), nrounds, verbose = 1, print_every_n = 1L, early_stopping_rounds = NULL, maximize = NULL, save_period = NULL, save_name = \"xgboost.model\", xgb_model = NULL, callbacks = list(), ... ) ewf <- epi_workflow(er, linear_reg()) %>% fit(jhu)"},{"path":"https://cmu-delphi.github.io/epipredict/articles/epipredict.html","id":"postprocessing","dir":"Articles","previous_headings":"Show me the basics > Inner workings","what":"Postprocessing","title":"Get started with epipredict","text":"stretch metaphor preparing cake natural limits, created postprocessing functionality called “frosting”. Much like recipe, postprocessing operation “layer” “slather” onto baked cake. fix ideas, postprocessing frosting arx_forecaster() 5 layers frosting. first generates forecasts test data. second uses quantiles residuals create distributional forecasts. next two add columns date forecast made date intended occur. predicting rates, non-negative, last layer thresholds predicted values intervals 0. code (inside forecaster) predict time, add object onto epi_workflow call predict() get_test_data() function examines recipe ensures enough test data available create necessary lags produce prediction desired future time point (end training data). mimics happen jhu contained recent available historical data wanted actually predict future. instead used test data contained necessary predictors.","code":"extract_frosting(out_q$epi_workflow) f <- frosting() %>% layer_predict() %>% layer_residual_quantiles( probs = c(.01, .025, seq(.05, .95, by = .05), .975, .99), symmetrize = TRUE ) %>% layer_add_forecast_date() %>% layer_add_target_date() %>% layer_threshold(starts_with(\".pred\")) test_data <- get_test_data(er, jhu) ewf %>% add_frosting(f) %>% predict(test_data) #> An `epi_df` object, 56 x 6 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 56 × 6 #> geo_value time_value .pred .pred_distn forecast_date target_date #> * #> 1 ak 2021-12-31 0.355 [0.01, 0.99] 2021-12-31 2022-01-07 #> 2 al 2021-12-31 0.325 [0.01, 0.99] 2021-12-31 2022-01-07 #> 3 ar 2021-12-31 0.496 [0.01, 0.99] 2021-12-31 2022-01-07 #> 4 as 2021-12-31 0.0836 [0.01, 0.99] 2021-12-31 2022-01-07 #> 5 az 2021-12-31 0.614 [0.01, 0.99] 2021-12-31 2022-01-07 #> 6 ca 2021-12-31 0.327 [0.01, 0.99] 2021-12-31 2022-01-07 #> 7 co 2021-12-31 0.567 [0.01, 0.99] 2021-12-31 2022-01-07 #> 8 ct 2021-12-31 0.544 [0.01, 0.99] 2021-12-31 2022-01-07 #> 9 dc 2021-12-31 0.831 [0.01, 0.99] 2021-12-31 2022-01-07 #> 10 de 2021-12-31 0.607 [0.01, 0.99] 2021-12-31 2022-01-07 #> # ℹ 46 more rows"},{"path":"https://cmu-delphi.github.io/epipredict/articles/epipredict.html","id":"conclusion","dir":"Articles","previous_headings":"Show me the basics","what":"Conclusion","title":"Get started with epipredict","text":"Internally, provide simple functions create reasonable forecasts. ideally, user create forecasters building components provide. vignettes, try walk customizations. illustrate everything , (roughly) code flatline_forecaster() applied case_rate. really differs arx_forecaster() recipe, test data, engine. frosting identical, fitting predicting procedure.","code":"r <- epi_recipe(jhu) %>% step_epi_ahead(case_rate, ahead = 7, skip = TRUE) %>% update_role(case_rate, new_role = \"predictor\") %>% add_role(all_of(epi_keys(jhu)), new_role = \"predictor\") # bit of a weird hack to get the latest values per key latest <- get_test_data(epi_recipe(jhu), jhu) f <- frosting() %>% layer_predict() %>% layer_residual_quantiles() %>% layer_add_forecast_date() %>% layer_add_target_date() %>% layer_threshold(starts_with(\".pred\")) eng <- linear_reg() %>% set_engine(\"flatline\") wf <- epi_workflow(r, eng, f) %>% fit(jhu) preds <- predict(wf, latest) preds #> An `epi_df` object, 56 x 6 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 56 × 6 #> geo_value time_value .pred .pred_distn forecast_date target_date #> * #> 1 ak 2021-12-31 36.4 [0.05, 0.95] 2021-12-31 2022-01-07 #> 2 al 2021-12-31 89.9 [0.05, 0.95] 2021-12-31 2022-01-07 #> 3 ar 2021-12-31 82.6 [0.05, 0.95] 2021-12-31 2022-01-07 #> 4 as 2021-12-31 0 [0.05, 0.95] 2021-12-31 2022-01-07 #> 5 az 2021-12-31 58.3 [0.05, 0.95] 2021-12-31 2022-01-07 #> 6 ca 2021-12-31 84.4 [0.05, 0.95] 2021-12-31 2022-01-07 #> 7 co 2021-12-31 106. [0.05, 0.95] 2021-12-31 2022-01-07 #> 8 ct 2021-12-31 143. [0.05, 0.95] 2021-12-31 2022-01-07 #> 9 dc 2021-12-31 295. [0.05, 0.95] 2021-12-31 2022-01-07 #> 10 de 2021-12-31 150. [0.05, 0.95] 2021-12-31 2022-01-07 #> # ℹ 46 more rows"},{"path":"https://cmu-delphi.github.io/epipredict/articles/preprocessing-and-models.html","id":"introduction","dir":"Articles","previous_headings":"","what":"Introduction","title":"Examples of Preprocessing and Models","text":"epipredict package utilizes tidymodels framework, namely {recipes} dplyr-like pipeable sequences feature engineering {parsnip} unified interface range models. epipredict additional customized feature engineering preprocessing steps, step_epi_lag(), step_population_scaling(), step_epi_naomit(). can used along steps recipes package feature engineering. vignette, illustrate examples use epipredict recipes parsnip different purposes epidemiological forecasting. focus basic autoregressive models, COVID cases deaths near future predicted using linear combination cases deaths near past. remaining vignette split three sections. first section, use Poisson regression predict death counts. second section, use linear regression predict death rates. Last least, create classification model hotspot predictions.","code":"library(tidyr) library(dplyr) library(epidatr) library(epipredict) library(recipes) library(workflows) library(poissonreg)"},{"path":"https://cmu-delphi.github.io/epipredict/articles/preprocessing-and-models.html","id":"poisson-regression","dir":"Articles","previous_headings":"","what":"Poisson Regression","title":"Examples of Preprocessing and Models","text":"COVID-19, US Center Disease Control Prevention (CDC) collected models forecasts characterize state outbreak course. use inform public health decision makers potential consequences deploying control measures. One outcomes CDC forecasts death counts COVID-19. Although many state---art models, choose use Poisson regression, textbook example modeling count data, illustration using epipredict package existing tidymodels packages. counts_subset dataset comes epidatr package, contains number confirmed cases deaths June 4, 2021 Dec 31, 2021 U.S. states. wish predict 7-day ahead death counts lagged cases deaths. Furthermore, let state dummy variable. Using differential intercept coefficients, can allow intercept shift states. \\(\\mu_{t+7} = \\mathbb{E}(y_{t+7})\\), \\(y_{t+7}\\) assumed follow Poisson distribution mean \\(\\mu_{t+7}\\); \\(s_{\\text{state}}\\) dummy variables state take values either 0 1. Preprocessing steps performed prepare data model fitting. diving , helpful understand roles recipes framework.","code":"x <- pub_covidcast( source = \"jhu-csse\", signals = \"confirmed_incidence_num\", time_type = \"day\", geo_type = \"state\", time_values = epirange(20210604, 20211231), geo_values = \"ca,fl,tx,ny,nj\" ) %>% select(geo_value, time_value, cases = value) y <- pub_covidcast( source = \"jhu-csse\", signals = \"deaths_incidence_num\", time_type = \"day\", geo_type = \"state\", time_values = epirange(20210604, 20211231), geo_values = \"ca,fl,tx,ny,nj\" ) %>% select(geo_value, time_value, deaths = value) counts_subset <- full_join(x, y, by = c(\"geo_value\", \"time_value\")) %>% as_epi_df()"},{"path":"https://cmu-delphi.github.io/epipredict/articles/preprocessing-and-models.html","id":"aside-on-recipes","dir":"Articles","previous_headings":"Poisson Regression","what":"Aside on recipes","title":"Examples of Preprocessing and Models","text":"recipes can assign one roles column data. roles restricted predefined set; can anything. conventional situations, typically “predictor” /“outcome”. Additional roles enable targeted step_*() operations specific variables groups variables. case, role predictor given explanatory variables right-hand side model (equation ). role outcome response variable wish predict. geo_value time_value predefined roles unique epipredict package. Since work epi_df objects, datasets geo_value time_value passed automatically two roles assigned appropriate columns data. recipes package also allows manual alterations roles bulk. handy functions can used together help us manipulate variable roles easily. update_role() alters existing role recipe assigns initial role variables yet declared role. add_role() adds additional role variables already role recipe, without overwriting old roles. remove_role() eliminates single existing role recipe.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/articles/preprocessing-and-models.html","id":"end-aside","dir":"Articles","previous_headings":"Poisson Regression","what":"End aside","title":"Examples of Preprocessing and Models","text":"Notice following preprocessing steps, used add_role() geo_value_factor since, currently, default role raw, like reuse variable predictors. specifying preprocessing steps, use parsnip package modeling producing prediction death count, 7 days latest available date dataset. Note time_value corresponds last available date training set, target date forecast (2022-01-07). Let’s take look fit: now, ’ve used Poisson regression model count data. Poisson regression can also used model rate data, case rates death rates, incorporating offset terms model. \\(\\log(\\text{population})\\) log state population used scale count data left-hand side equation. offset simply predictor coefficient fixed 1 rather estimated. several ways model rate data given count population data. First, parsnip framework, specify formula fit(). However, lose ability use recipes framework create new variables since variables exist original dataset (, , lags leads) called directly fit(). Alternatively, step_population_scaling() layer_population_scaling() epipredict package can perform population scaling provide population data, illustrate next section.","code":"counts_subset <- counts_subset %>% mutate(geo_value_factor = as.factor(geo_value)) %>% as_epi_df() epi_recipe(counts_subset) #> #> ── Recipe ────────────────────────────────────────────────────────────────────── #> #> ── Inputs #> Number of variables by role #> raw: 3 #> geo_value: 1 #> time_value: 1 r <- epi_recipe(counts_subset) %>% add_role(geo_value_factor, new_role = \"predictor\") %>% step_dummy(geo_value_factor) %>% ## Occasionally, data reporting errors / corrections result in negative ## cases / deaths step_mutate(cases = pmax(cases, 0), deaths = pmax(deaths, 0)) %>% step_epi_lag(cases, deaths, lag = c(0, 7)) %>% step_epi_ahead(deaths, ahead = 7, role = \"outcome\") %>% step_epi_naomit() latest <- get_test_data(r, counts_subset) wf <- epi_workflow(r, parsnip::poisson_reg()) %>% fit(counts_subset) predict(wf, latest) %>% filter(!is.na(.pred)) #> An `epi_df` object, 5 x 3 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2023-09-14 20:55:43.763975 #> #> # A tibble: 5 × 3 #> geo_value time_value .pred #> * #> 1 ca 2021-12-31 108. #> 2 fl 2021-12-31 270. #> 3 nj 2021-12-31 22.5 #> 4 ny 2021-12-31 94.8 #> 5 tx 2021-12-31 91.0 extract_fit_engine(wf) #> #> Call: stats::glm(formula = ..y ~ ., family = stats::poisson, data = data) #> #> Coefficients: #> (Intercept) geo_value_factor_fl geo_value_factor_nj #> 3.970e+00 -1.487e-01 -1.425e+00 #> geo_value_factor_ny geo_value_factor_tx lag_0_cases #> -6.865e-01 3.025e-01 1.339e-05 #> lag_7_cases lag_0_deaths lag_7_deaths #> 1.717e-06 1.731e-03 8.566e-04 #> #> Degrees of Freedom: 984 Total (i.e. Null); 976 Residual #> Null Deviance: 139600 #> Residual Deviance: 58110 AIC: 62710"},{"path":"https://cmu-delphi.github.io/epipredict/articles/preprocessing-and-models.html","id":"linear-regression","dir":"Articles","previous_headings":"","what":"Linear Regression","title":"Examples of Preprocessing and Models","text":"COVID-19, CDC required submission case death count predictions. However, Delphi Group preferred train rate data instead, puts different locations similar scale (eliminating need location-specific intercepts). can use liner regression predict death rates use state population data scale rates counts.1 using layer_population_scaling() epipredict package. Additionally, forecasts submitted, prediction intervals provided along point estimates. can obtained via postprocessing using layer_residual_quantiles(). worth pointing , however, layer_residual_quantiles() used population scaling else transformation make results uninterpretable. wish, now, predict 7-day ahead death counts lagged case rates death rates, along extra behaviourial predictors. Namely, use survey data COVID-19 Trends Impact Survey. survey data provides estimated percentage people wore mask time public past 7 days estimated percentage respondents reported people encountered public past 7 days maintained distance least 6 feet. State-wise population data 2019 U.S. Census included package used layer_population_scaling(). Rather using raw mask-wearing / social-distancing metrics, sake illustration, ’ll convert categorical predictors. take subset death rate case rate data built-dataset case_death_rate_subset. Preprocessing steps rely functions epipredict package well recipes package. also many functions recipes package allow scalar transformations, log transformations data centering. case, center numerical predictors allow meaningful interpretation intercept. sanity check can examine structure training data: directly predicting results, need add postprocessing layers obtain death counts instead death rates. Note rates used far “per 100K people” rather “per person”. ’ll also use quantile regression quantile_reg engine rather ordinary least squares create median predictions 90% prediction interval. columns marked *_scaled rescaled correct units, case deaths rather deaths per 100K people (remain .pred). look prediction intervals: Last least, let’s take look regression fit check coefficients:","code":"behav_ind_mask <- pub_covidcast( source = \"fb-survey\", signals = \"smoothed_wwearing_mask_7d\", time_type = \"day\", geo_type = \"state\", time_values = epirange(20210604, 20211231), geo_values = \"ca,fl,tx,ny,nj\" ) %>% select(geo_value, time_value, masking = value) behav_ind_distancing <- pub_covidcast( source = \"fb-survey\", signals = \"smoothed_wothers_distanced_public\", time_type = \"day\", geo_type = \"state\", time_values = epirange(20210604, 20211231), geo_values = \"ca,fl,tx,ny,nj\" ) %>% select(geo_value, time_value, distancing = value) pop_dat <- state_census %>% select(abbr, pop) behav_ind <- behav_ind_mask %>% full_join(behav_ind_distancing, by = c(\"geo_value\", \"time_value\")) jhu <- filter( case_death_rate_subset, time_value >= \"2021-06-04\", time_value <= \"2021-12-31\", geo_value %in% c(\"ca\", \"fl\", \"tx\", \"ny\", \"nj\") ) jhu <- jhu %>% mutate(geo_value_factor = as.factor(geo_value)) %>% left_join(behav_ind, by = c(\"geo_value\", \"time_value\")) %>% as_epi_df() r <- epi_recipe(jhu) %>% add_role(geo_value_factor, new_role = \"predictor\") %>% step_dummy(geo_value_factor) %>% step_epi_lag(case_rate, death_rate, lag = c(0, 7, 14)) %>% step_mutate( masking = cut_number(masking, 5), distancing = cut_number(distancing, 5) ) %>% step_epi_ahead(death_rate, ahead = 7, role = \"outcome\") %>% step_center(contains(\"lag\"), role = \"predictor\") %>% step_epi_naomit() glimpse(slice_sample(bake(prep(r, jhu), jhu), n = 6)) #> Rows: 6 #> Columns: 17 #> $ time_value 2021-08-02, 2021-08-27, 2021-10-07, 2021-11-24, 2… #> $ geo_value \"tx\", \"nj\", \"nj\", \"tx\", \"ca\", \"ny\" #> $ case_rate 32.01795, 22.27205, 19.09561, 11.24046, 18.86626, … #> $ death_rate 0.1420750, 0.1399240, 0.1994320, 0.2758784, 0.2696… #> $ masking \"[42.7,52.8]\", \"(60.2,63.9]\", \"(60.2,63.9]\", \"(52.… #> $ distancing \"(18.4,19.8]\", \"(21.1,27]\", \"(18.4,19.8]\", \"[13.9,… #> $ geo_value_factor_fl 0, 0, 0, 0, 0, 0 #> $ geo_value_factor_nj 0, 1, 1, 0, 0, 0 #> $ geo_value_factor_ny 0, 0, 0, 0, 0, 1 #> $ geo_value_factor_tx 1, 0, 0, 1, 0, 0 #> $ lag_0_case_rate 5.076291, -4.669617, -7.846053, -15.701198, -8.075… #> $ lag_7_case_rate -9.264035, -5.065264, -6.112282, -16.196514, -5.30… #> $ lag_14_case_rate -15.8578696, -9.9223972, -2.3391581, -16.2364118, … #> $ lag_0_death_rate -0.139798604, -0.141949604, -0.082441604, -0.00599… #> $ lag_7_death_rate -0.1855351035, -0.1885909035, -0.0583168035, 0.159… #> $ lag_14_death_rate -0.195266304, -0.209499104, -0.056708504, 0.006655… #> $ ahead_7_death_rate 0.1936501, 0.1656572, 0.1962153, 0.1571583, 0.2405… f <- frosting() %>% layer_predict() %>% layer_add_target_date(\"2022-01-07\") %>% layer_threshold(.pred, lower = 0) %>% layer_quantile_distn() %>% layer_naomit(.pred) %>% layer_population_scaling( .pred, .pred_distn, df = pop_dat, rate_rescaling = 1e5, by = c(\"geo_value\" = \"abbr\"), df_pop_col = \"pop\" ) wf <- epi_workflow(r, quantile_reg(tau = c(.05, .5, .95))) %>% fit(jhu) %>% add_frosting(f) latest <- get_test_data(recipe = r, x = jhu) p <- predict(wf, latest) p #> An `epi_df` object, 5 x 7 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 5 × 7 #> geo_value time_value .pred target_date .pred_distn #> * #> 1 ca 2021-12-31 [0.05, 0.95] 2022-01-07 [0.25, 0.75] #> 2 fl 2021-12-31 [0.05, 0.95] 2022-01-07 [0.25, 0.75] #> 3 nj 2021-12-31 [0.05, 0.95] 2022-01-07 [0.25, 0.75] #> 4 ny 2021-12-31 [0.05, 0.95] 2022-01-07 [0.25, 0.75] #> 5 tx 2021-12-31 [0.05, 0.95] 2022-01-07 [0.25, 0.75] #> # ℹ 2 more variables: .pred_scaled , .pred_distn_scaled p %>% select(geo_value, target_date, .pred_scaled, .pred_distn_scaled) %>% mutate(.pred_distn_scaled = nested_quantiles(.pred_distn_scaled)) %>% unnest(.pred_distn_scaled) %>% pivot_wider(names_from = tau, values_from = q) #> # A tibble: 5 × 5 #> geo_value target_date .pred_scaled `0.25` `0.75` #> #> 1 ca 2022-01-07 [0.05, 0.95] 48.8 94.0 #> 2 fl 2022-01-07 [0.05, 0.95] 48.4 104. #> 3 nj 2022-01-07 [0.05, 0.95] 45.5 68.7 #> 4 ny 2022-01-07 [0.05, 0.95] 108. 163. #> 5 tx 2022-01-07 [0.05, 0.95] 68.6 107. #> Call: #> quantreg::rq(formula = ..y ~ ., tau = ~c(0.05, 0.5, 0.95), data = data, #> na.action = stats::na.omit, method = \"br\", model = FALSE) #> #> Coefficients: #> tau= 0.05 tau= 0.50 tau= 0.95 #> (Intercept) 0.210811625 0.2962574475 0.417583265 #> geo_value_factor_fl 0.032085820 0.0482361119 0.171126713 #> geo_value_factor_nj 0.007313762 -0.0033797953 -0.025251865 #> geo_value_factor_ny -0.001489163 -0.0199485947 -0.032635584 #> geo_value_factor_tx 0.029077485 0.0391980273 0.071961515 #> lag_0_case_rate -0.001636588 -0.0011625693 -0.001430622 #> lag_7_case_rate 0.004700752 0.0057822095 0.006912655 #> lag_14_case_rate 0.001715816 0.0004224753 0.003448733 #> lag_0_death_rate 0.462341754 0.5274192012 0.164856372 #> lag_7_death_rate -0.007368501 0.1132903956 0.172687438 #> lag_14_death_rate -0.072500707 -0.0270474349 0.181279299 #> #> Degrees of freedom: 950 total; 939 residual"},{"path":"https://cmu-delphi.github.io/epipredict/articles/preprocessing-and-models.html","id":"classification","dir":"Articles","previous_headings":"","what":"Classification","title":"Examples of Preprocessing and Models","text":"Sometimes preferable create predictive model surges upswings rather raw values. case, target predict future increased case rates (denoted ), decreased case rates (), flat case rates (flat) relative current level. models may referred “hotspot prediction models”. follow analysis McDonald, Bien, Green, Hu, et al. extend application predict three categories instead two. Hotspot prediction uses categorical outcome variable defined terms relative change \\(Y_{\\ell, t+}\\) compared \\(Y_{\\ell, t}\\). \\(Y_{\\ell, t}\\) denotes case rates location \\(\\ell\\) time \\(t\\). define response variables follows: \\[ Z_{\\ell, t}= \\begin{cases} \\text{}, & \\text{}\\ Y^{\\Delta}_{\\ell, t} > 0.25 \\\\ \\text{}, & \\text{}\\ Y^{\\Delta}_{\\ell, t} < -0.20\\\\ \\text{flat}, & \\text{otherwise} \\end{cases} \\] \\(Y^{\\Delta}_{\\ell, t} = (Y_{\\ell, t}- Y_{\\ell, t-7})\\ /\\ (Y_{\\ell, t-7})\\). say location \\(\\ell\\) hotspot time \\(t\\) \\(Z_{\\ell,t}\\) , meaning number newly reported cases past 7 days increased least 25% compared preceding week. \\(Z_{\\ell,t}\\) categorized , suggests least 20% decrease newly reported cases past 7 days (20% decrease inverse 25% increase). Otherwise, consider trend flat. expression multinomial regression use follows: \\[ \\pi_{j}(x) = \\text{Pr}(Z_{\\ell,t} = j|x) = \\frac{e^{g_j(x)}}{1 + \\sum_{k=0}^2 g_j(x) } \\] \\(j\\) either , flat, Preprocessing steps similar previous models additional step categorizing response variables. , use subset death rate case rate data built-dataset case_death_rate_subset. fit multinomial regression examine predictions: can also look estimated coefficients model summary information: One also use formula epi_recipe() achieve results . However, one add_formula(), add_recipe(), workflow_variables() can specified. purpose demonstrating add_formula rather add_recipe, prep bake recipe return data.frame used model fitting.","code":"jhu <- case_death_rate_subset %>% dplyr::filter( time_value >= \"2021-06-04\", time_value <= \"2021-12-31\", geo_value %in% c(\"ca\", \"fl\", \"tx\", \"ny\", \"nj\") ) %>% mutate(geo_value_factor = as.factor(geo_value)) %>% as_epi_df() r <- epi_recipe(jhu) %>% add_role(time_value, new_role = \"predictor\") %>% step_dummy(geo_value_factor) %>% step_epi_lag(case_rate, lag = c(0, 7, 14)) %>% step_epi_ahead(case_rate, ahead = 7, role = \"predictor\") %>% step_mutate( pct_diff_ahead = case_when( lag_7_case_rate == 0 ~ 0, TRUE ~ (ahead_7_case_rate - lag_0_case_rate) / lag_0_case_rate ), pct_diff_wk1 = case_when( lag_7_case_rate == 0 ~ 0, TRUE ~ (lag_0_case_rate - lag_7_case_rate) / lag_7_case_rate ), pct_diff_wk2 = case_when( lag_14_case_rate == 0 ~ 0, TRUE ~ (lag_7_case_rate - lag_14_case_rate) / lag_14_case_rate ) ) %>% step_mutate( response = case_when( pct_diff_ahead < -0.20 ~ \"down\", pct_diff_ahead > 0.25 ~ \"up\", TRUE ~ \"flat\" ), role = \"outcome\" ) %>% step_rm( death_rate, case_rate, lag_0_case_rate, lag_7_case_rate, lag_14_case_rate, ahead_7_case_rate, pct_diff_ahead ) %>% step_epi_naomit() wf <- epi_workflow(r, parsnip::multinom_reg()) %>% fit(jhu) latest <- get_test_data(recipe = r, x = jhu) predict(wf, latest) %>% filter(!is.na(.pred_class)) #> An `epi_df` object, 5 x 3 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 5 × 3 #> geo_value time_value .pred_class #> * #> 1 ca 2021-12-31 up #> 2 fl 2021-12-31 up #> 3 nj 2021-12-31 up #> 4 ny 2021-12-31 up #> 5 tx 2021-12-31 flat extract_fit_engine(wf) #> Call: #> nnet::multinom(formula = ..y ~ ., data = data, trace = FALSE) #> #> Coefficients: #> (Intercept) time_value geo_value_factor_fl geo_value_factor_nj #> flat -58.11177 0.003162471 -0.5978151 1.350320 #> up 46.45080 -0.002429847 -0.4682080 1.572085 #> geo_value_factor_ny geo_value_factor_tx pct_diff_wk1 pct_diff_wk2 #> flat 3.113677 -0.3010305 1.263089 3.610543 #> up 3.172692 -0.2505232 2.194646 4.266267 #> #> Residual Deviance: 1529.929 #> AIC: 1561.929 b <- bake(prep(r, jhu), jhu) epi_workflow() %>% add_formula(response ~ geo_value + time_value + pct_diff_wk1 + pct_diff_wk2) %>% add_model(parsnip::multinom_reg()) %>% fit(data = b) #> ══ Workflow [trained] ══════════════════════════════════════════════════════════ #> Preprocessor: Formula #> Model: multinom_reg() #> #> ── Preprocessor ──────────────────────────────────────────────────────────────── #> response ~ geo_value + time_value + pct_diff_wk1 + pct_diff_wk2 #> #> ── Model ─────────────────────────────────────────────────────────────────────── #> Call: #> nnet::multinom(formula = ..y ~ ., data = data, trace = FALSE) #> #> Coefficients: #> (Intercept) geo_valuefl geo_valuenj geo_valueny geo_valuetx time_value #> flat -58.11158 -0.5978159 1.350325 3.113684 -0.3010308 0.003162461 #> up 46.45071 -0.4682087 1.572090 3.172698 -0.2505236 -0.002429839 #> pct_diff_wk1 pct_diff_wk2 #> flat 1.263093 3.610536 #> up 2.194649 4.266259 #> #> Residual Deviance: 1529.929 #> AIC: 1561.929"},{"path":"https://cmu-delphi.github.io/epipredict/articles/preprocessing-and-models.html","id":"benefits-of-lagging-and-leading-in-epipredict","dir":"Articles","previous_headings":"","what":"Benefits of Lagging and Leading in epipredict","title":"Examples of Preprocessing and Models","text":"step_epi_ahead step_epi_lag functions epipredict package handy creating correct lags leads future predictions. Let’s start simple dataset preprocessing: want predict death rates 2022-01-07, 7 days ahead latest available date dataset. compare two methods trying create lags leads: Notice difference number rows b1 b2 returns. second version, one doesn’t use step_epi_ahead step_epi_lag, omitted dates compared one used epipredict functions. model trained based recipes functions predict 7 days ahead 2021-12-24 instead 7 days ahead 2021-12-31.","code":"ex <- filter( case_death_rate_subset, time_value >= \"2021-12-01\", time_value <= \"2021-12-31\", geo_value == \"ca\" ) dim(ex) #> [1] 31 4 p1 <- epi_recipe(ex) %>% step_epi_lag(case_rate, lag = c(0, 7, 14)) %>% step_epi_lag(death_rate, lag = c(0, 7, 14)) %>% step_epi_ahead(death_rate, ahead = 7, role = \"outcome\") %>% step_epi_naomit() %>% prep() #> Warning in max.default(structure(numeric(0), class = \"Date\"), na.rm = FALSE): #> no non-missing arguments to max; returning -Inf b1 <- bake(p1, ex) b1 #> # A tibble: 17 × 11 #> time_value geo_value case_rate death_rate lag_0_case_rate lag_7_case_rate #> #> 1 2021-12-15 ca 15.8 0.157 15.8 18.0 #> 2 2021-12-16 ca 16.3 0.155 16.3 17.4 #> 3 2021-12-17 ca 16.9 0.158 16.9 17.4 #> 4 2021-12-18 ca 17.6 0.164 17.6 17.2 #> 5 2021-12-19 ca 19.1 0.165 19.1 16.3 #> 6 2021-12-20 ca 20.6 0.164 20.6 16.0 #> 7 2021-12-21 ca 22.6 0.165 22.6 16.6 #> 8 2021-12-22 ca 26.2 0.163 26.2 15.8 #> 9 2021-12-23 ca 30.8 0.167 30.8 16.3 #> 10 2021-12-24 ca 33.8 0.167 33.8 16.9 #> 11 2021-12-25 ca 32.6 0.153 32.6 17.6 #> 12 2021-12-26 ca 34.5 0.153 34.5 19.1 #> 13 2021-12-27 ca 48.4 0.132 48.4 20.6 #> 14 2021-12-28 ca 54.9 0.142 54.9 22.6 #> 15 2021-12-29 ca 63.7 0.140 63.7 26.2 #> 16 2021-12-30 ca 76.0 0.140 76.0 30.8 #> 17 2021-12-31 ca 84.4 0.142 84.4 33.8 #> # ℹ 5 more variables: lag_14_case_rate , lag_0_death_rate , #> # lag_7_death_rate , lag_14_death_rate , ahead_7_death_rate p2 <- epi_recipe(ex) %>% step_mutate( lag0case_rate = lag(case_rate, 0), lag7case_rate = lag(case_rate, 7), lag14case_rate = lag(case_rate, 14), lag0death_rate = lag(death_rate, 0), lag7death_rate = lag(death_rate, 7), lag14death_rate = lag(death_rate, 14), ahead7death_rate = lead(death_rate, 7) ) %>% step_epi_naomit() %>% prep() #> Warning in max.default(structure(numeric(0), class = \"Date\"), na.rm = FALSE): #> no non-missing arguments to max; returning -Inf b2 <- bake(p2, ex) b2 #> # A tibble: 10 × 11 #> time_value geo_value case_rate death_rate lag0case_rate lag7case_rate #> #> 1 2021-12-15 ca 15.8 0.157 15.8 18.0 #> 2 2021-12-16 ca 16.3 0.155 16.3 17.4 #> 3 2021-12-17 ca 16.9 0.158 16.9 17.4 #> 4 2021-12-18 ca 17.6 0.164 17.6 17.2 #> 5 2021-12-19 ca 19.1 0.165 19.1 16.3 #> 6 2021-12-20 ca 20.6 0.164 20.6 16.0 #> 7 2021-12-21 ca 22.6 0.165 22.6 16.6 #> 8 2021-12-22 ca 26.2 0.163 26.2 15.8 #> 9 2021-12-23 ca 30.8 0.167 30.8 16.3 #> 10 2021-12-24 ca 33.8 0.167 33.8 16.9 #> # ℹ 5 more variables: lag14case_rate , lag0death_rate , #> # lag7death_rate , lag14death_rate , ahead7death_rate dates_used_in_training1 <- b1 %>% select(-ahead_7_death_rate) %>% na.omit() %>% pull(time_value) dates_used_in_training1 #> [1] \"2021-12-15\" \"2021-12-16\" \"2021-12-17\" \"2021-12-18\" \"2021-12-19\" #> [6] \"2021-12-20\" \"2021-12-21\" \"2021-12-22\" \"2021-12-23\" \"2021-12-24\" #> [11] \"2021-12-25\" \"2021-12-26\" \"2021-12-27\" \"2021-12-28\" \"2021-12-29\" #> [16] \"2021-12-30\" \"2021-12-31\" dates_used_in_training2 <- b2 %>% select(-ahead7death_rate) %>% na.omit() %>% pull(time_value) dates_used_in_training2 #> [1] \"2021-12-15\" \"2021-12-16\" \"2021-12-17\" \"2021-12-18\" \"2021-12-19\" #> [6] \"2021-12-20\" \"2021-12-21\" \"2021-12-22\" \"2021-12-23\" \"2021-12-24\""},{"path":"https://cmu-delphi.github.io/epipredict/articles/preprocessing-and-models.html","id":"references","dir":"Articles","previous_headings":"","what":"References","title":"Examples of Preprocessing and Models","text":"McDonald, Bien, Green, Hu, et al. “Can auxiliary indicators improve COVID-19 forecasting hotspot prediction?.” Proceedings National Academy Sciences 118.51 (2021): e2111453118. doi:10.1073/pnas.2111453118","code":""},{"path":"https://cmu-delphi.github.io/epipredict/articles/preprocessing-and-models.html","id":"attribution","dir":"Articles","previous_headings":"","what":"Attribution","title":"Examples of Preprocessing and Models","text":"object contains modified part COVID-19 Data Repository Center Systems Science Engineering (CSSE) Johns Hopkins University republished COVIDcast Epidata API. data set licensed terms Creative Commons Attribution 4.0 International license Johns Hopkins University behalf Center Systems Science Engineering. Copyright Johns Hopkins University 2020.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/articles/sliding.html","id":"demonstrations-of-sliding-ar-and-arx-forecasters","dir":"Articles","previous_headings":"","what":"Demonstrations of sliding AR and ARX forecasters","title":"Demonstrations of sliding AR and ARX forecasters","text":"key function epiprocess package epi_slide(), allows user apply function formula-based computation variables epi_df running window n time steps (see following epiprocess vignette go basics function: “Slide computation signal values”). equivalent sliding method epi_archive object can called using wrapper function epix_slide() (refer following vignette basics function: “Work archive objects data revisions”). key difference epi_slide() performs version-aware computations. , function uses data available time t reference time. vignette, use epi_slide() epix_slide() backtesting arx_forecaster historical COVID-19 case data US Canada. precisely, first demonstrate using epi_slide() slide ARX forecasters epi_df object compare results obtained using different forecasting engines. compare results version-aware unaware forecasting, former obtained applying epix_slide() epi_archive object, latter obtained applying epi_slide() latest snapshot data.","code":""},{"path":[]},{"path":"https://cmu-delphi.github.io/epipredict/articles/sliding.html","id":"example-using-cli-and-case-data-from-us-states","dir":"Articles","previous_headings":"Demonstrations of sliding AR and ARX forecasters > Comparing different forecasting engines","what":"Example using CLI and case data from US states","title":"Demonstrations of sliding AR and ARX forecasters","text":"First, download version history (ie. archive) percentage doctor’s visits CLI (COVID-like illness) computed medical insurance claims number new confirmed COVID-19 cases per 100,000 population (daily) 50 states COVIDcast API. process , modification use sync = locf epix_merge() last version observation can carried forward extrapolate unavailable versions less --date input archive. obtaining latest snapshot data, produce forecasts data using default engine simple linear regression compare random forest. Note warnings forecast date less recent update date data suppressed avoid cluttering output. , arx_forecaster() heavy lifting. creates leads target (respecting time stamps locations) along lags features (, response doctors visits), estimates forecasting model using specified engine, creates predictions, non-parametric confidence bands. see predictions compare, plot top latest case rates. Note even though ’ve fitted model states, ’ll just display results two states, California (CA) Florida (FL), get sense model performance keeping graphic simple. two states interest, simple linear regression clearly performs better random forest terms accuracy predictions result overconfident predictions (overly narrow confidence bands). Though, general, neither approach produces amazingly accurate forecasts. behaviour rather different across states effects notable factors age public health measures may important account forecasting. Including factors well making enhancements correcting outliers improvements one make simple model.1","code":"theme_set(theme_bw()) y <- readRDS(system.file( \"extdata\", \"all_states_covidcast_signals.rds\", package = \"epipredict\", mustWork = TRUE )) y <- purrr::map(y, ~ select(.x, geo_value, time_value, version = issue, value)) x <- epix_merge( y[[1]] %>% rename(percent_cli = value) %>% as_epi_archive(compactify = FALSE), y[[2]] %>% rename(case_rate = value) %>% as_epi_archive(compactify = FALSE), sync = \"locf\", compactify = TRUE ) rm(y) # Latest snapshot of data, and forecast dates x_latest <- epix_as_of(x, max_version = max(x$versions_end)) fc_time_values <- seq( from = as.Date(\"2020-08-01\"), to = as.Date(\"2021-11-01\"), by = \"1 month\" ) aheads <- c(7, 14, 21, 28) k_week_ahead <- function(epi_df, outcome, predictors, ahead = 7, engine) { epi_slide( epi_df, ~ arx_forecaster( .x, outcome, predictors, engine, args_list = arx_args_list(ahead = ahead) ) %>% extract2(\"predictions\") %>% select(-geo_value), before = 120 - 1, ref_time_values = fc_time_values, new_col_name = \"fc\" ) %>% select(geo_value, time_value, starts_with(\"fc\")) %>% mutate(engine_type = engine$engine) } # Generate the forecasts and bind them together fc <- bind_rows( map( aheads, ~ k_week_ahead( x_latest, \"case_rate\", c(\"case_rate\", \"percent_cli\"), .x, engine = linear_reg() ) ) %>% list_rbind(), map( aheads, ~ k_week_ahead( x_latest, \"case_rate\", c(\"case_rate\", \"percent_cli\"), .x, engine = rand_forest(mode = \"regression\") ) ) %>% list_rbind() ) %>% pivot_quantiles(fc_.pred_distn) fc_cafl <- fc %>% filter(geo_value %in% c(\"ca\", \"fl\")) x_latest_cafl <- x_latest %>% filter(geo_value %in% c(\"ca\", \"fl\")) ggplot(fc_cafl, aes(fc_target_date, group = time_value, fill = engine_type)) + geom_line( data = x_latest_cafl, aes(x = time_value, y = case_rate), inherit.aes = FALSE, color = \"gray50\" ) + geom_ribbon(aes(ymin = `0.05`, ymax = `0.95`), alpha = 0.4) + geom_line(aes(y = fc_.pred)) + geom_point(aes(y = fc_.pred), size = 0.5) + geom_vline(aes(xintercept = time_value), linetype = 2, alpha = 0.5) + facet_grid(vars(geo_value), vars(engine_type), scales = \"free\") + scale_x_date(minor_breaks = \"month\", date_labels = \"%b %y\") + scale_fill_brewer(palette = \"Set1\") + labs(x = \"Date\", y = \"Reported COVID-19 case rates\") + theme(legend.position = \"none\")"},{"path":"https://cmu-delphi.github.io/epipredict/articles/sliding.html","id":"example-using-case-data-from-canada","dir":"Articles","previous_headings":"Demonstrations of sliding AR and ARX forecasters > Comparing different forecasting engines","what":"Example using case data from Canada","title":"Demonstrations of sliding AR and ARX forecasters","text":"leveraging flexibility epiprocess, can apply techniques data sources. Since collaborators British Columbia, Canada, ’ll essentially thing Canada . COVID-19 Canada Open Data Working Group collects daily time series data COVID-19 cases, deaths, recoveries, testing vaccinations health region province levels. Data collected publicly available sources government datasets news releases. Unfortunately, simple versioned source, created Github commit history. First, load versioned case rates provincial level. converting 7-day averages (due highly variable provincial reporting mismatches), convert data epi_archive object, extract latest version . Finally, run forcasting exercise American data, compare forecasts produced using simple linear regression using boosted regression trees. figures shows results provinces. approaches tend produce quite volatile forecasts (point predictions) /overly confident (narrow bands), particularly boosted regression trees used. meant simple demonstration sliding different engines arx_forecaster, may devote another vignette work improving predictive modelling using suite tools available epipredict.","code":"# source(\"drafts/canada-case-rates.R) can <- readRDS(system.file( \"extdata\", \"can_prov_cases.rds\", package = \"epipredict\", mustWork = TRUE )) can <- can %>% group_by(version, geo_value) %>% arrange(time_value) %>% mutate(cr_7dav = RcppRoll::roll_meanr(case_rate, n = 7L)) %>% as_epi_archive(compactify = TRUE) can_latest <- epix_as_of(can, max_version = max(can$DT$version)) # Generate the forecasts, and bind them together can_fc <- bind_rows( map( aheads, ~ k_week_ahead(can_latest, \"cr_7dav\", \"cr_7dav\", .x, linear_reg()) ) %>% list_rbind(), map( aheads, ~ k_week_ahead( can_latest, \"cr_7dav\", \"cr_7dav\", .x, boost_tree(mode = \"regression\", trees = 20) ) ) %>% list_rbind() ) %>% pivot_quantiles(fc_.pred_distn) ggplot( can_fc %>% filter(engine_type == \"lm\"), aes(x = fc_target_date, group = time_value) ) + coord_cartesian(xlim = lubridate::ymd(c(\"2020-12-01\", NA))) + geom_line( data = can_latest, aes(x = time_value, y = cr_7dav), inherit.aes = FALSE, color = \"gray50\" ) + geom_ribbon(aes(ymin = `0.05`, ymax = `0.95`, fill = geo_value), alpha = 0.4 ) + geom_line(aes(y = fc_.pred)) + geom_point(aes(y = fc_.pred), size = 0.5) + geom_vline(aes(xintercept = time_value), linetype = 2, alpha = 0.5) + facet_wrap(~geo_value, scales = \"free_y\", ncol = 3) + scale_x_date(minor_breaks = \"month\", date_labels = \"%b %y\") + labs( title = \"Using simple linear regression\", x = \"Date\", y = \"Reported COVID-19 case rates\" ) + theme(legend.position = \"none\") ggplot( can_fc %>% filter(engine_type == \"xgboost\"), aes(x = fc_target_date, group = time_value) ) + coord_cartesian(xlim = lubridate::ymd(c(\"2020-12-01\", NA))) + geom_line( data = can_latest, aes(x = time_value, y = cr_7dav), inherit.aes = FALSE, color = \"gray50\" ) + geom_ribbon(aes(ymin = `0.05`, ymax = `0.95`, fill = geo_value), alpha = 0.4 ) + geom_line(aes(y = fc_.pred)) + geom_point(aes(y = fc_.pred), size = 0.5) + geom_vline(aes(xintercept = time_value), linetype = 2, alpha = 0.5) + facet_wrap(~geo_value, scales = \"free_y\", ncol = 3) + scale_x_date(minor_breaks = \"month\", date_labels = \"%b %y\") + labs( title = \"Using boosted regression trees\", x = \"Date\", y = \"Reported COVID-19 case rates\" ) + theme(legend.position = \"none\")"},{"path":[]},{"path":"https://cmu-delphi.github.io/epipredict/articles/sliding.html","id":"example-using-case-data-from-us-states","dir":"Articles","previous_headings":"Demonstrations of sliding AR and ARX forecasters > Version-aware and unaware forecasting","what":"Example using case data from US states","title":"Demonstrations of sliding AR and ARX forecasters","text":"now employ forecaster uses properly-versioned data (available real-time) forecast future COVID-19 case rates current past COVID-19 case rates states. , can make forecasts archive, x, compare forecasts latest data, x_latest using general set-. version-aware forecasting, note x fed epix_slide(), version-unaware forecasting, x_latest fed epi_slide(). Now can plot results top latest case rates. , display focus results FL CA simplicity. , observe results great two states, ’s likely due simplicity model (ex. omission key factors age public health measures) quality data (ex. personally corrected anomalies data). shall leave reader try version aware unaware forecasting exercise Canadian case rate data. code American state data readily adaptable purpose.","code":"k_week_version_aware <- function(ahead = 7, version_aware = TRUE) { if (version_aware) { epix_slide( x, ~ arx_forecaster( .x, \"case_rate\", c(\"case_rate\", \"percent_cli\"), args_list = arx_args_list(ahead = ahead) ) %>% extract2(\"predictions\"), before = 120 - 1, ref_time_values = fc_time_values, new_col_name = \"fc\" ) %>% mutate(engine_type = \"lm\", version_aware = version_aware) %>% rename(geo_value = fc_geo_value) } else { k_week_ahead( x_latest, \"case_rate\", c(\"case_rate\", \"percent_cli\"), ahead, linear_reg() ) %>% mutate(version_aware = version_aware) } } # Generate the forecasts, and bind them together fc <- bind_rows( map(aheads, ~ k_week_version_aware(.x, TRUE)) %>% list_rbind(), map(aheads, ~ k_week_version_aware(.x, FALSE)) %>% list_rbind() ) %>% pivot_quantiles(fc_.pred_distn) fc_cafl <- fc %>% filter(geo_value %in% c(\"ca\", \"fl\")) x_latest_cafl <- x_latest %>% filter(geo_value %in% c(\"ca\", \"fl\")) ggplot(fc_cafl, aes(x = fc_target_date, group = time_value, fill = version_aware)) + geom_line( data = x_latest_cafl, aes(x = time_value, y = case_rate), inherit.aes = FALSE, color = \"gray50\" ) + geom_ribbon(aes(ymin = `0.05`, ymax = `0.95`), alpha = 0.4) + geom_line(aes(y = fc_.pred)) + geom_point(aes(y = fc_.pred), size = 0.5) + geom_vline(aes(xintercept = time_value), linetype = 2, alpha = 0.5) + facet_grid(geo_value ~ version_aware, scales = \"free\", labeller = labeller(version_aware = label_both) ) + scale_x_date(minor_breaks = \"month\", date_labels = \"%b %y\") + labs(x = \"Date\", y = \"Reported COVID-19 case rates\") + scale_fill_brewer(palette = \"Set1\") + theme(legend.position = \"none\")"},{"path":"https://cmu-delphi.github.io/epipredict/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Daniel McDonald. Author, maintainer. Ryan Tibshirani. Author. Logan Brooks. Author. Rachel Lobay. Author. Maggie Liu. Author. Ken Mawer. Author. Chloe . Author. Jacob Bien. Contributor.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"McDonald D, Tibshirani R, Brooks L, Lobay R, Liu M, Mawer K, C (2023). epipredict: Basic epidemiology forecasting methods. https://github.com/cmu-delphi/epipredict/, https://cmu-delphi.github.io/epipredict.","code":"@Manual{, title = {epipredict: Basic epidemiology forecasting methods}, author = {Daniel McDonald and Ryan Tibshirani and Logan Brooks and Rachel Lobay and Maggie Liu and Ken Mawer and Chloe You}, year = {2023}, note = {https://github.com/cmu-delphi/epipredict/, https://cmu-delphi.github.io/epipredict}, }"},{"path":"https://cmu-delphi.github.io/epipredict/index.html","id":"epipredict","dir":"","previous_headings":"","what":"Basic epidemiology forecasting methods","title":"Basic epidemiology forecasting methods","text":"Note: package currently development may work expected. Please file bug reports issues repo, best address quickly.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"Basic epidemiology forecasting methods","text":"can install development version epipredict GitHub :","code":"# install.packages(\"remotes\") remotes::install_github(\"cmu-delphi/epipredict\")"},{"path":"https://cmu-delphi.github.io/epipredict/index.html","id":"documentation","dir":"","previous_headings":"","what":"Documentation","title":"Basic epidemiology forecasting methods","text":"can view documentation main branch https://cmu-delphi.github.io/epipredict.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/index.html","id":"goals-for-epipredict","dir":"","previous_headings":"","what":"Goals for epipredict","title":"Basic epidemiology forecasting methods","text":"hope provide: Baseline flat-line forecaster Autoregressive forecaster Autoregressive classifier Preprocessor: things data model training Trainer: train model data, resulting fitted model object Predictor: make predictions, using fitted model object Postprocessor: things predictions returning Target audiences: Basic. data, calls forecaster default arguments. Intermediate. Wants examine changes arguments, take advantage built flexibility. Advanced. Wants write forecasters. Maybe willing build components write. Advanced user find task relatively easy. Examples tasks illustrated vignettes articles.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/index.html","id":"intermediate-example","dir":"","previous_headings":"","what":"Intermediate example","title":"Basic epidemiology forecasting methods","text":"package comes built-historical data illustration, --date versions downloaded {covidcast} package processed using {epiprocess}.1 create train simple auto-regressive forecaster predict death rate two weeks future using past (lagged) deaths cases, use following function. case, used number different lags case rate, using 3 weekly lags death rate (predictors). result fitted model object used time future create different forecasts, well set predicted values (prediction intervals) location 14 days last available time value data. fitted model involved preprocessing data appropriately generate lagged predictors, estimating linear model stats::lm() postprocessing results meaningful epidemiological tasks. can also examine predictions. results show distributional forecast produced using data end 2021 14th January 2022. prediction death rate per 100K inhabitants available every state (geo_value) along 90% predictive interval.","code":"library(tidyverse) library(epipredict) jhu <- case_death_rate_subset jhu #> An `epi_df` object, 20,496 x 4 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 12:08:25.791826 #> #> # A tibble: 20,496 × 4 #> geo_value time_value case_rate death_rate #> * #> 1 ak 2020-12-31 35.9 0.158 #> 2 al 2020-12-31 65.1 0.438 #> 3 ar 2020-12-31 66.0 1.27 #> 4 as 2020-12-31 0 0 #> 5 az 2020-12-31 76.8 1.10 #> 6 ca 2020-12-31 96.0 0.751 #> 7 co 2020-12-31 35.8 0.649 #> 8 ct 2020-12-31 52.1 0.819 #> 9 dc 2020-12-31 31.0 0.601 #> 10 de 2020-12-31 65.2 0.807 #> # ℹ 20,486 more rows two_week_ahead <- arx_forecaster( jhu, outcome = \"death_rate\", predictors = c(\"case_rate\", \"death_rate\"), args_list = arx_args_list( lags = list(c(0,1,2,3,7,14), c(0,7,14)), ahead = 14 ) ) two_week_ahead$epi_workflow #> ══ Epi Workflow [trained] ══════════════════════════════════════════════════════ #> Preprocessor: Recipe #> Model: linear_reg() #> Postprocessor: Frosting #> #> ── Preprocessor ──────────────────────────────────────────────────────────────── #> 6 Recipe Steps #> #> • step_epi_lag() #> • step_epi_lag() #> • step_epi_ahead() #> • step_naomit() #> • step_naomit() #> • step_training_window() #> #> ── Model ─────────────────────────────────────────────────────────────────────── #> #> Call: #> stats::lm(formula = ..y ~ ., data = data) #> #> Coefficients: #> (Intercept) lag_0_case_rate lag_1_case_rate lag_2_case_rate #> -0.0073358 0.0030365 0.0012467 0.0009536 #> lag_3_case_rate lag_7_case_rate lag_14_case_rate lag_0_death_rate #> 0.0011425 0.0012481 0.0003041 0.1351769 #> lag_7_death_rate lag_14_death_rate #> 0.1471127 0.1062473 #> #> ── Postprocessor ─────────────────────────────────────────────────────────────── #> 5 Frosting Layers #> #> • layer_predict() #> • layer_residual_quantiles() #> • layer_add_forecast_date() #> • layer_add_target_date() #> • layer_threshold() two_week_ahead$predictions #> # A tibble: 56 × 5 #> geo_value .pred .pred_distn forecast_date target_date #> #> 1 ak 0.449 [0.05, 0.95] 2021-12-31 2022-01-14 #> 2 al 0.574 [0.05, 0.95] 2021-12-31 2022-01-14 #> 3 ar 0.673 [0.05, 0.95] 2021-12-31 2022-01-14 #> 4 as 0 [0.05, 0.95] 2021-12-31 2022-01-14 #> 5 az 0.679 [0.05, 0.95] 2021-12-31 2022-01-14 #> 6 ca 0.575 [0.05, 0.95] 2021-12-31 2022-01-14 #> 7 co 0.862 [0.05, 0.95] 2021-12-31 2022-01-14 #> 8 ct 1.07 [0.05, 0.95] 2021-12-31 2022-01-14 #> 9 dc 2.12 [0.05, 0.95] 2021-12-31 2022-01-14 #> 10 de 1.09 [0.05, 0.95] 2021-12-31 2022-01-14 #> # ℹ 46 more rows"},{"path":"https://cmu-delphi.github.io/epipredict/reference/add_epi_recipe.html","id":null,"dir":"Reference","previous_headings":"","what":"Add an epi_recipe to a workflow — add_epi_recipe","title":"Add an epi_recipe to a workflow — add_epi_recipe","text":"Add epi_recipe workflow","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/add_epi_recipe.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Add an epi_recipe to a workflow — add_epi_recipe","text":"","code":"add_epi_recipe(x, recipe, ..., blueprint = default_epi_recipe_blueprint())"},{"path":"https://cmu-delphi.github.io/epipredict/reference/add_epi_recipe.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Add an epi_recipe to a workflow — add_epi_recipe","text":"x workflow epi_workflow recipe recipe created using recipes::recipe() ... used. blueprint hardhat blueprint used fine tuning preprocessing. default_epi_recipe_blueprint() used. Note preprocessing done separate preprocessing might done automatically underlying model.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/add_epi_recipe.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Add an epi_recipe to a workflow — add_epi_recipe","text":"x, updated new recipe preprocessor.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/add_epi_recipe.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Add an epi_recipe to a workflow — add_epi_recipe","text":"behaviour workflows::add_recipe() sets different default blueprint automatically handle epiprocess::epi_df data.","code":""},{"path":[]},{"path":"https://cmu-delphi.github.io/epipredict/reference/add_epi_recipe.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Add an epi_recipe to a workflow — add_epi_recipe","text":"","code":"library(epiprocess) library(dplyr) #> #> Attaching package: ‘dplyr’ #> The following objects are masked from ‘package:stats’: #> #> filter, lag #> The following objects are masked from ‘package:base’: #> #> intersect, setdiff, setequal, union library(recipes) #> #> Attaching package: ‘recipes’ #> The following object is masked from ‘package:stats’: #> #> step jhu <- case_death_rate_subset %>% filter(time_value > \"2021-08-01\") %>% dplyr::arrange(geo_value, time_value) r <- epi_recipe(jhu) %>% step_epi_lag(death_rate, lag = c(0, 7, 14)) %>% step_epi_ahead(death_rate, ahead = 7) %>% step_epi_lag(case_rate, lag = c(0, 7, 14)) %>% step_naomit(all_predictors()) %>% step_naomit(all_outcomes(), skip = TRUE) workflow <- epi_workflow() %>% add_epi_recipe(r) workflow #> ══ Epi Workflow ════════════════════════════════════════════════════════════════ #> Preprocessor: Recipe #> Model: None #> Postprocessor: None #> #> ── Preprocessor ──────────────────────────────────────────────────────────────── #> 5 Recipe Steps #> #> • step_epi_lag() #> • step_epi_ahead() #> • step_epi_lag() #> • step_naomit() #> • step_naomit()"},{"path":"https://cmu-delphi.github.io/epipredict/reference/add_frosting.html","id":null,"dir":"Reference","previous_headings":"","what":"Add frosting to a workflow — add_frosting","title":"Add frosting to a workflow — add_frosting","text":"Add frosting workflow","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/add_frosting.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Add frosting to a workflow — add_frosting","text":"","code":"add_frosting(x, frosting, ...) remove_frosting(x)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/add_frosting.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Add frosting to a workflow — add_frosting","text":"x workflow frosting frosting layer created using frosting() ... used.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/add_frosting.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Add frosting to a workflow — add_frosting","text":"x, updated new removed frosting postprocessor","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/add_frosting.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Add frosting to a workflow — add_frosting","text":"","code":"jhu <- case_death_rate_subset %>% filter(time_value > \"2021-11-01\", geo_value %in% c(\"ak\", \"ca\", \"ny\")) r <- epi_recipe(jhu) %>% step_epi_lag(death_rate, lag = c(0, 7, 14)) %>% step_epi_ahead(death_rate, ahead = 7) %>% step_epi_naomit() wf <- epi_workflow(r, parsnip::linear_reg()) %>% fit(jhu) latest <- jhu %>% dplyr::filter(time_value >= max(time_value) - 14) # Add frosting to a workflow and predict f <- frosting() %>% layer_predict() %>% layer_naomit(.pred) wf1 <- wf %>% add_frosting(f) p1 <- predict(wf1, latest) p1 #> An `epi_df` object, 3 x 3 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 3 × 3 #> geo_value time_value .pred #> * #> 1 ak 2021-12-31 0.245 #> 2 ca 2021-12-31 0.313 #> 3 ny 2021-12-31 0.295 # Remove frosting from the workflow and predict wf2 <- wf1 %>% remove_frosting() p2 <- predict(wf2, latest) p2 #> An `epi_df` object, 3 x 3 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 3 × 3 #> geo_value time_value .pred #> * #> 1 ak 2021-12-31 0.245 #> 2 ca 2021-12-31 0.313 #> 3 ny 2021-12-31 0.295"},{"path":"https://cmu-delphi.github.io/epipredict/reference/add_layer.html","id":null,"dir":"Reference","previous_headings":"","what":"Add layer to a frosting object — add_layer","title":"Add layer to a frosting object — add_layer","text":"Add layer frosting object","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/add_layer.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Add layer to a frosting object — add_layer","text":"","code":"add_layer(frosting, object)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/add_layer.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Add layer to a frosting object — add_layer","text":"frosting frosting postprocessor object frosting layer","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/add_layer.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Add layer to a frosting object — add_layer","text":"updated frosting postprocessor","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/apply_frosting.html","id":null,"dir":"Reference","previous_headings":"","what":"Apply postprocessing to a fitted workflow — apply_frosting","title":"Apply postprocessing to a fitted workflow — apply_frosting","text":"function intended internal use. implements postprocessing inside predict() method fitted workflow.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/apply_frosting.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Apply postprocessing to a fitted workflow — apply_frosting","text":"","code":"apply_frosting(workflow, ...) # S3 method for default apply_frosting(workflow, components, ...) # S3 method for epi_workflow apply_frosting(workflow, components, new_data, ...)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/apply_frosting.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Apply postprocessing to a fitted workflow — apply_frosting","text":"workflow object class workflow ... additional arguments passed methods components list components containing model information. updated returned layer. mold - output calling hardhat::mold() workflow. contains information preprocessing, including recipe. forged - output calling hardhat::forge() workflow. predictors outcomes new_data. three components predictors, outcomes (new_data), extras (usually rest data, including keys). keys - put keys (time_value, geo_value, others) ease. new_data data frame containing new predictors preprocess predict ","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_args_list.html","id":null,"dir":"Reference","previous_headings":"","what":"ARX forecaster argument constructor — arx_args_list","title":"ARX forecaster argument constructor — arx_args_list","text":"Constructs list arguments arx_forecaster().","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_args_list.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"ARX forecaster argument constructor — arx_args_list","text":"","code":"arx_args_list( lags = c(0L, 7L, 14L), ahead = 7L, n_training = Inf, forecast_date = NULL, target_date = NULL, levels = c(0.05, 0.95), symmetrize = TRUE, nonneg = TRUE, quantile_by_key = character(0L), nafill_buffer = Inf )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_args_list.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"ARX forecaster argument constructor — arx_args_list","text":"lags Vector List. Positive integers enumerating lags use autoregressive-type models (days). default, unnamed list lags set correspond order predictors. ahead Integer. Number time steps ahead (days) forecast date forecasts produced. n_training Integer. upper limit number rows per key used training (time unit epi_df). forecast_date Date. date forecast created. default NULL attempt determine automatically. target_date Date. date forecast intended. default NULL attempt determine automatically. levels Vector NULL. vector probabilities produce prediction intervals. created computing quantiles training residuals. NULL value result point forecasts . symmetrize Logical. default TRUE calculates symmetric prediction intervals. argument applies residual quantiles used. applicable trainer = quantile_reg(), example. nonneg Logical. default TRUE enforces nonnegative predictions hard-thresholding 0. quantile_by_key Character vector. Groups residuals listed keys calculating residual quantiles. See by_key argument layer_residual_quantiles() information. default, character(0) performs grouping. argument applies residual quantiles used. applicable trainer = quantile_reg(), example. nafill_buffer predict time, recent values training data used create forecast. However, can NA due , e.g., data latency issues. default, missing values get filled less recent data. Setting value NULL result 1 extra recent row (beyond required lag creation) used. Note require least min(lags) rows recent data per geo_value create prediction. reason, setting nafill_buffer < min(lags) treated additional allowed recent data rather total amount recent data examine.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_args_list.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"ARX forecaster argument constructor — arx_args_list","text":"list containing updated parameter choices class arx_flist.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_args_list.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"ARX forecaster argument constructor — arx_args_list","text":"","code":"arx_args_list() #> List of 11 #> $ lags : int [1:3] 0 7 14 #> $ ahead : int 7 #> $ n_training : num Inf #> $ levels : num [1:2] 0.05 0.95 #> $ forecast_date : NULL #> $ target_date : NULL #> $ symmetrize : logi TRUE #> $ nonneg : logi TRUE #> $ max_lags : int 14 #> $ quantile_by_key: chr(0) #> $ nafill_buffer : num Inf #> - attr(*, \"class\")= chr [1:2] \"arx_fcast\" \"alist\" arx_args_list(symmetrize = FALSE) #> List of 11 #> $ lags : int [1:3] 0 7 14 #> $ ahead : int 7 #> $ n_training : num Inf #> $ levels : num [1:2] 0.05 0.95 #> $ forecast_date : NULL #> $ target_date : NULL #> $ symmetrize : logi FALSE #> $ nonneg : logi TRUE #> $ max_lags : int 14 #> $ quantile_by_key: chr(0) #> $ nafill_buffer : num Inf #> - attr(*, \"class\")= chr [1:2] \"arx_fcast\" \"alist\" arx_args_list(levels = c(.1, .3, .7, .9), n_training = 120) #> List of 11 #> $ lags : int [1:3] 0 7 14 #> $ ahead : int 7 #> $ n_training : num 120 #> $ levels : num [1:4] 0.1 0.3 0.7 0.9 #> $ forecast_date : NULL #> $ target_date : NULL #> $ symmetrize : logi TRUE #> $ nonneg : logi TRUE #> $ max_lags : int 14 #> $ quantile_by_key: chr(0) #> $ nafill_buffer : num Inf #> - attr(*, \"class\")= chr [1:2] \"arx_fcast\" \"alist\""},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_class_args_list.html","id":null,"dir":"Reference","previous_headings":"","what":"ARX classifier argument constructor — arx_class_args_list","title":"ARX classifier argument constructor — arx_class_args_list","text":"Constructs list arguments arx_classifier().","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_class_args_list.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"ARX classifier argument constructor — arx_class_args_list","text":"","code":"arx_class_args_list( lags = c(0L, 7L, 14L), ahead = 7L, n_training = Inf, forecast_date = NULL, target_date = NULL, outcome_transform = c(\"growth_rate\", \"lag_difference\"), breaks = 0.25, horizon = 7L, method = c(\"rel_change\", \"linear_reg\", \"smooth_spline\", \"trend_filter\"), log_scale = FALSE, additional_gr_args = list(), nafill_buffer = Inf )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_class_args_list.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"ARX classifier argument constructor — arx_class_args_list","text":"lags Vector List. Positive integers enumerating lags use autoregressive-type models (days). default, unnamed list lags set correspond order predictors. ahead Integer. Number time steps ahead (days) forecast date forecasts produced. n_training Integer. upper limit number rows per key used training (time unit epi_df). forecast_date Date. date forecast created. default NULL attempt determine automatically. target_date Date. date forecast intended. default NULL attempt determine automatically. outcome_transform Scalar character. Whether outcome created using growth rates (predictors ) lagged differences. second case closer requirements 2022-23 CDC Flusight Hospitalization Experimental Target. See Classification Vignette details create reasonable baseline case. Selecting \"growth_rate\" (default) uses epiprocess::growth_rate() create outcome using additional arguments . Choosing \"lag_difference\" instead simply uses change value selected horizon. breaks Vector. vector breaks turn real-valued growth rates discrete classes. default gives binary upswing classification McDonald, Bien, Green, Hu, et al.. coincides default trainer = parsnip::logistic_reg() argument arx_classifier(). However, multiclass classification also supported (e.g. breaks = c(-.2, .25)) provided trainer = parsnip::multinom_reg() (another multiclass trainer) used well. sliently expanded cover entire real line (default become breaks = c(-Inf, .25, Inf)) used discretize response. different behaviour recipes::step_cut() creates classes cover range training data. horizon Scalar integer. passed h argument epiprocess::growth_rate(). determines amount data used calculate growth rate. method Character. Options available growth rate calculation. log_scale Scalar logical. Whether compute growth rates log scale. additional_gr_args List. Optional arguments controlling growth rate calculation. See epiprocess::growth_rate() related Vignette details. nafill_buffer predict time, recent values training data used create forecast. However, can NA due , e.g., data latency issues. default, missing values get filled less recent data. Setting value NULL result 1 extra recent row (beyond required lag creation) used. Note require least min(lags) rows recent data per geo_value create prediction. reason, setting nafill_buffer < min(lags) treated additional allowed recent data rather total amount recent data examine.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_class_args_list.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"ARX classifier argument constructor — arx_class_args_list","text":"list containing updated parameter choices class arx_clist.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_class_args_list.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"ARX classifier argument constructor — arx_class_args_list","text":"","code":"arx_class_args_list() #> List of 13 #> $ lags : int [1:3] 0 7 14 #> $ ahead : int 7 #> $ n_training : num Inf #> $ breaks : num [1:3] -Inf 0.25 Inf #> $ forecast_date : NULL #> $ target_date : NULL #> $ outcome_transform : chr \"growth_rate\" #> $ max_lags : int 14 #> $ horizon : int 7 #> $ method : chr \"rel_change\" #> $ log_scale : logi FALSE #> $ additional_gr_args: list() #> $ nafill_buffer : num Inf #> - attr(*, \"class\")= chr [1:2] \"arx_class\" \"alist\" # 3-class classsification, # also needs arx_classifier(trainer = parsnip::multinom_reg()) arx_class_args_list(breaks = c(-.2, .25)) #> List of 13 #> $ lags : int [1:3] 0 7 14 #> $ ahead : int 7 #> $ n_training : num Inf #> $ breaks : num [1:4] -Inf -0.2 0.25 Inf #> $ forecast_date : NULL #> $ target_date : NULL #> $ outcome_transform : chr \"growth_rate\" #> $ max_lags : int 14 #> $ horizon : int 7 #> $ method : chr \"rel_change\" #> $ log_scale : logi FALSE #> $ additional_gr_args: list() #> $ nafill_buffer : num Inf #> - attr(*, \"class\")= chr [1:2] \"arx_class\" \"alist\""},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_class_epi_workflow.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a template arx_classifier workflow — arx_class_epi_workflow","title":"Create a template arx_classifier workflow — arx_class_epi_workflow","text":"function creates unfit workflow use arx_classifier(). useful want make small modifications classifier fitting predicting. Supplying trainer function may alter returned epi_workflow object can omitted.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_class_epi_workflow.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a template arx_classifier workflow — arx_class_epi_workflow","text":"","code":"arx_class_epi_workflow( epi_data, outcome, predictors, trainer = NULL, args_list = arx_class_args_list() )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_class_epi_workflow.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a template arx_classifier workflow — arx_class_epi_workflow","text":"epi_data epi_df object outcome character (scalar) specifying outcome (epi_df). Note arx_forecaster(), expected real-valued. Conversion data unordered classes handled internally based breaks argument arx_class_args_list(). discrete classes already epi_df, recommended code classifier scratch using epi_recipe(). predictors character vector giving column(s) predictor variables. trainer {parsnip} model describing type estimation. now, enforce mode = \"classification\". Typical values parsnip::logistic_reg() parsnip::multinom_reg(). complicated trainers like parsnip::naive_Bayes() parsnip::rand_forest() can also used. May NULL (default). args_list list customization arguments determine type forecasting model. See arx_class_args_list().","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_class_epi_workflow.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a template arx_classifier workflow — arx_class_epi_workflow","text":"unfit epi_workflow.","code":""},{"path":[]},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_class_epi_workflow.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create a template arx_classifier workflow — arx_class_epi_workflow","text":"","code":"jhu <- case_death_rate_subset %>% dplyr::filter(time_value >= as.Date(\"2021-11-01\")) arx_class_epi_workflow(jhu, \"death_rate\", c(\"case_rate\", \"death_rate\")) #> ══ Epi Workflow ════════════════════════════════════════════════════════════════ #> Preprocessor: Recipe #> Model: None #> Postprocessor: Frosting #> #> ── Preprocessor ──────────────────────────────────────────────────────────────── #> 8 Recipe Steps #> #> • step_growth_rate() #> • step_epi_lag() #> • step_epi_lag() #> • step_epi_ahead() #> • step_mutate() #> • step_naomit() #> • step_naomit() #> • step_training_window() #> ── Postprocessor ─────────────────────────────────────────────────────────────── #> 3 Frosting Layers #> #> • layer_predict() #> • layer_add_forecast_date() #> • layer_add_target_date() arx_class_epi_workflow( jhu, \"death_rate\", c(\"case_rate\", \"death_rate\"), trainer = parsnip::multinom_reg(), args_list = arx_class_args_list( breaks = c(-.05, .1), ahead = 14, horizon = 14, method = \"linear_reg\" ) ) #> ══ Epi Workflow ════════════════════════════════════════════════════════════════ #> Preprocessor: Recipe #> Model: multinom_reg() #> Postprocessor: Frosting #> #> ── Preprocessor ──────────────────────────────────────────────────────────────── #> 8 Recipe Steps #> #> • step_growth_rate() #> • step_epi_lag() #> • step_epi_lag() #> • step_epi_ahead() #> • step_mutate() #> • step_naomit() #> • step_naomit() #> • step_training_window() #> #> ── Model ─────────────────────────────────────────────────────────────────────── #> Multinomial Regression Model Specification (classification) #> #> Computational engine: nnet #> #> ── Postprocessor ─────────────────────────────────────────────────────────────── #> 3 Frosting Layers #> #> • layer_predict() #> • layer_add_forecast_date() #> • layer_add_target_date()"},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_classifier.html","id":null,"dir":"Reference","previous_headings":"","what":"Direct autoregressive classifier with covariates — arx_classifier","title":"Direct autoregressive classifier with covariates — arx_classifier","text":"autoregressive classification model epiprocess::epi_df data. \"direct\" forecasting, meaning estimates class particular target horizon.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_classifier.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Direct autoregressive classifier with covariates — arx_classifier","text":"","code":"arx_classifier( epi_data, outcome, predictors, trainer = parsnip::logistic_reg(), args_list = arx_class_args_list() )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_classifier.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Direct autoregressive classifier with covariates — arx_classifier","text":"epi_data epi_df object outcome character (scalar) specifying outcome (epi_df). Note arx_forecaster(), expected real-valued. Conversion data unordered classes handled internally based breaks argument arx_class_args_list(). discrete classes already epi_df, recommended code classifier scratch using epi_recipe(). predictors character vector giving column(s) predictor variables. trainer {parsnip} model describing type estimation. now, enforce mode = \"classification\". Typical values parsnip::logistic_reg() parsnip::multinom_reg(). complicated trainers like parsnip::naive_Bayes() parsnip::rand_forest() can also used. args_list list customization arguments determine type forecasting model. See arx_class_args_list().","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_classifier.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Direct autoregressive classifier with covariates — arx_classifier","text":"list (1) predictions epi_df predicted classes (2) epi_workflow, list encapsulates entire estimation workflow","code":""},{"path":[]},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_classifier.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Direct autoregressive classifier with covariates — arx_classifier","text":"","code":"jhu <- case_death_rate_subset %>% dplyr::filter(time_value >= as.Date(\"2021-11-01\")) out <- arx_classifier(jhu, \"death_rate\", c(\"case_rate\", \"death_rate\")) #> Warning: The forecast_date is less than the most recent update date of the data: forecast_date = 2021-12-31 while data is from 2022-05-31. out <- arx_classifier( jhu, \"death_rate\", c(\"case_rate\", \"death_rate\"), trainer = parsnip::multinom_reg(), args_list = arx_class_args_list( breaks = c(-.05, .1), ahead = 14, horizon = 14, method = \"linear_reg\" ) ) #> Warning: The forecast_date is less than the most recent update date of the data: forecast_date = 2021-12-31 while data is from 2022-05-31."},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_fcast_epi_workflow.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a template arx_forecaster workflow — arx_fcast_epi_workflow","title":"Create a template arx_forecaster workflow — arx_fcast_epi_workflow","text":"function creates unfit workflow use arx_forecaster(). useful want make small modifications forecaster fitting predicting. Supplying trainer function may alter returned epi_workflow object (e.g., intend use quantile_reg()) can omitted.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_fcast_epi_workflow.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a template arx_forecaster workflow — arx_fcast_epi_workflow","text":"","code":"arx_fcast_epi_workflow( epi_data, outcome, predictors, trainer = NULL, args_list = arx_args_list() )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_fcast_epi_workflow.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a template arx_forecaster workflow — arx_fcast_epi_workflow","text":"epi_data epi_df object outcome character (scalar) specifying outcome (epi_df). predictors character vector giving column(s) predictor variables. trainer {parsnip} model describing type estimation. now, enforce mode = \"regression\". May NULL (default). args_list list customization arguments determine type forecasting model. See arx_args_list().","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_fcast_epi_workflow.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a template arx_forecaster workflow — arx_fcast_epi_workflow","text":"unfitted epi_workflow.","code":""},{"path":[]},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_fcast_epi_workflow.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create a template arx_forecaster workflow — arx_fcast_epi_workflow","text":"","code":"jhu <- case_death_rate_subset %>% dplyr::filter(time_value >= as.Date(\"2021-12-01\")) arx_fcast_epi_workflow(jhu, \"death_rate\", c(\"case_rate\", \"death_rate\")) #> ══ Epi Workflow ════════════════════════════════════════════════════════════════ #> Preprocessor: Recipe #> Model: None #> Postprocessor: Frosting #> #> ── Preprocessor ──────────────────────────────────────────────────────────────── #> 6 Recipe Steps #> #> • step_epi_lag() #> • step_epi_lag() #> • step_epi_ahead() #> • step_naomit() #> • step_naomit() #> • step_training_window() #> ── Postprocessor ─────────────────────────────────────────────────────────────── #> 5 Frosting Layers #> #> • layer_predict() #> • layer_residual_quantiles() #> • layer_add_forecast_date() #> • layer_add_target_date() #> • layer_threshold() arx_fcast_epi_workflow(jhu, \"death_rate\", c(\"case_rate\", \"death_rate\"), trainer = quantile_reg(), args_list = arx_args_list(levels = 1:9 / 10)) #> ══ Epi Workflow ════════════════════════════════════════════════════════════════ #> Preprocessor: Recipe #> Model: quantile_reg() #> Postprocessor: Frosting #> #> ── Preprocessor ──────────────────────────────────────────────────────────────── #> 6 Recipe Steps #> #> • step_epi_lag() #> • step_epi_lag() #> • step_epi_ahead() #> • step_naomit() #> • step_naomit() #> • step_training_window() #> #> ── Model ─────────────────────────────────────────────────────────────────────── #> quantile reg Model Specification (regression) #> #> Main Arguments: #> tau = c(0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9) #> #> Computational engine: rq #> #> ── Postprocessor ─────────────────────────────────────────────────────────────── #> 6 Frosting Layers #> #> • layer_predict() #> • layer_quantile_distn() #> • layer_point_from_distn() #> • layer_add_forecast_date() #> • layer_add_target_date() #> • layer_threshold()"},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_forecaster.html","id":null,"dir":"Reference","previous_headings":"","what":"Direct autoregressive forecaster with covariates — arx_forecaster","title":"Direct autoregressive forecaster with covariates — arx_forecaster","text":"autoregressive forecasting model epiprocess::epi_df data. \"direct\" forecasting, meaning estimates model particular target horizon.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_forecaster.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Direct autoregressive forecaster with covariates — arx_forecaster","text":"","code":"arx_forecaster( epi_data, outcome, predictors, trainer = parsnip::linear_reg(), args_list = arx_args_list() )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_forecaster.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Direct autoregressive forecaster with covariates — arx_forecaster","text":"epi_data epi_df object outcome character (scalar) specifying outcome (epi_df). predictors character vector giving column(s) predictor variables. trainer {parsnip} model describing type estimation. now, enforce mode = \"regression\". args_list list customization arguments determine type forecasting model. See arx_args_list().","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_forecaster.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Direct autoregressive forecaster with covariates — arx_forecaster","text":"list (1) predictions epi_df predicted values (2) epi_workflow, list encapsulates entire estimation workflow","code":""},{"path":[]},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_forecaster.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Direct autoregressive forecaster with covariates — arx_forecaster","text":"","code":"jhu <- case_death_rate_subset %>% dplyr::filter(time_value >= as.Date(\"2021-12-01\")) out <- arx_forecaster(jhu, \"death_rate\", c(\"case_rate\", \"death_rate\")) #> Warning: The forecast_date is less than the most recent update date of the data: forecast_date = 2021-12-31 while data is from 2022-05-31. out <- arx_forecaster(jhu, \"death_rate\", c(\"case_rate\", \"death_rate\"), trainer = quantile_reg(), args_list = arx_args_list(levels = 1:9 / 10)) #> Warning: The forecast_date is less than the most recent update date of the data: forecast_date = 2021-12-31 while data is from 2022-05-31."},{"path":"https://cmu-delphi.github.io/epipredict/reference/augment.epi_workflow.html","id":null,"dir":"Reference","previous_headings":"","what":"Augment data with predictions — augment.epi_workflow","title":"Augment data with predictions — augment.epi_workflow","text":"Augment data predictions","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/augment.epi_workflow.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Augment data with predictions — augment.epi_workflow","text":"","code":"# S3 method for epi_workflow augment(x, new_data, ...)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/augment.epi_workflow.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Augment data with predictions — augment.epi_workflow","text":"x trained epi_workflow new_data epi_df predictors ... Arguments passed predict method.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/augment.epi_workflow.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Augment data with predictions — augment.epi_workflow","text":"new_data additional columns containing predicted values","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/bake.html","id":null,"dir":"Reference","previous_headings":"","what":"Bake an epi_recipe — bake.epi_recipe","title":"Bake an epi_recipe — bake.epi_recipe","text":"Bake epi_recipe","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/bake.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Bake an epi_recipe — bake.epi_recipe","text":"","code":"# S3 method for epi_recipe bake(object, new_data, ...)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/bake.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Bake an epi_recipe — bake.epi_recipe","text":"object trained object recipe() least one preprocessing operation. new_data epi_df, data frame tibble preprocessing applied. NULL given new_data, pre-processed training data returned. ... One selector functions choose variables returned function. See recipes::selections() details. selectors given, default use tidyselect::everything().","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/bake.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Bake an epi_recipe — bake.epi_recipe","text":"epi_df may different columns original columns new_data.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/case_death_rate_subset.html","id":null,"dir":"Reference","previous_headings":"","what":"Subset of JHU daily state cases and deaths — case_death_rate_subset","title":"Subset of JHU daily state cases and deaths — case_death_rate_subset","text":"data source confirmed COVID-19 cases deaths based reports made available Center Systems Science Engineering Johns Hopkins University. example data ranges Dec 31, 2020 Dec 31, 2021, includes states.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/case_death_rate_subset.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Subset of JHU daily state cases and deaths — case_death_rate_subset","text":"","code":"case_death_rate_subset"},{"path":"https://cmu-delphi.github.io/epipredict/reference/case_death_rate_subset.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Subset of JHU daily state cases and deaths — case_death_rate_subset","text":"tibble 20,496 rows 4 variables: geo_value geographic value associated row measurements. time_value time value associated row measurements. case_rate 7-day average signal number new confirmed COVID-19 cases per 100,000 population, daily death_rate 7-day average signal number new confirmed deaths due COVID-19 per 100,000 population, daily","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/case_death_rate_subset.html","id":"source","dir":"Reference","previous_headings":"","what":"Source","title":"Subset of JHU daily state cases and deaths — case_death_rate_subset","text":"object contains modified part COVID-19 Data Repository Center Systems Science Engineering (CSSE) Johns Hopkins University republished COVIDcast Epidata API. data set licensed terms Creative Commons Attribution 4.0 International license Johns Hopkins University behalf Center Systems Science Engineering. Copyright Johns Hopkins University 2020. Modifications: COVIDcast Epidata API: signals taken directly JHU CSSE COVID-19 GitHub repository without changes. 7-day average signals computed Delphi calculating moving averages preceding 7 days, signal June 7 average underlying data June 1 7, inclusive.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/check_pname.html","id":null,"dir":"Reference","previous_headings":"","what":"Check that newly created variable names don't overlap — check_pname","title":"Check that newly created variable names don't overlap — check_pname","text":"check_pname used slather method ensure newly created variable names overlap existing names. Throws warning check fails, creates random string.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/check_pname.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Check that newly created variable names don't overlap — check_pname","text":"","code":"check_pname(res, preds, object, newname = NULL)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/check_pname.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Check that newly created variable names don't overlap — check_pname","text":"res data frame tibble newly created variables. preds epi_df tibble containing predictions. object layer object passed slather(). newname string variable names object contain $name element","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/create_layer.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a new layer — create_layer","title":"Create a new layer — create_layer","text":"function creates skeleton new frosting layer. called inside package, create R script R/ directory, fill name layer, open file.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/create_layer.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a new layer — create_layer","text":"","code":"create_layer(name = NULL, open = rlang::is_interactive())"},{"path":"https://cmu-delphi.github.io/epipredict/reference/create_layer.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a new layer — create_layer","text":"name Either string giving file name (without directory) NULL take name currently open file RStudio. open Whether open file interactive editing.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/create_layer.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create a new layer — create_layer","text":"","code":"if (FALSE) { # Note: running this will write `layer_strawberry.R` to # the `R/` directory of your current project create_layer(\"strawberry\") }"},{"path":"https://cmu-delphi.github.io/epipredict/reference/dist_quantiles.html","id":null,"dir":"Reference","previous_headings":"","what":"A distribution parameterized by a set of quantiles — dist_quantiles","title":"A distribution parameterized by a set of quantiles — dist_quantiles","text":"distribution parameterized set quantiles","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/dist_quantiles.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"A distribution parameterized by a set of quantiles — dist_quantiles","text":"","code":"dist_quantiles(x, tau)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/dist_quantiles.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"A distribution parameterized by a set of quantiles — dist_quantiles","text":"x vector values tau vector probabilities corresponding x","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/dist_quantiles.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"A distribution parameterized by a set of quantiles — dist_quantiles","text":"","code":"dstn <- dist_quantiles(list(1:4, 8:11), list(c(.2,.4,.6,.8))) quantile(dstn, p = c(.1, .25, .5, .9)) #> [[1]] #> [1] 0.124961 1.250000 2.500000 4.875039 #> #> [[2]] #> [1] 7.124961 8.250000 9.500000 11.875039 #> median(dstn) #> [1] 2.5 9.5 # it's a bit annoying to inspect the data vctrs::vec_data(vctrs::vec_data(dstn[1])[[1]]) #> q tau #> 1 1 0.2 #> 2 2 0.4 #> 3 3 0.6 #> 4 4 0.8"},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_juice.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract transformed training set — epi_juice","title":"Extract transformed training set — epi_juice","text":"Extract transformed training set","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_juice.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract transformed training set — epi_juice","text":"","code":"epi_juice(object, ...)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_juice.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Extract transformed training set — epi_juice","text":"object trained object recipe() least one preprocessing operation. ... One selector functions choose variables returned function. See recipes::selections() details. selectors given, default use tidyselect::everything().","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_keys.html","id":null,"dir":"Reference","previous_headings":"","what":"Grab any keys associated to an epi_df — epi_keys","title":"Grab any keys associated to an epi_df — epi_keys","text":"Grab keys associated epi_df","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_keys.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Grab any keys associated to an epi_df — epi_keys","text":"","code":"epi_keys(x, ...)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_keys.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Grab any keys associated to an epi_df — epi_keys","text":"x data.frame, tibble, epi_df ... additional arguments passed methods","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_keys.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Grab any keys associated to an epi_df — epi_keys","text":"epi_df, returns \"keys\". Otherwise NULL","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_recipe.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a epi_recipe for preprocessing data — epi_recipe","title":"Create a epi_recipe for preprocessing data — epi_recipe","text":"recipe description steps applied data set order prepare data analysis. loose wrapper around recipes::recipe() properly handle additional columns present epi_df","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_recipe.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a epi_recipe for preprocessing data — epi_recipe","text":"","code":"epi_recipe(x, ...) # S3 method for default epi_recipe(x, ...) # S3 method for epi_df epi_recipe(x, formula = NULL, ..., vars = NULL, roles = NULL) # S3 method for formula epi_recipe(formula, data, ...)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_recipe.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a epi_recipe for preprocessing data — epi_recipe","text":"x, data data frame, tibble, epi_df template data set (see ). always coerced first row avoid memory issues ... arguments passed methods (currently used). formula model formula. -line functions used (e.g. log(x), x:y, etc.) minus signs allowed. types transformations enacted using step functions package. Dots allowed simple multivariate outcome terms (.e. need cbind; see Examples). vars character string column names corresponding variables used context (see ) roles character string (length vars) describes single role variable take. value anything common roles \"outcome\", \"predictor\", \"time_value\", \"geo_value\"","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_recipe.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a epi_recipe for preprocessing data — epi_recipe","text":"object class recipe sub-objects: var_info tibble containing information original data set columns term_info tibble contains current set terms data set. initially defaults data contained var_info. steps list step check objects define sequence preprocessing operations applied data. default value NULL template tibble data. initialized data given data argument can different recipe trained.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_recipe.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create a epi_recipe for preprocessing data — epi_recipe","text":"","code":"library(epiprocess) library(dplyr) library(recipes) jhu <- case_death_rate_subset %>% dplyr::filter(time_value > \"2021-08-01\") %>% dplyr::arrange(geo_value, time_value) r <- epi_recipe(jhu) %>% step_epi_lag(death_rate, lag = c(0, 7, 14)) %>% step_epi_ahead(death_rate, ahead = 7) %>% step_epi_lag(case_rate, lag = c(0, 7, 14)) %>% step_naomit(all_predictors()) %>% # below, `skip` means we don't do this at predict time step_naomit(all_outcomes(), skip = TRUE) r #> #> ── Recipe ────────────────────────────────────────────────────────────────────── #> #> ── Inputs #> Number of variables by role #> raw: 2 #> geo_value: 1 #> time_value: 1 #> #> ── Operations #> • Lagging: death_rate by 0, 7, 14 #> • Leading: death_rate by 7 #> • Lagging: case_rate by 0, 7, 14 #> • Removing rows with NA values in: all_predictors() #> • Removing rows with NA values in: all_outcomes()"},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_shift.html","id":null,"dir":"Reference","previous_headings":"","what":"Shift predictors while maintaining grouping and time_value ordering — epi_shift","title":"Shift predictors while maintaining grouping and time_value ordering — epi_shift","text":"lower-level function. performs error checking.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_shift.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Shift predictors while maintaining grouping and time_value ordering — epi_shift","text":"","code":"epi_shift(x, shifts, time_value, keys = NULL, out_name = \"x\")"},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_shift.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Shift predictors while maintaining grouping and time_value ordering — epi_shift","text":"x Data frame. Variables shift shifts List. list element vector shifts. Negative values produce leads. list length number columns x. time_value Vector. length x giving time stamps. keys Data frame, vector, NULL. Additional grouping vars. out_name Chr. output list use prefix.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_shift.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Shift predictors while maintaining grouping and time_value ordering — epi_shift","text":"list tibbles","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_workflow.html","id":null,"dir":"Reference","previous_headings":"","what":"Create an epi_workflow — epi_workflow","title":"Create an epi_workflow — epi_workflow","text":"container object unifies preprocessing, fitting, prediction, postprocessing predictive modeling epidemiological data. extends functionality workflows::workflow() handle typical panel data structures found field. extension handled completely internally, invisible user. intents purposes, operates exactly like workflows::workflow(). details numerous examples, see .","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_workflow.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create an epi_workflow — epi_workflow","text":"","code":"epi_workflow(preprocessor = NULL, spec = NULL, postprocessor = NULL)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_workflow.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create an epi_workflow — epi_workflow","text":"preprocessor optional preprocessor add workflow. One : formula, passed add_formula(). recipe, passed add_recipe(). workflow_variables() object, passed add_variables(). spec optional parsnip model specification add workflow. Passed add_model(). postprocessor optional postprocessor add workflow. Currently frosting allowed using, add_frosting().","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_workflow.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create an epi_workflow — epi_workflow","text":"new epi_workflow object.","code":""},{"path":[]},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_workflow.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create an epi_workflow — epi_workflow","text":"","code":"jhu <- case_death_rate_subset r <- epi_recipe(jhu) %>% step_epi_lag(death_rate, lag = c(0, 7, 14)) %>% step_epi_ahead(death_rate, ahead = 7) %>% step_epi_lag(case_rate, lag = c(0, 7, 14)) %>% step_epi_naomit() wf <- epi_workflow(r, parsnip::linear_reg()) wf #> ══ Epi Workflow ════════════════════════════════════════════════════════════════ #> Preprocessor: Recipe #> Model: linear_reg() #> Postprocessor: None #> #> ── Preprocessor ──────────────────────────────────────────────────────────────── #> 5 Recipe Steps #> #> • step_epi_lag() #> • step_epi_ahead() #> • step_epi_lag() #> • step_naomit() #> • step_naomit() #> #> ── Model ─────────────────────────────────────────────────────────────────────── #> Linear Regression Model Specification (regression) #> #> Computational engine: lm #>"},{"path":"https://cmu-delphi.github.io/epipredict/reference/extract_argument.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract an argument made to a frosting layer or recipe step — extract_argument","title":"Extract an argument made to a frosting layer or recipe step — extract_argument","text":"Extract argument made frosting layer recipe step","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/extract_argument.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract an argument made to a frosting layer or recipe step — extract_argument","text":"","code":"extract_argument(x, name, arg, ...)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/extract_argument.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Extract an argument made to a frosting layer or recipe step — extract_argument","text":"x epi_workflow, epi_recipe, frosting, step, layer object name name layer arg name argument ... used","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/extract_argument.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Extract an argument made to a frosting layer or recipe step — extract_argument","text":"object originally passed argument layer step","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/extract_argument.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Extract an argument made to a frosting layer or recipe step — extract_argument","text":"","code":"f <- frosting() %>% layer_predict() %>% layer_residual_quantiles(probs = c(0.0275, 0.975), symmetrize = FALSE) %>% layer_naomit(.pred) extract_argument(f, \"layer_residual_quantiles\", \"symmetrize\") #> [1] FALSE"},{"path":"https://cmu-delphi.github.io/epipredict/reference/extract_frosting.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract the frosting object from a workflow — extract_frosting","title":"Extract the frosting object from a workflow — extract_frosting","text":"Extract frosting object workflow","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/extract_frosting.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract the frosting object from a workflow — extract_frosting","text":"","code":"extract_frosting(x, ...)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/extract_frosting.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Extract the frosting object from a workflow — extract_frosting","text":"x epi_workflow object ... used","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/extract_frosting.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Extract the frosting object from a workflow — extract_frosting","text":"frosting object","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/extrapolate_quantiles.html","id":null,"dir":"Reference","previous_headings":"","what":"Summarize a distribution with a set of quantiles — extrapolate_quantiles","title":"Summarize a distribution with a set of quantiles — extrapolate_quantiles","text":"Summarize distribution set quantiles","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/extrapolate_quantiles.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Summarize a distribution with a set of quantiles — extrapolate_quantiles","text":"","code":"extrapolate_quantiles(x, p, ...)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/extrapolate_quantiles.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Summarize a distribution with a set of quantiles — extrapolate_quantiles","text":"x distribution vector p vector probabilities calculate quantiles ... additional arguments passed quantile method","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/extrapolate_quantiles.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Summarize a distribution with a set of quantiles — extrapolate_quantiles","text":"distribution vector containing dist_quantiles","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/extrapolate_quantiles.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Summarize a distribution with a set of quantiles — extrapolate_quantiles","text":"","code":"library(distributional) dstn <- dist_normal(c(10, 2), c(5, 10)) extrapolate_quantiles(dstn, p = c(.25, 0.5, .75)) #> #> [1] [0.25, 0.75] [0.25, 0.75] dstn <- dist_quantiles(list(1:4, 8:11), list(c(.2,.4,.6,.8))) # because this distribution is already quantiles, any extra quantiles are # appended extrapolate_quantiles(dstn, p = c(.25, 0.5, .75)) #> #> [1] [0.2, 0.8] [0.2, 0.8] dstn <- c(dist_normal(c(10, 2), c(5, 10)), dist_quantiles(list(1:4, 8:11), list(c(.2,.4,.6,.8)))) extrapolate_quantiles(dstn, p = c(.25, 0.5, .75)) #> #> [1] [0.25, 0.75] [0.25, 0.75] [0.2, 0.8] #> [4] [0.2, 0.8]"},{"path":"https://cmu-delphi.github.io/epipredict/reference/fit-epi_workflow.html","id":null,"dir":"Reference","previous_headings":"","what":"Fit an epi_workflow object — fit-epi_workflow","title":"Fit an epi_workflow object — fit-epi_workflow","text":"fit() method epi_workflow object estimates parameters given model set data. Fitting epi_workflow involves two main steps, preprocessing data fitting underlying parsnip model.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/fit-epi_workflow.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Fit an epi_workflow object — fit-epi_workflow","text":"","code":"# S3 method for epi_workflow fit(object, data, ..., control = workflows::control_workflow())"},{"path":"https://cmu-delphi.github.io/epipredict/reference/fit-epi_workflow.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Fit an epi_workflow object — fit-epi_workflow","text":"object epi_workflow object data epi_df predictors outcomes use fitting epi_workflow ... used control workflows::control_workflow() object","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/fit-epi_workflow.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Fit an epi_workflow object — fit-epi_workflow","text":"epi_workflow object, updated fit parsnip model object$fit$fit slot.","code":""},{"path":[]},{"path":"https://cmu-delphi.github.io/epipredict/reference/fit-epi_workflow.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Fit an epi_workflow object — fit-epi_workflow","text":"","code":"jhu <- case_death_rate_subset %>% filter(time_value > \"2021-11-01\", geo_value %in% c(\"ak\", \"ca\", \"ny\")) r <- epi_recipe(jhu) %>% step_epi_lag(death_rate, lag = c(0, 7, 14)) %>% step_epi_ahead(death_rate, ahead = 7) wf <- epi_workflow(r, parsnip::linear_reg()) %>% fit(jhu) wf #> ══ Epi Workflow [trained] ══════════════════════════════════════════════════════ #> Preprocessor: Recipe #> Model: linear_reg() #> Postprocessor: None #> #> ── Preprocessor ──────────────────────────────────────────────────────────────── #> 2 Recipe Steps #> #> • step_epi_lag() #> • step_epi_ahead() #> #> ── Model ─────────────────────────────────────────────────────────────────────── #> #> Call: #> stats::lm(formula = ..y ~ ., data = data) #> #> Coefficients: #> (Intercept) lag_0_death_rate lag_7_death_rate lag_14_death_rate #> 0.32848 -0.01957 -0.02176 -0.05895 #>"},{"path":"https://cmu-delphi.github.io/epipredict/reference/flatline.html","id":null,"dir":"Reference","previous_headings":"","what":"(Internal) implementation of the flatline forecaster — flatline","title":"(Internal) implementation of the flatline forecaster — flatline","text":"internal function used create parsnip::linear_reg() model. somewhat odd behaviour (see ).","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/flatline.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"(Internal) implementation of the flatline forecaster — flatline","text":"","code":"flatline(formula, data)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/flatline.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"(Internal) implementation of the flatline forecaster — flatline","text":"formula lhs single variable. standard usage, actually observed time series shifted forward forecast horizon. right hand side must contain keys (locations) panel data separated plus. observed time series must come last. example Note function shifting, done outside. data data frame containing least variables used formula. must also contain column time_value giving observed time points.","code":"form <- as.formula(lead7_y ~ state + age + y)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/flatline.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"(Internal) implementation of the flatline forecaster — flatline","text":"S3 object class flatline two components: residuals - tibble keys .resid column contains forecast errors. .pred - tibble keys .pred column containing predictions future data (last observed outcome combination keys.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/flatline.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"(Internal) implementation of the flatline forecaster — flatline","text":"","code":"tib <- data.frame(y = runif(100), expand.grid(k = letters[1:4], j = letters[5:9], time_value = 1:5)) %>% dplyr::group_by(k, j) %>% dplyr::mutate(y2 = dplyr::lead(y, 2)) # predict 2 steps ahead flat <- flatline(y2 ~ j + k + y, tib) # predictions for 20 locations sum(!is.na(flat$residuals$.resid)) # 100 residuals, but 40 are NA #> [1] 60"},{"path":"https://cmu-delphi.github.io/epipredict/reference/flatline_args_list.html","id":null,"dir":"Reference","previous_headings":"","what":"Flatline forecaster argument constructor — flatline_args_list","title":"Flatline forecaster argument constructor — flatline_args_list","text":"Constructs list arguments flatline_forecaster().","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/flatline_args_list.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Flatline forecaster argument constructor — flatline_args_list","text":"","code":"flatline_args_list( ahead = 7L, n_training = Inf, forecast_date = NULL, target_date = NULL, levels = c(0.05, 0.95), symmetrize = TRUE, nonneg = TRUE, quantile_by_key = character(0L), nafill_buffer = Inf )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/flatline_args_list.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Flatline forecaster argument constructor — flatline_args_list","text":"ahead Integer. Number time steps ahead (days) forecast date forecasts produced. n_training Integer. upper limit number rows per key used training (time unit epi_df). forecast_date Date. date forecast created. default NULL attempt determine automatically. target_date Date. date forecast intended. default NULL attempt determine automatically. levels Vector NULL. vector probabilities produce prediction intervals. created computing quantiles training residuals. NULL value result point forecasts . symmetrize Logical. default TRUE calculates symmetric prediction intervals. argument applies residual quantiles used. applicable trainer = quantile_reg(), example. nonneg Logical. default TRUE enforces nonnegative predictions hard-thresholding 0. quantile_by_key Character vector. Groups residuals listed keys calculating residual quantiles. See by_key argument layer_residual_quantiles() information. default, character(0) performs grouping. argument applies residual quantiles used. applicable trainer = quantile_reg(), example. nafill_buffer predict time, recent values training data used create forecast. However, can NA due , e.g., data latency issues. default, missing values get filled less recent data. Setting value NULL result 1 extra recent row (beyond required lag creation) used. Note require least min(lags) rows recent data per geo_value create prediction. reason, setting nafill_buffer < min(lags) treated additional allowed recent data rather total amount recent data examine.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/flatline_args_list.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Flatline forecaster argument constructor — flatline_args_list","text":"list containing updated parameter choices class flatline_alist.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/flatline_args_list.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Flatline forecaster argument constructor — flatline_args_list","text":"","code":"flatline_args_list() #> List of 9 #> $ ahead : int 7 #> $ n_training : num Inf #> $ forecast_date : NULL #> $ target_date : NULL #> $ levels : num [1:2] 0.05 0.95 #> $ symmetrize : logi TRUE #> $ nonneg : logi TRUE #> $ quantile_by_key: chr(0) #> $ nafill_buffer : num Inf #> - attr(*, \"class\")= chr [1:2] \"flat_fcast\" \"alist\" flatline_args_list(symmetrize = FALSE) #> List of 9 #> $ ahead : int 7 #> $ n_training : num Inf #> $ forecast_date : NULL #> $ target_date : NULL #> $ levels : num [1:2] 0.05 0.95 #> $ symmetrize : logi FALSE #> $ nonneg : logi TRUE #> $ quantile_by_key: chr(0) #> $ nafill_buffer : num Inf #> - attr(*, \"class\")= chr [1:2] \"flat_fcast\" \"alist\" flatline_args_list(levels = c(.1, .3, .7, .9), n_training = 120) #> List of 9 #> $ ahead : int 7 #> $ n_training : num 120 #> $ forecast_date : NULL #> $ target_date : NULL #> $ levels : num [1:4] 0.1 0.3 0.7 0.9 #> $ symmetrize : logi TRUE #> $ nonneg : logi TRUE #> $ quantile_by_key: chr(0) #> $ nafill_buffer : num Inf #> - attr(*, \"class\")= chr [1:2] \"flat_fcast\" \"alist\""},{"path":"https://cmu-delphi.github.io/epipredict/reference/flatline_forecaster.html","id":null,"dir":"Reference","previous_headings":"","what":"Predict the future with today's value — flatline_forecaster","title":"Predict the future with today's value — flatline_forecaster","text":"simple forecasting model epiprocess::epi_df data. uses recent observation forcast future date, produces intervals based quantiles residuals \"flatline\" forecast available training data.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/flatline_forecaster.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Predict the future with today's value — flatline_forecaster","text":"","code":"flatline_forecaster(epi_data, outcome, args_list = flatline_args_list())"},{"path":"https://cmu-delphi.github.io/epipredict/reference/flatline_forecaster.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Predict the future with today's value — flatline_forecaster","text":"epi_data epiprocess::epi_df outcome scalar character column name wish predict. args_list list dditional arguments created flatline_args_list() constructor function.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/flatline_forecaster.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Predict the future with today's value — flatline_forecaster","text":"data frame point (optionally interval) forecasts single ahead (unique horizon) unique combination key_vars.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/flatline_forecaster.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Predict the future with today's value — flatline_forecaster","text":"default, predictive intervals computed separately combination key values (geo_value + additional keys) epi_data argument. forecaster similar used COVID19ForecastHub","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/flatline_forecaster.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Predict the future with today's value — flatline_forecaster","text":"","code":"jhu <- case_death_rate_subset %>% dplyr::filter(time_value >= as.Date(\"2021-12-01\")) out <- flatline_forecaster(jhu, \"death_rate\")"},{"path":"https://cmu-delphi.github.io/epipredict/reference/frosting.html","id":null,"dir":"Reference","previous_headings":"","what":"Create frosting for postprocessing predictions — frosting","title":"Create frosting for postprocessing predictions — frosting","text":"generates postprocessing container (much like recipes::recipe()) hold steps postprocessing predictions.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/frosting.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create frosting for postprocessing predictions — frosting","text":"","code":"frosting(layers = NULL, requirements = NULL)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/frosting.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create frosting for postprocessing predictions — frosting","text":"layers Must NULL. requirements Must NULL.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/frosting.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create frosting for postprocessing predictions — frosting","text":"frosting object.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/frosting.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Create frosting for postprocessing predictions — frosting","text":"arguments currently placeholders must NULL","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/frosting.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create frosting for postprocessing predictions — frosting","text":"","code":"# Toy example to show that frosting can be created and added for postprocessing f <- frosting() wf <- epi_workflow() %>% add_frosting(f) # A more realistic example jhu <- case_death_rate_subset %>% dplyr::filter(time_value > \"2021-11-01\", geo_value %in% c(\"ak\", \"ca\", \"ny\")) r <- epi_recipe(jhu) %>% step_epi_lag(death_rate, lag = c(0, 7, 14)) %>% step_epi_ahead(death_rate, ahead = 7) %>% step_epi_naomit() wf <- epi_workflow(r, parsnip::linear_reg()) %>% fit(jhu) latest <- get_test_data(recipe = r, x = jhu) f <- frosting() %>% layer_predict() %>% layer_naomit(.pred) wf1 <- wf %>% add_frosting(f) p <- predict(wf1, latest) p #> An `epi_df` object, 3 x 3 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 3 × 3 #> geo_value time_value .pred #> * #> 1 ak 2021-12-31 0.245 #> 2 ca 2021-12-31 0.313 #> 3 ny 2021-12-31 0.295"},{"path":"https://cmu-delphi.github.io/epipredict/reference/get_test_data.html","id":null,"dir":"Reference","previous_headings":"","what":"Get test data for prediction based on longest lag period — get_test_data","title":"Get test data for prediction based on longest lag period — get_test_data","text":"Based longest lag period recipe, get_test_data() creates epi_df columns geo_value, time_value variables original dataset, used create features necessary produce forecasts.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/get_test_data.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Get test data for prediction based on longest lag period — get_test_data","text":"","code":"get_test_data( recipe, x, fill_locf = FALSE, n_recent = NULL, forecast_date = max(x$time_value) )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/get_test_data.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Get test data for prediction based on longest lag period — get_test_data","text":"recipe recipe object. x epi_df. typical usage pass data used fitting recipe. fill_locf Logical. use locf fill missing data? n_recent Integer NULL. filling missing data locf = TRUE, far back willing tolerate missing data? Larger values allow filling. default NULL determine recipe. example, suppose n_recent = 3, 3 recent observations geo_value NA’s, won’t able fill anything, error message thrown. (See details.) forecast_date default, set maximum time_value x. data latency recent NA's filled, may last available time_value.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/get_test_data.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Get test data for prediction based on longest lag period — get_test_data","text":"object type x columns geo_value, time_value, additional keys, well variables original dataset.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/get_test_data.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Get test data for prediction based on longest lag period — get_test_data","text":"minimum required (recent) data produce forecast equal maximum lag requested (predictor) plus longest horizon used growth rate calculations requested recipe. calculated internally. also optionally fills missing values using last-observation-carried-forward (LOCF) method. possible (say NA's location), produce error suggesting alternative options handle missing values advanced techniques.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/get_test_data.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Get test data for prediction based on longest lag period — get_test_data","text":"","code":"# create recipe rec <- epi_recipe(case_death_rate_subset) %>% step_epi_ahead(death_rate, ahead = 7) %>% step_epi_lag(death_rate, lag = c(0, 7, 14)) %>% step_epi_lag(case_rate, lag = c(0, 7, 14)) get_test_data(recipe = rec, x = case_death_rate_subset) #> An `epi_df` object, 840 x 4 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 840 × 4 #> geo_value time_value case_rate death_rate #> * #> 1 ak 2021-12-17 23.1 1.19 #> 2 al 2021-12-17 15.6 0.290 #> 3 ar 2021-12-17 23.4 0.467 #> 4 as 2021-12-17 0 0 #> 5 az 2021-12-17 41.2 1.04 #> 6 ca 2021-12-17 16.9 0.158 #> 7 co 2021-12-17 30.5 0.578 #> 8 ct 2021-12-17 64.8 0.120 #> 9 dc 2021-12-17 50.4 0.140 #> 10 de 2021-12-17 67.9 0.333 #> # ℹ 830 more rows"},{"path":"https://cmu-delphi.github.io/epipredict/reference/grab_names.html","id":null,"dir":"Reference","previous_headings":"","what":"Get the names from a data frame via tidy select — grab_names","title":"Get the names from a data frame via tidy select — grab_names","text":"Given data.frame, use syntax choose variables. Return names variables","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/grab_names.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Get the names from a data frame via tidy select — grab_names","text":"","code":"grab_names(dat, ...)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/grab_names.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Get the names from a data frame via tidy select — grab_names","text":"dat data.frame ... One unquoted expressions separated commas. Variable names can used positions data frame, expressions like x:y can used select range variables.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/grab_names.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Get the names from a data frame via tidy select — grab_names","text":"character vector","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/grab_names.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Get the names from a data frame via tidy select — grab_names","text":"internal function, checks performed.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/grab_names.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Get the names from a data frame via tidy select — grab_names","text":"","code":"df <- data.frame(a = 1, b = 2, cc = rep(NA, 3)) grab_names(df, dplyr::starts_with(\"c\")) #> [1] \"cc\""},{"path":"https://cmu-delphi.github.io/epipredict/reference/is_epi_recipe.html","id":null,"dir":"Reference","previous_headings":"","what":"Test for epi_recipe — is_epi_recipe","title":"Test for epi_recipe — is_epi_recipe","text":"Test epi_recipe","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/is_epi_recipe.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Test for epi_recipe — is_epi_recipe","text":"","code":"is_epi_recipe(x)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/is_epi_recipe.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Test for epi_recipe — is_epi_recipe","text":"x object.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/is_epi_recipe.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Test for epi_recipe — is_epi_recipe","text":"TRUE object inherits epi_recipe.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/is_epi_workflow.html","id":null,"dir":"Reference","previous_headings":"","what":"Test for an epi_workflow — is_epi_workflow","title":"Test for an epi_workflow — is_epi_workflow","text":"Test epi_workflow","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/is_epi_workflow.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Test for an epi_workflow — is_epi_workflow","text":"","code":"is_epi_workflow(x)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/is_epi_workflow.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Test for an epi_workflow — is_epi_workflow","text":"x object.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/is_epi_workflow.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Test for an epi_workflow — is_epi_workflow","text":"TRUE object inherits epi_workflow.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer-processors.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract, validate, or detect layers of frosting — extract_layers","title":"Extract, validate, or detect layers of frosting — extract_layers","text":"functions mainly internal. can access validate different layers frosting.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer-processors.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract, validate, or detect layers of frosting — extract_layers","text":"","code":"extract_layers(x, ...) # S3 method for frosting extract_layers(x, ...) # S3 method for workflow extract_layers(x, ...) is_layer(x) validate_layer(x, ..., arg = \"`x`\", call = caller_env()) detect_layer(x, name, ...) # S3 method for frosting detect_layer(x, name, ...) # S3 method for workflow detect_layer(x, name, ...)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer-processors.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Extract, validate, or detect layers of frosting — extract_layers","text":"x epi_workflow, frosting, layer object ... additional arguments possible future methods arg name input (error reporting) call environment (error reporting) name layer name detect","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer-processors.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Extract, validate, or detect layers of frosting — extract_layers","text":"logical validators/detectors list layers extractors","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer-processors.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Extract, validate, or detect layers of frosting — extract_layers","text":"","code":"f <- frosting() %>% layer_predict() wf <- epi_workflow(postprocessor = f) is_layer(layer(\"what_the_what\")) #> [1] TRUE detect_layer(f, \"layer_predict\") #> [1] TRUE detect_layer(wf, \"layer_predict\") #> [1] TRUE extract_layers(f) #> [[1]] #> • Creating predictions: \"\" #> extract_layers(wf) #> [[1]] #> • Creating predictions: \"\" #>"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer.html","id":null,"dir":"Reference","previous_headings":"","what":"layer sets the class of the layer — layer","title":"layer sets the class of the layer — layer","text":"layer sets class layer","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"layer sets the class of the layer — layer","text":"","code":"layer(subclass, ..., .prefix = \"layer_\")"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"layer sets the class of the layer — layer","text":"subclass character string resulting class. example, subclass = \"blah\" layer object returned class layer_blah. ... arguments operator returned. .prefix Prefix subclass created.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"layer sets the class of the layer — layer","text":"updated layer new class","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_add_forecast_date.html","id":null,"dir":"Reference","previous_headings":"","what":"Postprocessing step to add the forecast date — layer_add_forecast_date","title":"Postprocessing step to add the forecast date — layer_add_forecast_date","text":"Postprocessing step add forecast date","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_add_forecast_date.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Postprocessing step to add the forecast date — layer_add_forecast_date","text":"","code":"layer_add_forecast_date( frosting, forecast_date = NULL, id = rand_id(\"add_forecast_date\") )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_add_forecast_date.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Postprocessing step to add the forecast date — layer_add_forecast_date","text":"frosting frosting postprocessor forecast_date forecast date add column epi_df. cases, specified form \"yyyy-mm-dd\". Note forecast date left unspecified, set maximum time value data used pre-processing, fitting model, postprocessing. id random id string","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_add_forecast_date.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Postprocessing step to add the forecast date — layer_add_forecast_date","text":"updated frosting postprocessor","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_add_forecast_date.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Postprocessing step to add the forecast date — layer_add_forecast_date","text":"use function, either specify forecast date leave forecast date unspecifed . latter case, forecast date set maximum time value data used pre-processing, fitting model, postprocessing. case, forecast date less maximum as_of value (data used pre-processing, model fitting, postprocessing), appropriate warning thrown.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_add_forecast_date.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Postprocessing step to add the forecast date — layer_add_forecast_date","text":"","code":"jhu <- case_death_rate_subset %>% dplyr::filter(time_value > \"2021-11-01\", geo_value %in% c(\"ak\", \"ca\", \"ny\")) r <- epi_recipe(jhu) %>% step_epi_lag(death_rate, lag = c(0, 7, 14)) %>% step_epi_ahead(death_rate, ahead = 7) %>% step_epi_naomit() wf <- epi_workflow(r, parsnip::linear_reg()) %>% fit(jhu) latest <- jhu %>% dplyr::filter(time_value >= max(time_value) - 14) # Don't specify `forecast_date` (by default, this should be last date in latest) f <- frosting() %>% layer_predict() %>% layer_naomit(.pred) wf0 <- wf %>% add_frosting(f) p0 <- predict(wf0, latest) p0 #> An `epi_df` object, 3 x 3 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 3 × 3 #> geo_value time_value .pred #> * #> 1 ak 2021-12-31 0.245 #> 2 ca 2021-12-31 0.313 #> 3 ny 2021-12-31 0.295 # Specify a `forecast_date` that is greater than or equal to `as_of` date f <- frosting() %>% layer_predict() %>% layer_add_forecast_date(forecast_date = \"2022-05-31\") %>% layer_naomit(.pred) wf1 <- wf %>% add_frosting(f) p1 <- predict(wf1, latest) p1 #> An `epi_df` object, 3 x 4 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 3 × 4 #> geo_value time_value .pred forecast_date #> * #> 1 ak 2021-12-31 0.245 2022-05-31 #> 2 ca 2021-12-31 0.313 2022-05-31 #> 3 ny 2021-12-31 0.295 2022-05-31 # Specify a `forecast_date` that is less than `as_of` date f2 <- frosting() %>% layer_predict() %>% layer_add_forecast_date(forecast_date = \"2021-12-31\") %>% layer_naomit(.pred) wf2 <- wf %>% add_frosting(f2) p2 <- predict(wf2, latest) #> Warning: The forecast_date is less than the most recent update date of the data: forecast_date = 2021-12-31 while data is from 2022-05-31. p2 #> An `epi_df` object, 3 x 4 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 3 × 4 #> geo_value time_value .pred forecast_date #> * #> 1 ak 2021-12-31 0.245 2021-12-31 #> 2 ca 2021-12-31 0.313 2021-12-31 #> 3 ny 2021-12-31 0.295 2021-12-31 # Do not specify a forecast_date f3 <- frosting() %>% layer_predict() %>% layer_add_forecast_date() %>% layer_naomit(.pred) wf3 <- wf %>% add_frosting(f3) p3 <- predict(wf3, latest) #> Warning: The forecast_date is less than the most recent update date of the data: forecast_date = 2021-12-31 while data is from 2022-05-31. p3 #> An `epi_df` object, 3 x 4 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 3 × 4 #> geo_value time_value .pred forecast_date #> * #> 1 ak 2021-12-31 0.245 2021-12-31 #> 2 ca 2021-12-31 0.313 2021-12-31 #> 3 ny 2021-12-31 0.295 2021-12-31"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_add_target_date.html","id":null,"dir":"Reference","previous_headings":"","what":"Postprocessing step to add the target date — layer_add_target_date","title":"Postprocessing step to add the target date — layer_add_target_date","text":"Postprocessing step add target date","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_add_target_date.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Postprocessing step to add the target date — layer_add_target_date","text":"","code":"layer_add_target_date( frosting, target_date = NULL, id = rand_id(\"add_target_date\") )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_add_target_date.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Postprocessing step to add the target date — layer_add_target_date","text":"frosting frosting postprocessor target_date target date add column epi_df. forecast date specified layer, forecast date plus ahead (step_epi_ahead epi_recipe). Otherwise, maximum time_value (data used pre-processing, fitting model, postprocessing) plus ahead, ahead specified preprocessing. user may override specifying target date (form \"yyyy-mm-dd\"). id random id string","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_add_target_date.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Postprocessing step to add the target date — layer_add_target_date","text":"updated frosting postprocessor","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_add_target_date.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Postprocessing step to add the target date — layer_add_target_date","text":"default, function assumes value ahead specified preprocessing step (likely step_epi_ahead). , ahead added maximum time_value test data get target date.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_add_target_date.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Postprocessing step to add the target date — layer_add_target_date","text":"","code":"jhu <- case_death_rate_subset %>% dplyr::filter(time_value > \"2021-11-01\", geo_value %in% c(\"ak\", \"ca\", \"ny\")) r <- epi_recipe(jhu) %>% step_epi_lag(death_rate, lag = c(0, 7, 14)) %>% step_epi_ahead(death_rate, ahead = 7) %>% step_epi_naomit() wf <- epi_workflow(r, parsnip::linear_reg()) %>% fit(jhu) latest <- get_test_data(r, jhu) # Use ahead + forecast date f <- frosting() %>% layer_predict() %>% layer_add_forecast_date(forecast_date = \"2022-05-31\") %>% layer_add_target_date() %>% layer_naomit(.pred) wf1 <- wf %>% add_frosting(f) p <- predict(wf1, latest) p #> An `epi_df` object, 3 x 5 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 3 × 5 #> geo_value time_value .pred forecast_date target_date #> * #> 1 ak 2021-12-31 0.245 2022-05-31 2022-06-07 #> 2 ca 2021-12-31 0.313 2022-05-31 2022-06-07 #> 3 ny 2021-12-31 0.295 2022-05-31 2022-06-07 # Use ahead + max time value from pre, fit, post # which is the same if include `layer_add_forecast_date()` f2 <- frosting() %>% layer_predict() %>% layer_add_target_date() %>% layer_naomit(.pred) wf2 <- wf %>% add_frosting(f2) p2 <- predict(wf2, latest) p2 #> An `epi_df` object, 3 x 4 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 3 × 4 #> geo_value time_value .pred target_date #> * #> 1 ak 2021-12-31 0.245 2022-01-07 #> 2 ca 2021-12-31 0.313 2022-01-07 #> 3 ny 2021-12-31 0.295 2022-01-07 # Specify own target date f3 <- frosting() %>% layer_predict() %>% layer_add_target_date(target_date = \"2022-01-08\") %>% layer_naomit(.pred) wf3 <- wf %>% add_frosting(f3) p3 <- predict(wf3, latest) p3 #> An `epi_df` object, 3 x 4 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 3 × 4 #> geo_value time_value .pred target_date #> * #> 1 ak 2021-12-31 0.245 2022-01-08 #> 2 ca 2021-12-31 0.313 2022-01-08 #> 3 ny 2021-12-31 0.295 2022-01-08"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_naomit.html","id":null,"dir":"Reference","previous_headings":"","what":"Omit NAs from predictions or other columns — layer_naomit","title":"Omit NAs from predictions or other columns — layer_naomit","text":"Omit NAs predictions columns","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_naomit.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Omit NAs from predictions or other columns — layer_naomit","text":"","code":"layer_naomit(frosting, ..., id = rand_id(\"naomit\"))"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_naomit.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Omit NAs from predictions or other columns — layer_naomit","text":"frosting frosting postprocessor ... One unquoted expressions separated commas. Variable names can used positions data frame, expressions like x:y can used select range variables. Typical usage .pred remove rows NA predictions. id random id string","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_naomit.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Omit NAs from predictions or other columns — layer_naomit","text":"updated frosting postprocessor","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_naomit.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Omit NAs from predictions or other columns — layer_naomit","text":"","code":"jhu <- case_death_rate_subset %>% dplyr::filter(time_value > \"2021-11-01\", geo_value %in% c(\"ak\", \"ca\", \"ny\")) r <- epi_recipe(jhu) %>% step_epi_lag(death_rate, lag = c(0, 7, 14)) %>% step_epi_ahead(death_rate, ahead = 7) wf <- epi_workflow(r, parsnip::linear_reg()) %>% fit(jhu) latest <- get_test_data(recipe = r, x = jhu) f <- frosting() %>% layer_predict() %>% layer_naomit(.pred) wf1 <- wf %>% add_frosting(f) p <- predict(wf1, latest) p #> An `epi_df` object, 3 x 3 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 3 × 3 #> geo_value time_value .pred #> * #> 1 ak 2021-12-31 0.245 #> 2 ca 2021-12-31 0.313 #> 3 ny 2021-12-31 0.295"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_point_from_distn.html","id":null,"dir":"Reference","previous_headings":"","what":"Converts distributional forecasts to point forecasts — layer_point_from_distn","title":"Converts distributional forecasts to point forecasts — layer_point_from_distn","text":"function adds postprocessing layer extract point forecast distributional forecast. NOTE: default arguments, remove information, one usually call layer_quantile_distn() set name argument something specific.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_point_from_distn.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Converts distributional forecasts to point forecasts — layer_point_from_distn","text":"","code":"layer_point_from_distn( frosting, ..., type = c(\"median\", \"mean\"), name = NULL, id = rand_id(\"point_from_distn\") )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_point_from_distn.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Converts distributional forecasts to point forecasts — layer_point_from_distn","text":"frosting frosting postprocessor ... Unused, include consistency layers. type character. Either mean median. name character. name output column. default NULL overwrite .pred column, removing distribution information. id random id string","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_point_from_distn.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Converts distributional forecasts to point forecasts — layer_point_from_distn","text":"updated frosting postprocessor.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_point_from_distn.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Converts distributional forecasts to point forecasts — layer_point_from_distn","text":"","code":"jhu <- case_death_rate_subset %>% dplyr::filter(time_value > \"2021-11-01\", geo_value %in% c(\"ak\", \"ca\", \"ny\")) r <- epi_recipe(jhu) %>% step_epi_lag(death_rate, lag = c(0, 7, 14)) %>% step_epi_ahead(death_rate, ahead = 7) %>% step_epi_naomit() wf <- epi_workflow(r, quantile_reg(tau = c(.25, .5, .75))) %>% fit(jhu) latest <- get_test_data(recipe = r, x = jhu) f1 <- frosting() %>% layer_predict() %>% layer_quantile_distn() %>% # puts the other quantiles in a different col layer_point_from_distn() %>% # mutate `.pred` to contain only a point prediction layer_naomit(.pred) wf1 <- wf %>% add_frosting(f1) p1 <- predict(wf1, latest) p1 #> An `epi_df` object, 3 x 4 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 3 × 4 #> geo_value time_value .pred .pred_distn #> * #> 1 ak 2021-12-31 0.167 [0.25, 0.75] #> 2 ca 2021-12-31 0.177 [0.25, 0.75] #> 3 ny 2021-12-31 0.272 [0.25, 0.75] f2 <- frosting() %>% layer_predict() %>% layer_point_from_distn() %>% # mutate `.pred` to contain only a point prediction layer_naomit(.pred) wf2 <- wf %>% add_frosting(f2) p2 <- predict(wf2, latest) p2 #> An `epi_df` object, 3 x 3 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 3 × 3 #> geo_value time_value .pred #> * #> 1 ak 2021-12-31 0.167 #> 2 ca 2021-12-31 0.177 #> 3 ny 2021-12-31 0.272"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_population_scaling.html","id":null,"dir":"Reference","previous_headings":"","what":"Convert per-capita predictions to raw scale — layer_population_scaling","title":"Convert per-capita predictions to raw scale — layer_population_scaling","text":"layer_population_scaling creates specification frosting layer \"undo\" per-capita scaling. Typical usage load dataset contains state-level population, use convert predictions made rate-scale model raw scale multiplying population. Although, worth noting nothing special \"population\". function can used scale variable. Population standard use case epidemiology forecasting scenario. value passed multiply selected variables rate_rescaling argument common divisor selected variables.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_population_scaling.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Convert per-capita predictions to raw scale — layer_population_scaling","text":"","code":"layer_population_scaling( frosting, ..., df, by = NULL, df_pop_col, rate_rescaling = 1, create_new = TRUE, suffix = \"_scaled\", id = rand_id(\"population_scaling\") )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_population_scaling.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Convert per-capita predictions to raw scale — layer_population_scaling","text":"frosting frosting postprocessor. layer added sequence operations frosting. ... One selector functions scale variables step. See recipes::selections() details. df data frame contains population data used inverting existing scaling. (possibly named) character vector variables join . NULL, default, function perform natural join, using variables common across epi_df produced predict() call user-provided dataset. columns epi_df df name (included ), .df added one user-provided data disambiguate. join different variables epi_df df, use named vector. example, = c(\"geo_value\" = \"states\") match epi_df$geo_value df$states. join multiple variables, use vector length > 1. example, = c(\"geo_value\" = \"states\", \"county\" = \"county\") match epi_df$geo_value df$states epi_df$county df$county. See dplyr::left_join() details. df_pop_col name column data frame df contains population data used scaling. rate_rescaling Sometimes rates \"per 100K\" \"per 1M\" rather \"per person\". Adjustments can made . example, original rate \"per 100K\", set rate_rescaling = 1e5 get counts back. create_new TRUE create new column keep original column epi_df. suffix character. suffix added column name create_new = TRUE. Default \"_scaled\". id random id string","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_population_scaling.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Convert per-capita predictions to raw scale — layer_population_scaling","text":"updated frosting postprocessor","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_population_scaling.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Convert per-capita predictions to raw scale — layer_population_scaling","text":"","code":"jhu <- epiprocess::jhu_csse_daily_subset %>% dplyr::filter(time_value > \"2021-11-01\", geo_value %in% c(\"ca\", \"ny\")) %>% dplyr::select(geo_value, time_value, cases) pop_data = data.frame(states = c(\"ca\", \"ny\"), value = c(20000, 30000)) r <- epi_recipe(jhu) %>% step_population_scaling(df = pop_data, df_pop_col = \"value\", by = c(\"geo_value\" = \"states\"), cases, suffix = \"_scaled\") %>% step_epi_lag(cases_scaled, lag = c(0, 7, 14)) %>% step_epi_ahead(cases_scaled, ahead = 7, role = \"outcome\") %>% step_epi_naomit() f <- frosting() %>% layer_predict() %>% layer_threshold(.pred) %>% layer_naomit(.pred) %>% layer_population_scaling(.pred, df = pop_data, by = c(\"geo_value\" = \"states\"), df_pop_col = \"value\") wf <- epi_workflow(r, parsnip::linear_reg()) %>% fit(jhu) %>% add_frosting(f) latest <- get_test_data( recipe = r, x = epiprocess::jhu_csse_daily_subset %>% dplyr::filter(time_value > \"2021-11-01\", geo_value %in% c(\"ca\", \"ny\")) %>% dplyr::select(geo_value, time_value, cases)) predict(wf, latest) #> An `epi_df` object, 2 x 4 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-23 20:17:07.044666 #> #> # A tibble: 2 × 4 #> geo_value time_value .pred .pred_scaled #> * #> 1 ca 2021-12-31 4.25 84967. #> 2 ny 2021-12-31 5.93 177783."},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_predict.html","id":null,"dir":"Reference","previous_headings":"","what":"Prediction layer for postprocessing — layer_predict","title":"Prediction layer for postprocessing — layer_predict","text":"Implements prediction fitted epi_workflow. One may want different types prediction, potentially apply amount postprocessing. typically first layer frosting postprocessor.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_predict.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Prediction layer for postprocessing — layer_predict","text":"","code":"layer_predict( frosting, type = NULL, opts = list(), ..., id = rand_id(\"predict_default\") )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_predict.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Prediction layer for postprocessing — layer_predict","text":"frosting frosting object type single character value NULL. Possible values \"numeric\", \"class\", \"prob\", \"conf_int\", \"pred_int\", \"quantile\", \"time\", \"hazard\", \"survival\", \"raw\". NULL, predict() choose appropriate value based model's mode. opts list optional arguments underlying predict function used type = \"raw\". list include options model object new data predicted. ... Additional parsnip-related options, depending value type. Arguments underlying model's prediction function passed (use opts argument instead). Possible arguments : interval: type equal \"survival\" \"quantile\", interval estimates added, available? Options \"none\" \"confidence\". level: type equal \"conf_int\", \"pred_int\", \"survival\", parameter tail area intervals (e.g. confidence level confidence intervals). Default value 0.95. std_error: type equal \"conf_int\" \"pred_int\", add standard error fit prediction (scale linear predictors). Default value FALSE. quantile: type equal quantile, quantiles distribution. Default (1:9)/10. eval_time: type equal \"survival\" \"hazard\", time points survival probability hazard estimated. id string identifying layer","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_predict.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Prediction layer for postprocessing — layer_predict","text":"updated frosting object","code":""},{"path":[]},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_predict.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Prediction layer for postprocessing — layer_predict","text":"","code":"jhu <- case_death_rate_subset %>% filter(time_value > \"2021-11-01\", geo_value %in% c(\"ak\", \"ca\", \"ny\")) r <- epi_recipe(jhu) %>% step_epi_lag(death_rate, lag = c(0, 7, 14)) %>% step_epi_ahead(death_rate, ahead = 7) %>% step_epi_naomit() wf <- epi_workflow(r, parsnip::linear_reg()) %>% fit(jhu) latest <- jhu %>% filter(time_value >= max(time_value) - 14) # Predict layer alone f <- frosting() %>% layer_predict() wf1 <- wf %>% add_frosting(f) p1 <- predict(wf1, latest) p1 #> An `epi_df` object, 3 x 3 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 3 × 3 #> geo_value time_value .pred #> * #> 1 ak 2021-12-31 0.245 #> 2 ca 2021-12-31 0.313 #> 3 ny 2021-12-31 0.295 # Prediction with interval f <- frosting() %>% layer_predict(type = \"pred_int\") wf2 <- wf %>% add_frosting(f) p2 <- predict(wf2, latest) p2 #> An `epi_df` object, 3 x 4 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 3 × 4 #> geo_value time_value .pred_lower .pred_upper #> * #> 1 ak 2021-12-31 -0.366 0.856 #> 2 ca 2021-12-31 -0.284 0.910 #> 3 ny 2021-12-31 -0.301 0.891"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_predictive_distn.html","id":null,"dir":"Reference","previous_headings":"","what":"Returns predictive distributions — layer_predictive_distn","title":"Returns predictive distributions — layer_predictive_distn","text":"function calculates approximation parametric predictive distribution. Predictive distributions linear models require x* (X'X)^{-1} x* along degrees freedom. function approximates . reasonably accurate models fit using lm new point x* far bulk data.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_predictive_distn.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Returns predictive distributions — layer_predictive_distn","text":"","code":"layer_predictive_distn( frosting, ..., dist_type = c(\"gaussian\", \"student_t\"), truncate = c(-Inf, Inf), name = \".pred_distn\", id = rand_id(\"predictive_distn\") )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_predictive_distn.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Returns predictive distributions — layer_predictive_distn","text":"frosting frosting postprocessor ... Unused, include consistency layers. dist_type Gaussian Student's t predictive intervals truncate truncate distribution interval name character. name output column. id random id string","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_predictive_distn.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Returns predictive distributions — layer_predictive_distn","text":"updated frosting postprocessor additional columns residual quantiles added prediction","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_predictive_distn.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Returns predictive distributions — layer_predictive_distn","text":"","code":"jhu <- case_death_rate_subset %>% dplyr::filter(time_value > \"2021-11-01\", geo_value %in% c(\"ak\", \"ca\", \"ny\")) r <- epi_recipe(jhu) %>% step_epi_lag(death_rate, lag = c(0, 7, 14)) %>% step_epi_ahead(death_rate, ahead = 7) %>% step_epi_naomit() wf <- epi_workflow(r, parsnip::linear_reg()) %>% fit(jhu) latest <- get_test_data(recipe = r, x = jhu) f <- frosting() %>% layer_predict() %>% layer_predictive_distn() %>% layer_naomit(.pred) wf1 <- wf %>% add_frosting(f) p <- predict(wf1, latest) p #> An `epi_df` object, 3 x 4 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 3 × 4 #> geo_value time_value .pred .pred_distn #> * #> 1 ak 2021-12-31 0.245 N(0.24, 0.093) #> 2 ca 2021-12-31 0.313 N(0.31, 0.093) #> 3 ny 2021-12-31 0.295 N(0.29, 0.093)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_quantile_distn.html","id":null,"dir":"Reference","previous_headings":"","what":"Returns predictive quantiles — layer_quantile_distn","title":"Returns predictive quantiles — layer_quantile_distn","text":"function calculates quantiles prediction distributional. Currently, distributional engine quantile_reg(). engine used, layer grab estimated (extrapolated) quantiles requested levels.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_quantile_distn.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Returns predictive quantiles — layer_quantile_distn","text":"","code":"layer_quantile_distn( frosting, ..., levels = c(0.25, 0.75), truncate = c(-Inf, Inf), name = \".pred_distn\", id = rand_id(\"quantile_distn\") )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_quantile_distn.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Returns predictive quantiles — layer_quantile_distn","text":"frosting frosting postprocessor ... Unused, include consistency layers. levels vector probabilities (quantiles) extract truncate truncate distribution interval name character. name output column. id random id string","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_quantile_distn.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Returns predictive quantiles — layer_quantile_distn","text":"updated frosting postprocessor. additional column predictive quantiles added predictions.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_quantile_distn.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Returns predictive quantiles — layer_quantile_distn","text":"","code":"jhu <- case_death_rate_subset %>% dplyr::filter(time_value > \"2021-11-01\", geo_value %in% c(\"ak\", \"ca\", \"ny\")) r <- epi_recipe(jhu) %>% step_epi_lag(death_rate, lag = c(0, 7, 14)) %>% step_epi_ahead(death_rate, ahead = 7) %>% step_epi_naomit() wf <- epi_workflow(r, quantile_reg(tau = c(.25, .5, .75))) %>% fit(jhu) latest <- get_test_data(recipe = r, x = jhu) f <- frosting() %>% layer_predict() %>% layer_quantile_distn() %>% layer_naomit(.pred) wf1 <- wf %>% add_frosting(f) p <- predict(wf1, latest) p #> An `epi_df` object, 3 x 4 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 3 × 4 #> geo_value time_value .pred .pred_distn #> * #> 1 ak 2021-12-31 [0.25, 0.75] [0.25, 0.75] #> 2 ca 2021-12-31 [0.25, 0.75] [0.25, 0.75] #> 3 ny 2021-12-31 [0.25, 0.75] [0.25, 0.75]"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_residual_quantiles.html","id":null,"dir":"Reference","previous_headings":"","what":"Creates predictions based on residual quantiles — layer_residual_quantiles","title":"Creates predictions based on residual quantiles — layer_residual_quantiles","text":"Creates predictions based residual quantiles","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_residual_quantiles.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Creates predictions based on residual quantiles — layer_residual_quantiles","text":"","code":"layer_residual_quantiles( frosting, ..., probs = c(0.05, 0.95), symmetrize = TRUE, by_key = character(0L), name = \".pred_distn\", id = rand_id(\"residual_quantiles\") )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_residual_quantiles.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Creates predictions based on residual quantiles — layer_residual_quantiles","text":"frosting frosting postprocessor ... Unused, include consistency layers. probs numeric vector probabilities values (0,1) referring desired quantile. symmetrize logical. TRUE interval symmetric. by_key character vector keys group residuals calculating quantiles. default, c() performs grouping. name character. name output column. id random id string","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_residual_quantiles.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Creates predictions based on residual quantiles — layer_residual_quantiles","text":"updated frosting postprocessor additional columns residual quantiles added prediction","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_residual_quantiles.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Creates predictions based on residual quantiles — layer_residual_quantiles","text":"","code":"jhu <- case_death_rate_subset %>% dplyr::filter(time_value > \"2021-11-01\", geo_value %in% c(\"ak\", \"ca\", \"ny\")) r <- epi_recipe(jhu) %>% step_epi_lag(death_rate, lag = c(0, 7, 14)) %>% step_epi_ahead(death_rate, ahead = 7) %>% step_epi_naomit() wf <- epi_workflow(r, parsnip::linear_reg()) %>% fit(jhu) latest <- get_test_data(recipe = r, x = jhu) f <- frosting() %>% layer_predict() %>% layer_residual_quantiles(probs = c(0.0275, 0.975), symmetrize = FALSE) %>% layer_naomit(.pred) wf1 <- wf %>% add_frosting(f) p <- predict(wf1, latest) f2 <- frosting() %>% layer_predict() %>% layer_residual_quantiles(probs = c(0.3, 0.7), by_key = \"geo_value\") %>% layer_naomit(.pred) wf2 <- wf %>% add_frosting(f2) p2 <- predict(wf2, latest) #> Warning: Some grouping keys are not in data.frame returned by the"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_threshold.html","id":null,"dir":"Reference","previous_headings":"","what":"Lower and upper thresholds for predicted values — layer_threshold","title":"Lower and upper thresholds for predicted values — layer_threshold","text":"postprocessing step used set prediction values smaller lower threshold higher upper threshold equal threshold values.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_threshold.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Lower and upper thresholds for predicted values — layer_threshold","text":"","code":"layer_threshold( frosting, ..., lower = 0, upper = Inf, id = rand_id(\"threshold\") )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_threshold.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Lower and upper thresholds for predicted values — layer_threshold","text":"frosting frosting postprocessor ... One unquoted expressions separated commas. Variable names can used positions data frame, expressions like x:y can used select range variables. Typical usage .pred threshold predictions range (say, nonnegative). lower Lower threshold prediction values. , predictions less lower bound set . Default value 0. upper Upper threshold prediction values. , predictions greater upper bound set . Default value Inf. id random id string","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_threshold.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Lower and upper thresholds for predicted values — layer_threshold","text":"updated frosting postprocessor","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_threshold.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Lower and upper thresholds for predicted values — layer_threshold","text":"","code":"jhu <- case_death_rate_subset %>% dplyr::filter(time_value < \"2021-03-08\", geo_value %in% c(\"ak\", \"ca\", \"ar\")) r <- epi_recipe(jhu) %>% step_epi_lag(death_rate, lag = c(0, 7, 14)) %>% step_epi_ahead(death_rate, ahead = 7) %>% step_epi_naomit() wf <- epi_workflow(r, parsnip::linear_reg()) %>% fit(jhu) latest <- get_test_data(r, jhu) f <- frosting() %>% layer_predict() %>% layer_threshold(.pred, lower = 0.180, upper = 0.310) wf <- wf %>% add_frosting(f) p <- predict(wf, latest) p #> An `epi_df` object, 3 x 3 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 3 × 3 #> geo_value time_value .pred #> * #> 1 ak 2021-03-07 0.18 #> 2 ar 2021-03-07 0.18 #> 3 ca 2021-03-07 0.31"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_unnest.html","id":null,"dir":"Reference","previous_headings":"","what":"Unnest prediction list-cols — layer_unnest","title":"Unnest prediction list-cols — layer_unnest","text":"Unnest prediction list-cols","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_unnest.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Unnest prediction list-cols — layer_unnest","text":"","code":"layer_unnest(frosting, ..., id = rand_id(\"unnest\"))"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_unnest.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Unnest prediction list-cols — layer_unnest","text":"frosting frosting postprocessor ... One unquoted expressions separated commas. Variable names can used positions data frame, expressions like x:y can used select range variables. id random id string","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_unnest.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Unnest prediction list-cols — layer_unnest","text":"updated frosting postprocessor","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/nested_quantiles.html","id":null,"dir":"Reference","previous_headings":"","what":"Turn a vector of quantile distributions into a list-col — nested_quantiles","title":"Turn a vector of quantile distributions into a list-col — nested_quantiles","text":"Turn vector quantile distributions list-col","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/nested_quantiles.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Turn a vector of quantile distributions into a list-col — nested_quantiles","text":"","code":"nested_quantiles(x)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/nested_quantiles.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Turn a vector of quantile distributions into a list-col — nested_quantiles","text":"x distribution containing dist_quantiles","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/nested_quantiles.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Turn a vector of quantile distributions into a list-col — nested_quantiles","text":"list-col","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/nested_quantiles.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Turn a vector of quantile distributions into a list-col — nested_quantiles","text":"","code":"edf <- case_death_rate_subset[1:3,] edf$q <- dist_quantiles(list(1:5, 2:4, 3:10), list(1:5/6, 2:4/5, 3:10/11)) edf_nested <- edf %>% dplyr::mutate(q = nested_quantiles(q)) edf_nested %>% tidyr::unnest(q) #> An `epi_df` object, 16 x 6 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 16 × 6 #> geo_value time_value case_rate death_rate q tau #> * #> 1 ak 2020-12-31 35.9 0.158 1 0.167 #> 2 ak 2020-12-31 35.9 0.158 2 0.333 #> 3 ak 2020-12-31 35.9 0.158 3 0.5 #> 4 ak 2020-12-31 35.9 0.158 4 0.667 #> 5 ak 2020-12-31 35.9 0.158 5 0.833 #> 6 al 2020-12-31 65.1 0.438 2 0.4 #> 7 al 2020-12-31 65.1 0.438 3 0.6 #> 8 al 2020-12-31 65.1 0.438 4 0.8 #> 9 ar 2020-12-31 66.0 1.27 3 0.273 #> 10 ar 2020-12-31 66.0 1.27 4 0.364 #> 11 ar 2020-12-31 66.0 1.27 5 0.455 #> 12 ar 2020-12-31 66.0 1.27 6 0.545 #> 13 ar 2020-12-31 66.0 1.27 7 0.636 #> 14 ar 2020-12-31 66.0 1.27 8 0.727 #> 15 ar 2020-12-31 66.0 1.27 9 0.818 #> 16 ar 2020-12-31 66.0 1.27 10 0.909"},{"path":"https://cmu-delphi.github.io/epipredict/reference/new_epi_recipe_blueprint.html","id":null,"dir":"Reference","previous_headings":"","what":"Recipe blueprint that accounts for epi_df panel data — new_epi_recipe_blueprint","title":"Recipe blueprint that accounts for epi_df panel data — new_epi_recipe_blueprint","text":"Used simplicity. See hardhat::new_recipe_blueprint() hardhat::default_recipe_blueprint() details.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/new_epi_recipe_blueprint.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Recipe blueprint that accounts for epi_df panel data — new_epi_recipe_blueprint","text":"","code":"new_epi_recipe_blueprint( intercept = FALSE, allow_novel_levels = FALSE, fresh = TRUE, composition = \"tibble\", ptypes = NULL, recipe = NULL, ..., subclass = character() ) epi_recipe_blueprint( intercept = FALSE, allow_novel_levels = FALSE, fresh = TRUE, composition = \"tibble\" ) default_epi_recipe_blueprint( intercept = FALSE, allow_novel_levels = FALSE, fresh = TRUE, composition = \"tibble\" ) new_default_epi_recipe_blueprint( intercept = FALSE, allow_novel_levels = FALSE, fresh = TRUE, composition = \"tibble\", ptypes = NULL, recipe = NULL, extra_role_ptypes = NULL, ..., subclass = character() )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/new_epi_recipe_blueprint.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Recipe blueprint that accounts for epi_df panel data — new_epi_recipe_blueprint","text":"intercept logical. intercept included processed data? information used process function mold forge function list. allow_novel_levels logical. novel factor levels allowed prediction time? information used clean function forge function list, passed scream(). fresh already trained operations re-trained prep() called? composition Either \"tibble\", \"matrix\", \"dgCMatrix\" format processed predictors. \"matrix\" \"dgCMatrix\" chosen, predictors must numeric preprocessing method applied; otherwise error thrown. ptypes Either NULL, named list 2 elements, predictors outcomes, 0-row tibbles. ptypes generated automatically mold() time used validate new_data prediction time. recipe Either NULL, unprepped recipe. argument set automatically mold() time. ... Name-value pairs additional elements blueprints subclass blueprint. subclass character vector. subclasses blueprint. extra_role_ptypes named list. names unique non-standard recipe roles (.e. everything except \"predictors\" \"outcomes\"). values prototypes original columns role. used validation forge().","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/new_epi_recipe_blueprint.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Recipe blueprint that accounts for epi_df panel data — new_epi_recipe_blueprint","text":"recipe blueprint.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/new_epi_recipe_blueprint.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Recipe blueprint that accounts for epi_df panel data — new_epi_recipe_blueprint","text":"bake_dependent_roles automatically set epi_df defaults.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/pipe.html","id":null,"dir":"Reference","previous_headings":"","what":"Pipe operator — %>%","title":"Pipe operator — %>%","text":"See magrittr::%>% details.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/pipe.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Pipe operator — %>%","text":"","code":"lhs %>% rhs"},{"path":"https://cmu-delphi.github.io/epipredict/reference/pipe.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Pipe operator — %>%","text":"lhs value magrittr placeholder. rhs function call using magrittr semantics.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/pipe.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Pipe operator — %>%","text":"result calling rhs(lhs).","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/pivot_quantiles.html","id":null,"dir":"Reference","previous_headings":"","what":"Pivot columns containing dist_quantile wider — pivot_quantiles","title":"Pivot columns containing dist_quantile wider — pivot_quantiles","text":"selected columns contain dist_quantiles \"widened\" \"taus\" (quantile) serving names values data frame. pivoting multiple columns, original column name used prefix.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/pivot_quantiles.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Pivot columns containing dist_quantile wider — pivot_quantiles","text":"","code":"pivot_quantiles(.data, ...)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/pivot_quantiles.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Pivot columns containing dist_quantile wider — pivot_quantiles","text":".data data frame, data frame extension tibble epi_df. ... One unquoted expressions separated commas. Variable names can used positions data frame, expressions like x:y can used select range variables. selected columns ","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/pivot_quantiles.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Pivot columns containing dist_quantile wider — pivot_quantiles","text":"object class .data","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/pivot_quantiles.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Pivot columns containing dist_quantile wider — pivot_quantiles","text":"","code":"d1 <- c(dist_quantiles(1:3, 1:3 / 4), dist_quantiles(2:4, 1:3 / 4)) d2 <- c(dist_quantiles(2:4, 2:4 / 5), dist_quantiles(3:5, 2:4 / 5)) tib <- tibble::tibble(g = c(\"a\", \"b\"), d1 = d1, d2 = d2) pivot_quantiles(tib, c(\"d1\", \"d2\")) #> # A tibble: 2 × 7 #> g d1_0.25 d1_0.5 d1_0.75 d2_0.4 d2_0.6 d2_0.8 #> #> 1 a 1 2 3 2 3 4 #> 2 b 2 3 4 3 4 5 pivot_quantiles(tib, tidyselect::starts_with(\"d\")) #> # A tibble: 2 × 7 #> g d1_0.25 d1_0.5 d1_0.75 d2_0.4 d2_0.6 d2_0.8 #> #> 1 a 1 2 3 2 3 4 #> 2 b 2 3 4 3 4 5 pivot_quantiles(tib, d2) #> # A tibble: 2 × 5 #> g d1 `0.4` `0.6` `0.8` #> #> 1 a [0.25, 0.75] 2 3 4 #> 2 b [0.25, 0.75] 3 4 5"},{"path":"https://cmu-delphi.github.io/epipredict/reference/predict-epi_workflow.html","id":null,"dir":"Reference","previous_headings":"","what":"Predict from an epi_workflow — predict-epi_workflow","title":"Predict from an epi_workflow — predict-epi_workflow","text":"predict() method fit epi_workflow object. nice thing predicting epi_workflow : Preprocess new_data using preprocessing method specified workflow created fit. accomplished using hardhat::forge(), apply formula preprocessing call recipes::bake() recipe supplied. Call parsnip::predict.model_fit() using underlying fit parsnip model. Ensure returned object epiprocess::epi_df possible. Specifically, output time_value geo_value columns well prediction.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/predict-epi_workflow.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Predict from an epi_workflow — predict-epi_workflow","text":"","code":"# S3 method for epi_workflow predict(object, new_data, ...)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/predict-epi_workflow.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Predict from an epi_workflow — predict-epi_workflow","text":"object epi_workflow fit workflows::fit.workflow() new_data data frame containing new predictors preprocess predict ... Additional parsnip-related options, depending value type. Arguments underlying model's prediction function passed (use opts argument instead). Possible arguments : interval: type equal \"survival\" \"quantile\", interval estimates added, available? Options \"none\" \"confidence\". level: type equal \"conf_int\", \"pred_int\", \"survival\", parameter tail area intervals (e.g. confidence level confidence intervals). Default value 0.95. std_error: type equal \"conf_int\" \"pred_int\", add standard error fit prediction (scale linear predictors). Default value FALSE. quantile: type equal quantile, quantiles distribution. Default (1:9)/10. eval_time: type equal \"survival\" \"hazard\", time points survival probability hazard estimated.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/predict-epi_workflow.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Predict from an epi_workflow — predict-epi_workflow","text":"data frame model predictions, many rows new_data . new_data epi_df data frame time_value geo_value columns, result well.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/predict-epi_workflow.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Predict from an epi_workflow — predict-epi_workflow","text":"","code":"jhu <- case_death_rate_subset r <- epi_recipe(jhu) %>% step_epi_lag(death_rate, lag = c(0, 7, 14)) %>% step_epi_ahead(death_rate, ahead = 7) %>% step_epi_lag(case_rate, lag = c(0, 7, 14)) %>% step_epi_naomit() wf <- epi_workflow(r, parsnip::linear_reg()) %>% fit(jhu) latest <- jhu %>% dplyr::filter(time_value >= max(time_value) - 14) preds <- predict(wf, latest) preds #> An `epi_df` object, 56 x 3 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 56 × 3 #> geo_value time_value .pred #> * #> 1 ak 2021-12-31 0.378 #> 2 al 2021-12-31 0.280 #> 3 ar 2021-12-31 0.452 #> 4 as 2021-12-31 -0.000475 #> 5 az 2021-12-31 0.657 #> 6 ca 2021-12-31 0.293 #> 7 co 2021-12-31 0.569 #> 8 ct 2021-12-31 0.641 #> 9 dc 2021-12-31 1.02 #> 10 de 2021-12-31 0.733 #> # ℹ 46 more rows"},{"path":"https://cmu-delphi.github.io/epipredict/reference/quantile_reg.html","id":null,"dir":"Reference","previous_headings":"","what":"Quantile regression — quantile_reg","title":"Quantile regression — quantile_reg","text":"quantile_reg() generates quantile regression model specification tidymodels framework. Currently, supported engine \"rq\" uses quantreg::rq().","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/quantile_reg.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Quantile regression — quantile_reg","text":"","code":"quantile_reg(mode = \"regression\", engine = \"rq\", tau = 0.5)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/quantile_reg.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Quantile regression — quantile_reg","text":"mode single character string type model. possible value model \"regression\". engine Character string naming fitting function. Currently, \"rq\" supported. tau scalar vector values (0, 1) determine quantiles estimate (default 0.5).","code":""},{"path":[]},{"path":"https://cmu-delphi.github.io/epipredict/reference/quantile_reg.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Quantile regression — quantile_reg","text":"","code":"tib <- data.frame(y = rnorm(100), x1 = rnorm(100), x2 = rnorm(100)) rq_spec <- quantile_reg(tau = c(.2, .8)) %>% set_engine(\"rq\") ff <- rq_spec %>% fit(y ~ ., data = tib) predict(ff, new_data = tib) #> # A tibble: 100 × 1 #> .pred #> #> 1 [0.2, 0.8] #> 2 [0.2, 0.8] #> 3 [0.2, 0.8] #> 4 [0.2, 0.8] #> 5 [0.2, 0.8] #> 6 [0.2, 0.8] #> 7 [0.2, 0.8] #> 8 [0.2, 0.8] #> 9 [0.2, 0.8] #> 10 [0.2, 0.8] #> # ℹ 90 more rows"},{"path":"https://cmu-delphi.github.io/epipredict/reference/reexports.html","id":null,"dir":"Reference","previous_headings":"","what":"Objects exported from other packages — reexports","title":"Objects exported from other packages — reexports","text":"objects imported packages. Follow links see documentation. generics fit recipes bake, prep","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/slather.html","id":null,"dir":"Reference","previous_headings":"","what":"Spread a layer of frosting on a fitted workflow — slather","title":"Spread a layer of frosting on a fitted workflow — slather","text":"Slathering frosting means implement postprocessing layer. creating new postprocessing layer, must implement S3 method function","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/slather.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Spread a layer of frosting on a fitted workflow — slather","text":"","code":"slather(object, components, workflow, new_data, ...)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/slather.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Spread a layer of frosting on a fitted workflow — slather","text":"object workflow frosting postprocessing steps components list components containing model information. updated returned layer. mold - output calling hardhat::mold() workflow. contains information preprocessing, including recipe. forged - output calling hardhat::forge() workflow. predictors outcomes new_data. three components predictors, outcomes (new_data), extras (usually rest data, including keys). keys - put keys (time_value, geo_value, others) ease. workflow object class workflow new_data data frame containing new predictors preprocess predict ... additional arguments used methods. Currently unused.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/slather.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Spread a layer of frosting on a fitted workflow — slather","text":"components list. format applying updates.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/smooth_quantile_reg.html","id":null,"dir":"Reference","previous_headings":"","what":"Smooth quantile regression — smooth_quantile_reg","title":"Smooth quantile regression — smooth_quantile_reg","text":"smooth_quantile_reg() generates quantile regression model specification tidymodels framework. Currently, supported engine smoothqr::smooth_qr().","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/smooth_quantile_reg.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Smooth quantile regression — smooth_quantile_reg","text":"","code":"smooth_quantile_reg( mode = \"regression\", engine = \"smoothqr\", outcome_locations = NULL, tau = 0.5, degree = 3L )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/smooth_quantile_reg.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Smooth quantile regression — smooth_quantile_reg","text":"mode single character string type model. possible value model \"regression\". engine Character string naming fitting function. Currently, \"smooth_qr\" supported. outcome_locations Defaults vector 1:ncol(y) responses observed different spacing (appear different order), information used . argument mapped ahead argument smoothqr::smooth_qr(). tau scalar vector values (0, 1) determine quantiles estimate (default 0.5). degree number polynomials used response smoothing. Must number responses.","code":""},{"path":[]},{"path":"https://cmu-delphi.github.io/epipredict/reference/smooth_quantile_reg.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Smooth quantile regression — smooth_quantile_reg","text":"","code":"tib <- data.frame( y1 = rnorm(100), y2 = rnorm(100), y3 = rnorm(100), y4 = rnorm(100), y5 = rnorm(100), y6 = rnorm(100), x1 = rnorm(100), x2 = rnorm(100)) qr_spec <- smooth_quantile_reg(tau = c(.2, .5, .8), outcome_locations = 1:6) ff <- qr_spec %>% fit(cbind(y1, y2 , y3 , y4 , y5 , y6) ~ ., data = tib) p <- predict(ff, new_data = tib) x <- -99:99 / 100 * 2 * pi y <- sin(x) + rnorm(length(x), sd = .1) fd <- x[length(x) - 20] XY <- smoothqr::lagmat(y[1:(length(y) - 20)], c(-20:20)) XY <- tibble::as_tibble(XY) qr_spec <- smooth_quantile_reg(tau = c(.2, .5, .8), outcome_locations = 20:1) tt <- qr_spec %>% fit_xy(x = XY[,21:41], y = XY[,1:20]) library(tidyr) library(dplyr) pl <- predict( object = tt, new_data = XY[max(which(complete.cases(XY[,21:41]))), 21:41] ) pl <- pl %>% unnest(.pred) %>% mutate(distn = nested_quantiles(distn)) %>% unnest(distn) %>% mutate(x = x[length(x) - 20] + ahead / 100 * 2 * pi, ahead = NULL) %>% pivot_wider(names_from = tau, values_from = q) plot(x, y, pch = 16, xlim = c(pi, 2 * pi), col = \"lightgrey\") curve(sin(x), add = TRUE) abline(v = fd, lty = 2) lines(pl$x, pl$`0.2`, col = \"blue\") lines(pl$x, pl$`0.8`, col = \"blue\") lines(pl$x, pl$`0.5`, col = \"red\") if (FALSE) { ggplot(data.frame(x = x, y = y), aes(x)) + geom_ribbon(data = pl, aes(ymin = `0.2`, ymax = `0.8`), fill = \"lightblue\") + geom_point(aes(y = y), colour = \"grey\") + # observed data geom_function(fun = sin, colour = \"black\") + # truth geom_vline(xintercept = fd, linetype = \"dashed\") + # end of training data geom_line(data = pl, aes(y = `0.5`), colour = \"red\") + # median prediction theme_bw() + coord_cartesian(xlim = c(0, NA)) + ylab(\"y\") }"},{"path":"https://cmu-delphi.github.io/epipredict/reference/state_census.html","id":null,"dir":"Reference","previous_headings":"","what":"State population data — state_census","title":"State population data — state_census","text":"Data set state populations, 2019 US Census.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/state_census.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"State population data — state_census","text":"","code":"state_census"},{"path":"https://cmu-delphi.github.io/epipredict/reference/state_census.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"State population data — state_census","text":"Data frame 57 rows (including one United States whole, plus District Columbia, Puerto Rico Commonwealth, American Samoa, Guam, U.S. Virgin Islands, Northern Mariana, Islands). fips FIPS code name Full name state territory pop Estimate location's resident population 2019. abbr Postal abbreviation location","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/state_census.html","id":"source","dir":"Reference","previous_headings":"","what":"Source","title":"State population data — state_census","text":"United States Census Bureau, https://www2.census.gov/programs-surveys/popest/datasets/2010-2019/counties/totals/co-est2019-alldata.pdf, https://www.census.gov/data/tables/time-series/demo/popest/2010s-total-puerto-rico-municipios.html, https://www.census.gov/data/tables/2010/dec/2010-island-areas.html","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_epi_naomit.html","id":null,"dir":"Reference","previous_headings":"","what":"Unified NA omission wrapper function for recipes — step_epi_naomit","title":"Unified NA omission wrapper function for recipes — step_epi_naomit","text":"Unified NA omission wrapper function recipes","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_epi_naomit.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Unified NA omission wrapper function for recipes — step_epi_naomit","text":"","code":"step_epi_naomit(recipe)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_epi_naomit.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Unified NA omission wrapper function for recipes — step_epi_naomit","text":"recipe Recipe used omission steps","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_epi_naomit.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Unified NA omission wrapper function for recipes — step_epi_naomit","text":"Omits NA's predictors outcomes training time fit model. Also omits associated predictors outcomes prediction time due lack response avoidance data loss.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_epi_naomit.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Unified NA omission wrapper function for recipes — step_epi_naomit","text":"","code":"case_death_rate_subset %>% epi_recipe() %>% step_epi_naomit() #> #> ── Recipe ────────────────────────────────────────────────────────────────────── #> #> ── Inputs #> Number of variables by role #> raw: 2 #> geo_value: 1 #> time_value: 1 #> #> ── Operations #> • Removing rows with NA values in: all_predictors() #> • Removing rows with NA values in: all_outcomes()"},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_epi_shift.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a shifted predictor — step_epi_lag","title":"Create a shifted predictor — step_epi_lag","text":"step_epi_lag step_epi_ahead create specification recipe step add new columns shifted data. former created lag column, latter create lead column. Shifted data default include NA values shift induced. can properly removed step_epi_naomit(), may specify alternative filler value default argument.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_epi_shift.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a shifted predictor — step_epi_lag","text":"","code":"step_epi_lag( recipe, ..., role = \"predictor\", trained = FALSE, lag, prefix = \"lag_\", default = NA, columns = NULL, skip = FALSE, id = rand_id(\"epi_lag\") ) step_epi_ahead( recipe, ..., role = \"outcome\", trained = FALSE, ahead, prefix = \"ahead_\", default = NA, columns = NULL, skip = FALSE, id = rand_id(\"epi_ahead\") )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_epi_shift.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a shifted predictor — step_epi_lag","text":"recipe recipe object. step added sequence operations recipe. ... One selector functions choose variables step. See recipes::selections() details. role model terms created step, analysis role assigned? lag default predictor ahead outcome. trained logical indicate quantities preprocessing estimated. lag, ahead vector integers. specified column lag lead value vector. Lag integers must nonnegative, ahead integers must positive. prefix prefix indicate type variable default Determines fills empty rows left leading/lagging (defaults NA). columns character string variable names populated (eventually) terms argument. skip logical. step skipped recipe baked bake()? operations baked prep() run, operations may able conducted new data (e.g. processing outcome variable(s)). Care taken using skip = TRUE may affect computations subsequent operations. id unique identifier step","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_epi_shift.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a shifted predictor — step_epi_lag","text":"updated version recipe new step added sequence existing operations.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_epi_shift.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Create a shifted predictor — step_epi_lag","text":"step assumes data already proper sequential order shifting. prefix id arguments unchangeable ensure code runs properly avoid inconsistency naming. step_epi_ahead, always set \"ahead_\" \"epi_ahead\" respectively, step_epi_lag, set \"lag_\" \"epi_lag, respectively.","code":""},{"path":[]},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_epi_shift.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create a shifted predictor — step_epi_lag","text":"","code":"r <- epi_recipe(case_death_rate_subset) %>% step_epi_ahead(death_rate, ahead = 7) %>% step_epi_lag(death_rate, lag = c(0,7,14)) r #> #> ── Recipe ────────────────────────────────────────────────────────────────────── #> #> ── Inputs #> Number of variables by role #> raw: 2 #> geo_value: 1 #> time_value: 1 #> #> ── Operations #> • Leading: death_rate by 7 #> • Lagging: death_rate by 0, 7, 14"},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_growth_rate.html","id":null,"dir":"Reference","previous_headings":"","what":"Calculate a growth rate — step_growth_rate","title":"Calculate a growth rate — step_growth_rate","text":"step_growth_rate() creates specification recipe step generate one new columns derived data.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_growth_rate.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Calculate a growth rate — step_growth_rate","text":"","code":"step_growth_rate( recipe, ..., role = \"predictor\", trained = FALSE, horizon = 7, method = c(\"rel_change\", \"linear_reg\", \"smooth_spline\", \"trend_filter\"), log_scale = FALSE, replace_Inf = NA, prefix = \"gr_\", columns = NULL, skip = FALSE, id = rand_id(\"growth_rate\"), additional_gr_args_list = list() )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_growth_rate.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Calculate a growth rate — step_growth_rate","text":"recipe recipe object. step added sequence operations recipe. ... One selector functions choose variables step. See recipes::selections() details. role model terms created step, analysis role assigned? lag default predictor ahead outcome. trained logical indicate quantities preprocessing estimated. horizon Bandwidth sliding window, method \"rel_change\" \"linear_reg\". See epiprocess::growth_rate() details. method Either \"rel_change\", \"linear_reg\", \"smooth_spline\", \"trend_filter\", indicating method use growth rate calculation. first two local methods: run sliding fashion sequence (order estimate derivatives hence growth rates); latter two global methods: run entire sequence. See epiprocess::growth_rate() details. log_scale growth rates estimated using parameterization log scale? See details explanation. Default FALSE. replace_Inf Sometimes, growth rate calculation can result infinite values (denominator zero, example). case, prediction methods fail. argument specifies potential replacement values. default (NA) likely result rows removed data. Alternatively, specify arbitrary large values, perhaps zero. Setting argument NULL result replacement. prefix prefix indicate type variable columns character string variable names populated (eventually) terms argument. skip logical. step skipped recipe baked bake()? operations baked prep() run, operations may able conducted new data (e.g. processing outcome variable(s)). Care taken using skip = TRUE may affect computations subsequent operations. id unique identifier step additional_gr_args_list list additional arguments used epiprocess::growth_rate(). ... arguments may passed along dup_rm na_rm.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_growth_rate.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Calculate a growth rate — step_growth_rate","text":"updated version recipe new step added sequence existing operations.","code":""},{"path":[]},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_growth_rate.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Calculate a growth rate — step_growth_rate","text":"","code":"r <- epi_recipe(case_death_rate_subset) %>% step_growth_rate(case_rate, death_rate) r #> #> ── Recipe ────────────────────────────────────────────────────────────────────── #> #> ── Inputs #> Number of variables by role #> raw: 2 #> geo_value: 1 #> time_value: 1 #> #> ── Operations #> • Calculating growth_rate for: case_rate, death_rate by rel_change r %>% recipes::prep() %>% recipes::bake(case_death_rate_subset) #> An `epi_df` object, 20,496 x 6 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 20,496 × 6 #> time_value geo_value case_rate death_rate gr_7_rel_change_case_rate #> * #> 1 2020-12-31 ak 35.9 0.158 NA #> 2 2020-12-31 al 65.1 0.438 NA #> 3 2020-12-31 ar 66.0 1.27 NA #> 4 2020-12-31 as 0 0 NA #> 5 2020-12-31 az 76.8 1.10 NA #> 6 2020-12-31 ca 96.0 0.751 NA #> 7 2020-12-31 co 35.8 0.649 NA #> 8 2020-12-31 ct 52.1 0.819 NA #> 9 2020-12-31 dc 31.0 0.601 NA #> 10 2020-12-31 de 65.2 0.807 NA #> # ℹ 20,486 more rows #> # ℹ 1 more variable: gr_7_rel_change_death_rate "},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_lag_difference.html","id":null,"dir":"Reference","previous_headings":"","what":"Calculate a lagged difference — step_lag_difference","title":"Calculate a lagged difference — step_lag_difference","text":"step_lag_difference() creates specification recipe step generate one new columns derived data.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_lag_difference.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Calculate a lagged difference — step_lag_difference","text":"","code":"step_lag_difference( recipe, ..., role = \"predictor\", trained = FALSE, horizon = 7, prefix = \"lag_diff_\", columns = NULL, skip = FALSE, id = rand_id(\"lag_diff\") )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_lag_difference.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Calculate a lagged difference — step_lag_difference","text":"recipe recipe object. step added sequence operations recipe. ... One selector functions choose variables step. See recipes::selections() details. role model terms created step, analysis role assigned? lag default predictor ahead outcome. trained logical indicate quantities preprocessing estimated. horizon Scalar vector. Time period(s) calculate differences. prefix prefix indicate type variable columns character string variable names populated (eventually) terms argument. skip logical. step skipped recipe baked bake()? operations baked prep() run, operations may able conducted new data (e.g. processing outcome variable(s)). Care taken using skip = TRUE may affect computations subsequent operations. id unique identifier step","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_lag_difference.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Calculate a lagged difference — step_lag_difference","text":"updated version recipe new step added sequence existing operations.","code":""},{"path":[]},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_lag_difference.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Calculate a lagged difference — step_lag_difference","text":"","code":"r <- epi_recipe(case_death_rate_subset) %>% step_lag_difference(case_rate, death_rate, horizon = c(7, 14)) r #> #> ── Recipe ────────────────────────────────────────────────────────────────────── #> #> ── Inputs #> Number of variables by role #> raw: 2 #> geo_value: 1 #> time_value: 1 #> #> ── Operations #> • Calculating lag_difference for: case_rate, death_rate by 7, 14 r %>% recipes::prep() %>% recipes::bake(case_death_rate_subset) #> An `epi_df` object, 20,496 x 8 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 20,496 × 8 #> time_value geo_value case_rate death_rate lag_diff_7_case_rate #> * #> 1 2020-12-31 ak 35.9 0.158 NA #> 2 2020-12-31 al 65.1 0.438 NA #> 3 2020-12-31 ar 66.0 1.27 NA #> 4 2020-12-31 as 0 0 NA #> 5 2020-12-31 az 76.8 1.10 NA #> 6 2020-12-31 ca 96.0 0.751 NA #> 7 2020-12-31 co 35.8 0.649 NA #> 8 2020-12-31 ct 52.1 0.819 NA #> 9 2020-12-31 dc 31.0 0.601 NA #> 10 2020-12-31 de 65.2 0.807 NA #> # ℹ 20,486 more rows #> # ℹ 3 more variables: lag_diff_14_case_rate , lag_diff_7_death_rate , #> # lag_diff_14_death_rate "},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_population_scaling.html","id":null,"dir":"Reference","previous_headings":"","what":"Convert raw scale predictions to per-capita — step_population_scaling","title":"Convert raw scale predictions to per-capita — step_population_scaling","text":"step_population_scaling creates specification recipe step perform per-capita scaling. Typical usage load dataset contains state-level population, use convert predictions made raw scale model rate-scale dividing population. Although, worth noting nothing special \"population\". function can used scale variable. Population standard use case epidemiology forecasting scenario. value passed divide selected variables rate_rescaling argument common multiplier selected variables.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_population_scaling.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Convert raw scale predictions to per-capita — step_population_scaling","text":"","code":"step_population_scaling( recipe, ..., role = \"raw\", trained = FALSE, df, by = NULL, df_pop_col, rate_rescaling = 1, create_new = TRUE, suffix = \"_scaled\", columns = NULL, skip = FALSE, id = rand_id(\"population_scaling\") )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_population_scaling.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Convert raw scale predictions to per-capita — step_population_scaling","text":"recipe recipe object. step added sequence operations recipe. recipe contain information epi_df column names. ... One selector functions scale variables step. See recipes::selections() details. role model terms created step, analysis role assigned? default, new columns created step original variables used predictors model. options can ard limited \"outcome\". trained logical indicate quantities preprocessing estimated. df data frame contains population data used inverting existing scaling. (possibly named) character vector variables join . NULL, default, function perform natural join, using variables common across epi_df produced predict() call user-provided dataset. columns epi_df df name (included ), .df added one user-provided data disambiguate. join different variables epi_df df, use named vector. example, = c(\"geo_value\" = \"states\") match epi_df$geo_value df$states. join multiple variables, use vector length > 1. example, = c(\"geo_value\" = \"states\", \"county\" = \"county\") match epi_df$geo_value df$states epi_df$county df$county. See dplyr::left_join() details. df_pop_col name column data frame df contains population data used scaling. one column. rate_rescaling Sometimes raw scales \"per 100K\" \"per 1M\". Adjustments can made . example, original scale \"per 100K\", set rate_rescaling = 1e5 get rates. create_new TRUE create new column keep original column epi_df suffix character. suffix added column name crete_new = TRUE. Default \"_scaled\". columns character string variable names populated (eventually) terms argument. skip logical. step skipped recipe baked bake()? operations baked prep() run, operations may able conducted new data (e.g. processing outcome variable(s)). Care taken using skip = TRUE may affect computations subsequent operations. id unique identifier step","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_population_scaling.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Convert raw scale predictions to per-capita — step_population_scaling","text":"Scales raw data population","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_population_scaling.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Convert raw scale predictions to per-capita — step_population_scaling","text":"","code":"library(epiprocess) library(epipredict) jhu <- epiprocess::jhu_csse_daily_subset %>% dplyr::filter(time_value > \"2021-11-01\", geo_value %in% c(\"ca\", \"ny\")) %>% dplyr::select(geo_value, time_value, cases) pop_data = data.frame(states = c(\"ca\", \"ny\"), value = c(20000, 30000)) r <- epi_recipe(jhu) %>% step_population_scaling(df = pop_data, df_pop_col = \"value\", by = c(\"geo_value\" = \"states\"), cases, suffix = \"_scaled\") %>% step_epi_lag(cases_scaled, lag = c(0, 7, 14)) %>% step_epi_ahead(cases_scaled, ahead = 7, role = \"outcome\") %>% step_epi_naomit() f <- frosting() %>% layer_predict() %>% layer_threshold(.pred) %>% layer_naomit(.pred) %>% layer_population_scaling(.pred, df = pop_data, by = c(\"geo_value\" = \"states\"), df_pop_col = \"value\") wf <- epi_workflow(r, parsnip::linear_reg()) %>% fit(jhu) %>% add_frosting(f) latest <- get_test_data( recipe = r, epiprocess::jhu_csse_daily_subset %>% dplyr::filter(time_value > \"2021-11-01\", geo_value %in% c(\"ca\", \"ny\")) %>% dplyr::select(geo_value, time_value, cases) ) predict(wf, latest) #> An `epi_df` object, 2 x 4 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-23 20:17:07.044666 #> #> # A tibble: 2 × 4 #> geo_value time_value .pred .pred_scaled #> * #> 1 ca 2021-12-31 4.25 84967. #> 2 ny 2021-12-31 5.93 177783."},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_training_window.html","id":null,"dir":"Reference","previous_headings":"","what":"Limits the size of the training window to the most recent observations — step_training_window","title":"Limits the size of the training window to the most recent observations — step_training_window","text":"step_training_window creates specification recipe step limits size training window n_recent recent observations time_value per group, groups formed based remaining epi_keys.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_training_window.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Limits the size of the training window to the most recent observations — step_training_window","text":"","code":"step_training_window( recipe, role = NA, trained = FALSE, n_recent = 50, epi_keys = NULL, id = rand_id(\"training_window\") )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_training_window.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Limits the size of the training window to the most recent observations — step_training_window","text":"recipe recipe object. step added sequence operations recipe. role used step since new variables created. trained logical indicate quantities preprocessing estimated. n_recent integer value represents number recent observations kept training window per key default value 50. epi_keys optional character vector specifying \"key\" variables group . default, NULL, ensures every key combination limited. id character string unique step identify .","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_training_window.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Limits the size of the training window to the most recent observations — step_training_window","text":"updated version recipe new step added sequence existing operations.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_training_window.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Limits the size of the training window to the most recent observations — step_training_window","text":"Note step_epi_lead() step_epi_lag() come filtering step.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_training_window.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Limits the size of the training window to the most recent observations — step_training_window","text":"","code":"tib <- tibble::tibble( x = 1:10, y = 1:10, time_value = rep(seq(as.Date(\"2020-01-01\"), by = 1, length.out = 5), times = 2), geo_value = rep(c(\"ca\", \"hi\"), each = 5)) %>% as_epi_df() epi_recipe(y ~ x, data = tib) %>% step_training_window(n_recent = 3) %>% prep(tib) %>% bake(new_data = NULL) #> An `epi_df` object, 6 x 4 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2023-09-14 20:46:07.790956 #> #> # A tibble: 6 × 4 #> time_value geo_value x y #> * #> 1 2020-01-03 ca 3 3 #> 2 2020-01-04 ca 4 4 #> 3 2020-01-05 ca 5 5 #> 4 2020-01-03 hi 8 8 #> 5 2020-01-04 hi 9 9 #> 6 2020-01-05 hi 10 10 epi_recipe(y ~ x, data = tib) %>% recipes::step_naomit() %>% step_training_window(n_recent = 3) %>% prep(tib) %>% bake(new_data = NULL) #> An `epi_df` object, 6 x 4 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2023-09-14 20:46:07.790956 #> #> # A tibble: 6 × 4 #> time_value geo_value x y #> * #> 1 2020-01-03 ca 3 3 #> 2 2020-01-04 ca 4 4 #> 3 2020-01-05 ca 5 5 #> 4 2020-01-03 hi 8 8 #> 5 2020-01-04 hi 9 9 #> 6 2020-01-05 hi 10 10"},{"path":"https://cmu-delphi.github.io/epipredict/news/index.html","id":"epipredict-005","dir":"Changelog","previous_headings":"","what":"epipredict 0.0.5","title":"epipredict 0.0.5","text":"add smooth_quantile_reg() improved printing various methods / internals canned forecasters get class fixed quantile bug flatline_forecaster() add functionality output unfit workflow canned forecasters add pivot_quantiles() easier plotting","code":""},{"path":"https://cmu-delphi.github.io/epipredict/news/index.html","id":"epipredict-004","dir":"Changelog","previous_headings":"","what":"epipredict 0.0.4","title":"epipredict 0.0.4","text":"add quantile_reg() clean documentation bugs add smooth_quantile_reg() add classifier training window step debugged min_train_window argument removed canned forecasters","code":""},{"path":"https://cmu-delphi.github.io/epipredict/news/index.html","id":"epipredict-003","dir":"Changelog","previous_headings":"","what":"epipredict 0.0.3","title":"epipredict 0.0.3","text":"add forecasters implement postprocessing vignettes avaliable arx_forecaster pkgdown","code":""},{"path":"https://cmu-delphi.github.io/epipredict/news/index.html","id":"epipredict-0009000","dir":"Changelog","previous_headings":"","what":"epipredict 0.0.0.9000","title":"epipredict 0.0.0.9000","text":"Publish public easy navigation Two simple forecasters test beds Working vignette","code":""}] +[{"path":"https://cmu-delphi.github.io/epipredict/LICENSE.html","id":null,"dir":"","previous_headings":"","what":"MIT License","title":"MIT License","text":"Copyright (c) 2022 epipredict authors Permission hereby granted, free charge, person obtaining copy software associated documentation files (“Software”), deal Software without restriction, including without limitation rights use, copy, modify, merge, publish, distribute, sublicense, /sell copies Software, permit persons Software furnished , subject following conditions: copyright notice permission notice shall included copies substantial portions Software. SOFTWARE PROVIDED “”, WITHOUT WARRANTY KIND, EXPRESS IMPLIED, INCLUDING LIMITED WARRANTIES MERCHANTABILITY, FITNESS PARTICULAR PURPOSE NONINFRINGEMENT. EVENT SHALL AUTHORS COPYRIGHT HOLDERS LIABLE CLAIM, DAMAGES LIABILITY, WHETHER ACTION CONTRACT, TORT OTHERWISE, ARISING , CONNECTION SOFTWARE USE DEALINGS SOFTWARE.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/articles/epipredict.html","id":"goals-for-the-package","dir":"Articles","previous_headings":"","what":"Goals for the package","title":"Get started with epipredict","text":"high level, goal epipredict make running simple Machine Learning / Statistical forecasters epidemiology easy. However, package extremely extensible, part utility. hope easy users epi training statistics fit baseline models still allowing nuanced statistical understanding create complicated specializations using framework. Serving populations main motivation efforts, time, tried hard make useful.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/articles/epipredict.html","id":"baseline-models","dir":"Articles","previous_headings":"Goals for the package","what":"Baseline models","title":"Get started with epipredict","text":"provide set basic, easy--use forecasters work box. able reasonably limited amount customization . serious customization happens framework discussed ). basic forecasters, provide: Baseline flat-line forecaster Autoregressive forecaster Autoregressive classifier forcasters provide built framework. use basic models illustrate flexibility.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/articles/epipredict.html","id":"forecasting-framework","dir":"Articles","previous_headings":"Goals for the package","what":"Forecasting framework","title":"Get started with epipredict","text":"framework creating custom forecasters views prediction task set modular components. four types components: Preprocessor: make transformations data model training Trainer: train model data, resulting fitted model object Predictor: make predictions, using fitted model object processed test data Postprocessor: manipulate transform predictions returning Users familiar {tidymodels} especially {workflows} package notice lot overlap. design, fact feature. truth epipredict wrapper around much contained packages. Therefore, want something -verse, “just work” (hope). reason overlap workflows already implements first three steps. well. However, missing postprocessing stage currently plans implementation. feature important. baseline forecaster provide requires postprocessing. Anything complicated needs well. second omission tidymodels support panel data. Besides epidemiological data, economics, psychology, sociology, many areas frequently deal data type. framework behind epipredict implements . principle, nothing epidemiology, one simply use package solution missing functionality tidymodels. , “just work”. panel data functionality implemented epi_df data type companion {epiprocess} package. much see , moment, ’s enough look simple one: data built package contains measured variables case_rate death_rate COVID-19 daily level US state year 2021. “panel” part repeated measurements across number locations. epi_df encodes time stamp time_value key geo_value. 2 names required, values don’t need actually represent objects. Additional key’s also supported (like age group, ethnicity, taxonomy, etc.). epi_df also contains metadata describes keys well vintage data. ’s possible data collected different times set geo_value’s time_value’s actually different. details, see {epiprocess}.","code":"jhu <- case_death_rate_subset jhu #> An `epi_df` object, 20,496 x 4 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 20,496 × 4 #> geo_value time_value case_rate death_rate #> * #> 1 ak 2020-12-31 35.9 0.158 #> 2 al 2020-12-31 65.1 0.438 #> 3 ar 2020-12-31 66.0 1.27 #> 4 as 2020-12-31 0 0 #> 5 az 2020-12-31 76.8 1.10 #> 6 ca 2020-12-31 96.0 0.751 #> 7 co 2020-12-31 35.8 0.649 #> 8 ct 2020-12-31 52.1 0.819 #> 9 dc 2020-12-31 31.0 0.601 #> 10 de 2020-12-31 65.2 0.807 #> # ℹ 20,486 more rows"},{"path":"https://cmu-delphi.github.io/epipredict/articles/epipredict.html","id":"why-doesnt-this-package-already-exist","dir":"Articles","previous_headings":"Goals for the package","what":"Why doesn’t this package already exist?","title":"Get started with epipredict","text":"described : Parts actually exist. ’s universe called tidymodels. handles preprocessing, training, prediction, bound together, package called workflows. built epipredict top setup. way, CAN use almost everything provide. However, workflows doesn’t postprocessing. nothing -verse handles panel data. tidy-team doesn’t plans either things. (checked). two packages time series built tidymodels, ’s “basic” time series: 1-step AR models, exponential smoothing, STL decomposition, etc.1 group prioritized sorts models epidemic forecasting, one also integrate methods framework.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/articles/epipredict.html","id":"show-me-the-basics","dir":"Articles","previous_headings":"","what":"Show me the basics","title":"Get started with epipredict","text":"start jhu data displayed . One “canned” forecasters provide autoregressive forecaster (without) covariates directly trains response. contrast typical “iterative” AR model trains predict one-step-ahead, plugs predictions “leverage ” longer horizons. ’ll estimate model jointly across locations using recent 30 days. call produces warning, ’ll ignore now. essentially, ’s telling us data comes May 2022 ’re trying forecast January 2022. result likely accurate measure real-time forecast performance, data revised time. object two components: predictions just another epi_df. contains predictions location along additional columns. default, 90% predictive interval, forecast_date (date forecast putatively made) target_date (date forecast made). list object class epi_workflow. object encapsulates instructions necessary create prediction. details . Note time_value predictions necessarily meaningful, required column epi_df, remains . default, forecaster predicts outcome (death_rate) 1-week ahead, using 3 lags predictor (case_rate death_rate) 0 (today), 1 week back 2 weeks back. predictors outcome can changed directly. rest defaults encapsulated list arguments. list produced arx_args_list().","code":"jhu <- jhu %>% filter(time_value >= max(time_value) - 30) out <- arx_forecaster( jhu, outcome = \"death_rate\", predictors = c(\"case_rate\", \"death_rate\") ) #> Warning: The forecast_date is less than the most recent update date of the #> data: forecast_date = 2021-12-31 while data is from 2022-05-31. out$predictions #> # A tibble: 56 × 5 #> geo_value .pred .pred_distn forecast_date target_date #> #> 1 ak 0.355 [0.05, 0.95] 2021-12-31 2022-01-07 #> 2 al 0.325 [0.05, 0.95] 2021-12-31 2022-01-07 #> 3 ar 0.496 [0.05, 0.95] 2021-12-31 2022-01-07 #> 4 as 0.0836 [0.05, 0.95] 2021-12-31 2022-01-07 #> 5 az 0.614 [0.05, 0.95] 2021-12-31 2022-01-07 #> 6 ca 0.327 [0.05, 0.95] 2021-12-31 2022-01-07 #> 7 co 0.567 [0.05, 0.95] 2021-12-31 2022-01-07 #> 8 ct 0.544 [0.05, 0.95] 2021-12-31 2022-01-07 #> 9 dc 0.831 [0.05, 0.95] 2021-12-31 2022-01-07 #> 10 de 0.607 [0.05, 0.95] 2021-12-31 2022-01-07 #> # ℹ 46 more rows out$epi_workflow #> ══ Epi Workflow [trained] ══════════════════════════════════════════════════════ #> Preprocessor: Recipe #> Model: linear_reg() #> Postprocessor: Frosting #> #> ── Preprocessor ──────────────────────────────────────────────────────────────── #> 6 Recipe Steps #> #> • step_epi_lag() #> • step_epi_lag() #> • step_epi_ahead() #> • step_naomit() #> • step_naomit() #> • step_training_window() #> #> ── Model ─────────────────────────────────────────────────────────────────────── #> #> Call: #> stats::lm(formula = ..y ~ ., data = data) #> #> Coefficients: #> (Intercept) lag_0_case_rate lag_7_case_rate lag_14_case_rate #> 0.0829475 0.0009830 0.0027035 -0.0005651 #> lag_0_death_rate lag_7_death_rate lag_14_death_rate #> 0.2466110 0.1964921 0.0752998 #> #> ── Postprocessor ─────────────────────────────────────────────────────────────── #> 5 Frosting Layers #> #> • layer_predict() #> • layer_residual_quantiles() #> • layer_add_forecast_date() #> • layer_add_target_date() #> • layer_threshold()"},{"path":"https://cmu-delphi.github.io/epipredict/articles/epipredict.html","id":"simple-adjustments","dir":"Articles","previous_headings":"Show me the basics","what":"Simple adjustments","title":"Get started with epipredict","text":"Basic adjustments can made args_list. , ’ve used different lags case_rate now predicting 2 weeks ahead. example also illustrates major difficulty “iterative” versions AR models. model doesn’t produce forecasts case_rate, , data “plug ” necessary lags.2 Another property basic model predictive interval. describe detail different vignette, easy request multiple quantiles. column .pred_dstn predictions object actually “distribution” parameterized quantiles. default forecaster, created using quantiles residuals predictive model (possibly symmetrized). , used 23 quantiles, one can grab particular quantile, extract entire distribution “long” epi_df tau probability q value associated quantile. Additional simple adjustments basic forecaster can made using function:","code":"out2week <- arx_forecaster( jhu, outcome = \"death_rate\", predictors = c(\"case_rate\", \"death_rate\"), args_list = arx_args_list( lags = list(c(0, 1, 2, 3, 7, 14), c(0, 7, 14)), ahead = 14 ) ) out_q <- arx_forecaster(jhu, \"death_rate\", c(\"case_rate\", \"death_rate\"), args_list = arx_args_list( levels = c(.01, .025, seq(.05, .95, by = .05), .975, .99) ) ) head(quantile(out_q$predictions$.pred_distn, p = .4)) #> 40% 40% 40% 40% 40% 40% #> 0.30277798 0.27213225 0.44345734 0.03120647 0.56121844 0.27492711 out_q$predictions %>% # first create a \"nested\" list-column mutate(.pred_distn = nested_quantiles(.pred_distn)) %>% unnest(.pred_distn) # then unnest it #> # A tibble: 1,288 × 6 #> geo_value .pred q tau forecast_date target_date #> #> 1 ak 0.355 0 0.01 2021-12-31 2022-01-07 #> 2 ak 0.355 0 0.025 2021-12-31 2022-01-07 #> 3 ak 0.355 0.0371 0.05 2021-12-31 2022-01-07 #> 4 ak 0.355 0.123 0.1 2021-12-31 2022-01-07 #> 5 ak 0.355 0.174 0.15 2021-12-31 2022-01-07 #> 6 ak 0.355 0.211 0.2 2021-12-31 2022-01-07 #> 7 ak 0.355 0.237 0.25 2021-12-31 2022-01-07 #> 8 ak 0.355 0.260 0.3 2021-12-31 2022-01-07 #> 9 ak 0.355 0.282 0.35 2021-12-31 2022-01-07 #> 10 ak 0.355 0.303 0.4 2021-12-31 2022-01-07 #> # ℹ 1,278 more rows arx_args_list( lags = c(0L, 7L, 14L), ahead = 7L, n_training = Inf, forecast_date = NULL, target_date = NULL, levels = c(0.05, 0.95), symmetrize = TRUE, nonneg = TRUE, quantile_by_key = character(0L), nafill_buffer = Inf )"},{"path":"https://cmu-delphi.github.io/epipredict/articles/epipredict.html","id":"changing-the-engine","dir":"Articles","previous_headings":"Show me the basics","what":"Changing the engine","title":"Get started with epipredict","text":"far, forecasts produced using simple linear regression. way estimate model. trainer argument determines type model want. takes {parsnip} model. default linear regression, instead use random forest ranger package: boosted regression trees xgboost: quantile regression, using custom forecasting engine quantile_reg(): FWIW, last case (using quantile regression), far Delphi production forecast team used Covid forecasts past years.","code":"out_rf <- arx_forecaster( jhu, \"death_rate\", c(\"case_rate\", \"death_rate\"), rand_forest(mode = \"regression\") ) out_gb <- arx_forecaster( jhu, \"death_rate\", c(\"case_rate\", \"death_rate\"), boost_tree(mode = \"regression\", trees = 20) ) out_gb <- arx_forecaster( jhu, \"death_rate\", c(\"case_rate\", \"death_rate\"), quantile_reg() )"},{"path":"https://cmu-delphi.github.io/epipredict/articles/epipredict.html","id":"inner-workings","dir":"Articles","previous_headings":"Show me the basics","what":"Inner workings","title":"Get started with epipredict","text":"Underneath hood, forecaster creates (returns) epi_workflow. Essentially, big S3 object wraps 4 modular steps (preprocessing - postprocessing) described .","code":""},{"path":"https://cmu-delphi.github.io/epipredict/articles/epipredict.html","id":"preprocessing","dir":"Articles","previous_headings":"Show me the basics > Inner workings","what":"Preprocessing","title":"Get started with epipredict","text":"Preprocessing accomplished recipe (imagine baking cake) provided {recipes} package. ’ve made modifications (handle panel data) well added additional options. recipe gives specification handle training data. Think like fancified formula pass lm(): y ~ x1 + log(x2). general, 2 extensions formula recipes handles: transformations training test data can always applied. things like taking log variable, leading lagging, filtering rows, handling dummy variables, etc. Using statistics training data eventually process test data. major benefit recipes. prevents tidy team calls “data leakage”. simple example centering predictor mean. need store mean predictor training data use value test data rather accidentally calculating mean test predictor centering. recipe processed 2 steps, first “prepped”. calculates stores intermediate statistics necessary use test data. “baked” resulting training data ready passing statistical model (like lm). introduced epi_recipe. ’s just recipe knows handle time_value, geo_value, additional keys available necessary. epi_recipe out_gb can extracted result: “Inputs” original epi_df “roles” assigned. None predictors outcomes. created recipe prepped. “Operations” sequence instructions create cake (baked training data). create lagged predictors, lead outcome, remove NAs. models like lm internally handle NAs, everything , deal explicitly. code (inside forecaster) recipes provides function step_lag(), assumes data breaks sequence time_values. bit dangerous, avoid behaviour. lag/ahead functions also appropriately adjust amount data avoid accidentally dropping recent predictors test data.","code":"extract_recipe(out_gb$epi_workflow) er <- epi_recipe(jhu) %>% step_epi_lag(case_rate, death_rate, lag = c(0, 7, 14)) %>% step_epi_ahead(death_rate, ahead = 7) %>% step_epi_naomit()"},{"path":"https://cmu-delphi.github.io/epipredict/articles/epipredict.html","id":"the-model-specification","dir":"Articles","previous_headings":"Show me the basics > Inner workings","what":"The model specification","title":"Get started with epipredict","text":"Users familiarity parsnip package trouble . Basically, parsnip unifies function signature across statistical models. example, lm() “likes” work formulas, glmnet::glmnet() uses x y predictors response. parsnip agnostic. “linear regression”. switched lm() xgboost() without issue despite fact functions couldn’t different. epipredict provides engines/modules (flatline forecaster quantile regression), able use available models listed . estimate (fit) preprocessed model, one calls fit() epi_workflow.","code":"lm(formula, data, subset, weights, na.action, method = \"qr\", model = TRUE, x = FALSE, y = FALSE, qr = TRUE, singular.ok = TRUE, contrasts = NULL, offset, ... ) xgboost( data = NULL, label = NULL, missing = NA, weight = NULL, params = list(), nrounds, verbose = 1, print_every_n = 1L, early_stopping_rounds = NULL, maximize = NULL, save_period = NULL, save_name = \"xgboost.model\", xgb_model = NULL, callbacks = list(), ... ) ewf <- epi_workflow(er, linear_reg()) %>% fit(jhu)"},{"path":"https://cmu-delphi.github.io/epipredict/articles/epipredict.html","id":"postprocessing","dir":"Articles","previous_headings":"Show me the basics > Inner workings","what":"Postprocessing","title":"Get started with epipredict","text":"stretch metaphor preparing cake natural limits, created postprocessing functionality called “frosting”. Much like recipe, postprocessing operation “layer” “slather” onto baked cake. fix ideas, postprocessing frosting arx_forecaster() 5 layers frosting. first generates forecasts test data. second uses quantiles residuals create distributional forecasts. next two add columns date forecast made date intended occur. predicting rates, non-negative, last layer thresholds predicted values intervals 0. code (inside forecaster) predict time, add object onto epi_workflow call predict() get_test_data() function examines recipe ensures enough test data available create necessary lags produce prediction desired future time point (end training data). mimics happen jhu contained recent available historical data wanted actually predict future. instead used test data contained necessary predictors.","code":"extract_frosting(out_q$epi_workflow) f <- frosting() %>% layer_predict() %>% layer_residual_quantiles( probs = c(.01, .025, seq(.05, .95, by = .05), .975, .99), symmetrize = TRUE ) %>% layer_add_forecast_date() %>% layer_add_target_date() %>% layer_threshold(starts_with(\".pred\")) test_data <- get_test_data(er, jhu) ewf %>% add_frosting(f) %>% predict(test_data) #> An `epi_df` object, 56 x 6 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 56 × 6 #> geo_value time_value .pred .pred_distn forecast_date target_date #> * #> 1 ak 2021-12-31 0.355 [0.01, 0.99] 2021-12-31 2022-01-07 #> 2 al 2021-12-31 0.325 [0.01, 0.99] 2021-12-31 2022-01-07 #> 3 ar 2021-12-31 0.496 [0.01, 0.99] 2021-12-31 2022-01-07 #> 4 as 2021-12-31 0.0836 [0.01, 0.99] 2021-12-31 2022-01-07 #> 5 az 2021-12-31 0.614 [0.01, 0.99] 2021-12-31 2022-01-07 #> 6 ca 2021-12-31 0.327 [0.01, 0.99] 2021-12-31 2022-01-07 #> 7 co 2021-12-31 0.567 [0.01, 0.99] 2021-12-31 2022-01-07 #> 8 ct 2021-12-31 0.544 [0.01, 0.99] 2021-12-31 2022-01-07 #> 9 dc 2021-12-31 0.831 [0.01, 0.99] 2021-12-31 2022-01-07 #> 10 de 2021-12-31 0.607 [0.01, 0.99] 2021-12-31 2022-01-07 #> # ℹ 46 more rows"},{"path":"https://cmu-delphi.github.io/epipredict/articles/epipredict.html","id":"conclusion","dir":"Articles","previous_headings":"Show me the basics","what":"Conclusion","title":"Get started with epipredict","text":"Internally, provide simple functions create reasonable forecasts. ideally, user create forecasters building components provide. vignettes, try walk customizations. illustrate everything , (roughly) code flatline_forecaster() applied case_rate. really differs arx_forecaster() recipe, test data, engine. frosting identical, fitting predicting procedure.","code":"r <- epi_recipe(jhu) %>% step_epi_ahead(case_rate, ahead = 7, skip = TRUE) %>% update_role(case_rate, new_role = \"predictor\") %>% add_role(all_of(epi_keys(jhu)), new_role = \"predictor\") # bit of a weird hack to get the latest values per key latest <- get_test_data(epi_recipe(jhu), jhu) f <- frosting() %>% layer_predict() %>% layer_residual_quantiles() %>% layer_add_forecast_date() %>% layer_add_target_date() %>% layer_threshold(starts_with(\".pred\")) eng <- linear_reg() %>% set_engine(\"flatline\") wf <- epi_workflow(r, eng, f) %>% fit(jhu) preds <- predict(wf, latest) preds #> An `epi_df` object, 56 x 6 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 56 × 6 #> geo_value time_value .pred .pred_distn forecast_date target_date #> * #> 1 ak 2021-12-31 36.4 [0.05, 0.95] 2021-12-31 2022-01-07 #> 2 al 2021-12-31 89.9 [0.05, 0.95] 2021-12-31 2022-01-07 #> 3 ar 2021-12-31 82.6 [0.05, 0.95] 2021-12-31 2022-01-07 #> 4 as 2021-12-31 0 [0.05, 0.95] 2021-12-31 2022-01-07 #> 5 az 2021-12-31 58.3 [0.05, 0.95] 2021-12-31 2022-01-07 #> 6 ca 2021-12-31 84.4 [0.05, 0.95] 2021-12-31 2022-01-07 #> 7 co 2021-12-31 106. [0.05, 0.95] 2021-12-31 2022-01-07 #> 8 ct 2021-12-31 143. [0.05, 0.95] 2021-12-31 2022-01-07 #> 9 dc 2021-12-31 295. [0.05, 0.95] 2021-12-31 2022-01-07 #> 10 de 2021-12-31 150. [0.05, 0.95] 2021-12-31 2022-01-07 #> # ℹ 46 more rows"},{"path":"https://cmu-delphi.github.io/epipredict/articles/preprocessing-and-models.html","id":"introduction","dir":"Articles","previous_headings":"","what":"Introduction","title":"Examples of Preprocessing and Models","text":"epipredict package utilizes tidymodels framework, namely {recipes} dplyr-like pipeable sequences feature engineering {parsnip} unified interface range models. epipredict additional customized feature engineering preprocessing steps, step_epi_lag(), step_population_scaling(), step_epi_naomit(). can used along steps recipes package feature engineering. vignette, illustrate examples use epipredict recipes parsnip different purposes epidemiological forecasting. focus basic autoregressive models, COVID cases deaths near future predicted using linear combination cases deaths near past. remaining vignette split three sections. first section, use Poisson regression predict death counts. second section, use linear regression predict death rates. Last least, create classification model hotspot predictions.","code":"library(tidyr) library(dplyr) library(epidatr) library(epipredict) library(recipes) library(workflows) library(poissonreg)"},{"path":"https://cmu-delphi.github.io/epipredict/articles/preprocessing-and-models.html","id":"poisson-regression","dir":"Articles","previous_headings":"","what":"Poisson Regression","title":"Examples of Preprocessing and Models","text":"COVID-19, US Center Disease Control Prevention (CDC) collected models forecasts characterize state outbreak course. use inform public health decision makers potential consequences deploying control measures. One outcomes CDC forecasts death counts COVID-19. Although many state---art models, choose use Poisson regression, textbook example modeling count data, illustration using epipredict package existing tidymodels packages. counts_subset dataset comes epidatr package, contains number confirmed cases deaths June 4, 2021 Dec 31, 2021 U.S. states. wish predict 7-day ahead death counts lagged cases deaths. Furthermore, let state dummy variable. Using differential intercept coefficients, can allow intercept shift states. \\(\\mu_{t+7} = \\mathbb{E}(y_{t+7})\\), \\(y_{t+7}\\) assumed follow Poisson distribution mean \\(\\mu_{t+7}\\); \\(s_{\\text{state}}\\) dummy variables state take values either 0 1. Preprocessing steps performed prepare data model fitting. diving , helpful understand roles recipes framework.","code":"x <- pub_covidcast( source = \"jhu-csse\", signals = \"confirmed_incidence_num\", time_type = \"day\", geo_type = \"state\", time_values = epirange(20210604, 20211231), geo_values = \"ca,fl,tx,ny,nj\" ) %>% select(geo_value, time_value, cases = value) y <- pub_covidcast( source = \"jhu-csse\", signals = \"deaths_incidence_num\", time_type = \"day\", geo_type = \"state\", time_values = epirange(20210604, 20211231), geo_values = \"ca,fl,tx,ny,nj\" ) %>% select(geo_value, time_value, deaths = value) counts_subset <- full_join(x, y, by = c(\"geo_value\", \"time_value\")) %>% as_epi_df()"},{"path":"https://cmu-delphi.github.io/epipredict/articles/preprocessing-and-models.html","id":"aside-on-recipes","dir":"Articles","previous_headings":"Poisson Regression","what":"Aside on recipes","title":"Examples of Preprocessing and Models","text":"recipes can assign one roles column data. roles restricted predefined set; can anything. conventional situations, typically “predictor” /“outcome”. Additional roles enable targeted step_*() operations specific variables groups variables. case, role predictor given explanatory variables right-hand side model (equation ). role outcome response variable wish predict. geo_value time_value predefined roles unique epipredict package. Since work epi_df objects, datasets geo_value time_value passed automatically two roles assigned appropriate columns data. recipes package also allows manual alterations roles bulk. handy functions can used together help us manipulate variable roles easily. update_role() alters existing role recipe assigns initial role variables yet declared role. add_role() adds additional role variables already role recipe, without overwriting old roles. remove_role() eliminates single existing role recipe.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/articles/preprocessing-and-models.html","id":"end-aside","dir":"Articles","previous_headings":"Poisson Regression","what":"End aside","title":"Examples of Preprocessing and Models","text":"Notice following preprocessing steps, used add_role() geo_value_factor since, currently, default role raw, like reuse variable predictors. specifying preprocessing steps, use parsnip package modeling producing prediction death count, 7 days latest available date dataset. Note time_value corresponds last available date training set, target date forecast (2022-01-07). Let’s take look fit: now, ’ve used Poisson regression model count data. Poisson regression can also used model rate data, case rates death rates, incorporating offset terms model. \\(\\log(\\text{population})\\) log state population used scale count data left-hand side equation. offset simply predictor coefficient fixed 1 rather estimated. several ways model rate data given count population data. First, parsnip framework, specify formula fit(). However, lose ability use recipes framework create new variables since variables exist original dataset (, , lags leads) called directly fit(). Alternatively, step_population_scaling() layer_population_scaling() epipredict package can perform population scaling provide population data, illustrate next section.","code":"counts_subset <- counts_subset %>% mutate(geo_value_factor = as.factor(geo_value)) %>% as_epi_df() epi_recipe(counts_subset) #> #> ── Recipe ────────────────────────────────────────────────────────────────────── #> #> ── Inputs #> Number of variables by role #> raw: 3 #> geo_value: 1 #> time_value: 1 r <- epi_recipe(counts_subset) %>% add_role(geo_value_factor, new_role = \"predictor\") %>% step_dummy(geo_value_factor) %>% ## Occasionally, data reporting errors / corrections result in negative ## cases / deaths step_mutate(cases = pmax(cases, 0), deaths = pmax(deaths, 0)) %>% step_epi_lag(cases, deaths, lag = c(0, 7)) %>% step_epi_ahead(deaths, ahead = 7, role = \"outcome\") %>% step_epi_naomit() latest <- get_test_data(r, counts_subset) wf <- epi_workflow(r, parsnip::poisson_reg()) %>% fit(counts_subset) predict(wf, latest) %>% filter(!is.na(.pred)) #> An `epi_df` object, 5 x 3 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2023-10-04 21:31:33.762729 #> #> # A tibble: 5 × 3 #> geo_value time_value .pred #> * #> 1 ca 2021-12-31 108. #> 2 fl 2021-12-31 270. #> 3 nj 2021-12-31 22.5 #> 4 ny 2021-12-31 94.8 #> 5 tx 2021-12-31 91.0 extract_fit_engine(wf) #> #> Call: stats::glm(formula = ..y ~ ., family = stats::poisson, data = data) #> #> Coefficients: #> (Intercept) geo_value_factor_fl geo_value_factor_nj #> 3.970e+00 -1.487e-01 -1.425e+00 #> geo_value_factor_ny geo_value_factor_tx lag_0_cases #> -6.865e-01 3.025e-01 1.339e-05 #> lag_7_cases lag_0_deaths lag_7_deaths #> 1.717e-06 1.731e-03 8.566e-04 #> #> Degrees of Freedom: 984 Total (i.e. Null); 976 Residual #> Null Deviance: 139600 #> Residual Deviance: 58110 AIC: 62710"},{"path":"https://cmu-delphi.github.io/epipredict/articles/preprocessing-and-models.html","id":"linear-regression","dir":"Articles","previous_headings":"","what":"Linear Regression","title":"Examples of Preprocessing and Models","text":"COVID-19, CDC required submission case death count predictions. However, Delphi Group preferred train rate data instead, puts different locations similar scale (eliminating need location-specific intercepts). can use liner regression predict death rates use state population data scale rates counts.1 using layer_population_scaling() epipredict package. Additionally, forecasts submitted, prediction intervals provided along point estimates. can obtained via postprocessing using layer_residual_quantiles(). worth pointing , however, layer_residual_quantiles() used population scaling else transformation make results uninterpretable. wish, now, predict 7-day ahead death counts lagged case rates death rates, along extra behaviourial predictors. Namely, use survey data COVID-19 Trends Impact Survey. survey data provides estimated percentage people wore mask time public past 7 days estimated percentage respondents reported people encountered public past 7 days maintained distance least 6 feet. State-wise population data 2019 U.S. Census included package used layer_population_scaling(). Rather using raw mask-wearing / social-distancing metrics, sake illustration, ’ll convert categorical predictors. take subset death rate case rate data built-dataset case_death_rate_subset. Preprocessing steps rely functions epipredict package well recipes package. also many functions recipes package allow scalar transformations, log transformations data centering. case, center numerical predictors allow meaningful interpretation intercept. sanity check can examine structure training data: directly predicting results, need add postprocessing layers obtain death counts instead death rates. Note rates used far “per 100K people” rather “per person”. ’ll also use quantile regression quantile_reg engine rather ordinary least squares create median predictions 90% prediction interval. columns marked *_scaled rescaled correct units, case deaths rather deaths per 100K people (remain .pred). look prediction intervals: Last least, let’s take look regression fit check coefficients:","code":"behav_ind_mask <- pub_covidcast( source = \"fb-survey\", signals = \"smoothed_wwearing_mask_7d\", time_type = \"day\", geo_type = \"state\", time_values = epirange(20210604, 20211231), geo_values = \"ca,fl,tx,ny,nj\" ) %>% select(geo_value, time_value, masking = value) behav_ind_distancing <- pub_covidcast( source = \"fb-survey\", signals = \"smoothed_wothers_distanced_public\", time_type = \"day\", geo_type = \"state\", time_values = epirange(20210604, 20211231), geo_values = \"ca,fl,tx,ny,nj\" ) %>% select(geo_value, time_value, distancing = value) pop_dat <- state_census %>% select(abbr, pop) behav_ind <- behav_ind_mask %>% full_join(behav_ind_distancing, by = c(\"geo_value\", \"time_value\")) jhu <- filter( case_death_rate_subset, time_value >= \"2021-06-04\", time_value <= \"2021-12-31\", geo_value %in% c(\"ca\", \"fl\", \"tx\", \"ny\", \"nj\") ) jhu <- jhu %>% mutate(geo_value_factor = as.factor(geo_value)) %>% left_join(behav_ind, by = c(\"geo_value\", \"time_value\")) %>% as_epi_df() r <- epi_recipe(jhu) %>% add_role(geo_value_factor, new_role = \"predictor\") %>% step_dummy(geo_value_factor) %>% step_epi_lag(case_rate, death_rate, lag = c(0, 7, 14)) %>% step_mutate( masking = cut_number(masking, 5), distancing = cut_number(distancing, 5) ) %>% step_epi_ahead(death_rate, ahead = 7, role = \"outcome\") %>% step_center(contains(\"lag\"), role = \"predictor\") %>% step_epi_naomit() glimpse(slice_sample(bake(prep(r, jhu), jhu), n = 6)) #> Rows: 6 #> Columns: 17 #> $ time_value 2021-11-25, 2021-12-13, 2021-08-21, 2021-11-09, 2… #> $ geo_value \"tx\", \"fl\", \"ny\", \"fl\", \"ca\", \"ny\" #> $ case_rate 11.129043, 8.534627, 23.356678, 6.900533, 21.08597… #> $ death_rate 0.2087334, 0.1866785, 0.1145116, 0.4916745, 0.0729… #> $ masking \"(52.8,60.2]\", \"[42.7,52.8]\", \"(52.8,60.2]\", \"(52.… #> $ distancing \"[13.9,18.4]\", \"[13.9,18.4]\", \"(19.8,21.1]\", \"[13.… #> $ geo_value_factor_fl 0, 1, 0, 1, 0, 0 #> $ geo_value_factor_nj 0, 0, 0, 0, 0, 0 #> $ geo_value_factor_ny 0, 0, 1, 0, 0, 1 #> $ geo_value_factor_tx 1, 0, 0, 0, 0, 0 #> $ lag_0_case_rate -15.81261965, -18.40703535, -3.58498415, -20.04112… #> $ lag_7_case_rate -15.771262, -14.087794, -5.969042, -18.954582, -11… #> $ lag_14_case_rate -15.960047, -26.941662, -10.178638, -17.368472, -1… #> $ lag_0_death_rate -0.0731402, -0.0951951, -0.1673620, 0.2098009, -0.… #> $ lag_7_death_rate 0.0874240, -0.1168866, -0.1873092, 0.2025703, -0.2… #> $ lag_14_death_rate 0.0835315, -0.0248620, -0.2168605, 0.2374082, -0.1… #> $ ahead_7_death_rate 0.2082469, 0.1255479, 0.1086014, 0.2813324, 0.1114… f <- frosting() %>% layer_predict() %>% layer_add_target_date(\"2022-01-07\") %>% layer_threshold(.pred, lower = 0) %>% layer_quantile_distn() %>% layer_naomit(.pred) %>% layer_population_scaling( .pred, .pred_distn, df = pop_dat, rate_rescaling = 1e5, by = c(\"geo_value\" = \"abbr\"), df_pop_col = \"pop\" ) wf <- epi_workflow(r, quantile_reg(tau = c(.05, .5, .95))) %>% fit(jhu) %>% add_frosting(f) latest <- get_test_data(recipe = r, x = jhu) p <- predict(wf, latest) p #> An `epi_df` object, 5 x 7 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 5 × 7 #> geo_value time_value .pred target_date .pred_distn #> * #> 1 ca 2021-12-31 [0.05, 0.95] 2022-01-07 [0.25, 0.75] #> 2 fl 2021-12-31 [0.05, 0.95] 2022-01-07 [0.25, 0.75] #> 3 nj 2021-12-31 [0.05, 0.95] 2022-01-07 [0.25, 0.75] #> 4 ny 2021-12-31 [0.05, 0.95] 2022-01-07 [0.25, 0.75] #> 5 tx 2021-12-31 [0.05, 0.95] 2022-01-07 [0.25, 0.75] #> # ℹ 2 more variables: .pred_scaled , .pred_distn_scaled p %>% select(geo_value, target_date, .pred_scaled, .pred_distn_scaled) %>% mutate(.pred_distn_scaled = nested_quantiles(.pred_distn_scaled)) %>% unnest(.pred_distn_scaled) %>% pivot_wider(names_from = tau, values_from = q) #> # A tibble: 5 × 5 #> geo_value target_date .pred_scaled `0.25` `0.75` #> #> 1 ca 2022-01-07 [0.05, 0.95] 48.8 94.0 #> 2 fl 2022-01-07 [0.05, 0.95] 48.4 104. #> 3 nj 2022-01-07 [0.05, 0.95] 45.5 68.7 #> 4 ny 2022-01-07 [0.05, 0.95] 108. 163. #> 5 tx 2022-01-07 [0.05, 0.95] 68.6 107. #> Call: #> quantreg::rq(formula = ..y ~ ., tau = ~c(0.05, 0.5, 0.95), data = data, #> na.action = stats::na.omit, method = \"br\", model = FALSE) #> #> Coefficients: #> tau= 0.05 tau= 0.50 tau= 0.95 #> (Intercept) 0.210811625 0.2962574475 0.417583265 #> geo_value_factor_fl 0.032085820 0.0482361119 0.171126713 #> geo_value_factor_nj 0.007313762 -0.0033797953 -0.025251865 #> geo_value_factor_ny -0.001489163 -0.0199485947 -0.032635584 #> geo_value_factor_tx 0.029077485 0.0391980273 0.071961515 #> lag_0_case_rate -0.001636588 -0.0011625693 -0.001430622 #> lag_7_case_rate 0.004700752 0.0057822095 0.006912655 #> lag_14_case_rate 0.001715816 0.0004224753 0.003448733 #> lag_0_death_rate 0.462341754 0.5274192012 0.164856372 #> lag_7_death_rate -0.007368501 0.1132903956 0.172687438 #> lag_14_death_rate -0.072500707 -0.0270474349 0.181279299 #> #> Degrees of freedom: 950 total; 939 residual"},{"path":"https://cmu-delphi.github.io/epipredict/articles/preprocessing-and-models.html","id":"classification","dir":"Articles","previous_headings":"","what":"Classification","title":"Examples of Preprocessing and Models","text":"Sometimes preferable create predictive model surges upswings rather raw values. case, target predict future increased case rates (denoted ), decreased case rates (), flat case rates (flat) relative current level. models may referred “hotspot prediction models”. follow analysis McDonald, Bien, Green, Hu, et al. extend application predict three categories instead two. Hotspot prediction uses categorical outcome variable defined terms relative change \\(Y_{\\ell, t+}\\) compared \\(Y_{\\ell, t}\\). \\(Y_{\\ell, t}\\) denotes case rates location \\(\\ell\\) time \\(t\\). define response variables follows: \\[ Z_{\\ell, t}= \\begin{cases} \\text{}, & \\text{}\\ Y^{\\Delta}_{\\ell, t} > 0.25 \\\\ \\text{}, & \\text{}\\ Y^{\\Delta}_{\\ell, t} < -0.20\\\\ \\text{flat}, & \\text{otherwise} \\end{cases} \\] \\(Y^{\\Delta}_{\\ell, t} = (Y_{\\ell, t}- Y_{\\ell, t-7})\\ /\\ (Y_{\\ell, t-7})\\). say location \\(\\ell\\) hotspot time \\(t\\) \\(Z_{\\ell,t}\\) , meaning number newly reported cases past 7 days increased least 25% compared preceding week. \\(Z_{\\ell,t}\\) categorized , suggests least 20% decrease newly reported cases past 7 days (20% decrease inverse 25% increase). Otherwise, consider trend flat. expression multinomial regression use follows: \\[ \\pi_{j}(x) = \\text{Pr}(Z_{\\ell,t} = j|x) = \\frac{e^{g_j(x)}}{1 + \\sum_{k=0}^2 g_j(x) } \\] \\(j\\) either , flat, Preprocessing steps similar previous models additional step categorizing response variables. , use subset death rate case rate data built-dataset case_death_rate_subset. fit multinomial regression examine predictions: can also look estimated coefficients model summary information: One also use formula epi_recipe() achieve results . However, one add_formula(), add_recipe(), workflow_variables() can specified. purpose demonstrating add_formula rather add_recipe, prep bake recipe return data.frame used model fitting.","code":"jhu <- case_death_rate_subset %>% dplyr::filter( time_value >= \"2021-06-04\", time_value <= \"2021-12-31\", geo_value %in% c(\"ca\", \"fl\", \"tx\", \"ny\", \"nj\") ) %>% mutate(geo_value_factor = as.factor(geo_value)) %>% as_epi_df() r <- epi_recipe(jhu) %>% add_role(time_value, new_role = \"predictor\") %>% step_dummy(geo_value_factor) %>% step_epi_lag(case_rate, lag = c(0, 7, 14)) %>% step_epi_ahead(case_rate, ahead = 7, role = \"predictor\") %>% step_mutate( pct_diff_ahead = case_when( lag_7_case_rate == 0 ~ 0, TRUE ~ (ahead_7_case_rate - lag_0_case_rate) / lag_0_case_rate ), pct_diff_wk1 = case_when( lag_7_case_rate == 0 ~ 0, TRUE ~ (lag_0_case_rate - lag_7_case_rate) / lag_7_case_rate ), pct_diff_wk2 = case_when( lag_14_case_rate == 0 ~ 0, TRUE ~ (lag_7_case_rate - lag_14_case_rate) / lag_14_case_rate ) ) %>% step_mutate( response = case_when( pct_diff_ahead < -0.20 ~ \"down\", pct_diff_ahead > 0.25 ~ \"up\", TRUE ~ \"flat\" ), role = \"outcome\" ) %>% step_rm( death_rate, case_rate, lag_0_case_rate, lag_7_case_rate, lag_14_case_rate, ahead_7_case_rate, pct_diff_ahead ) %>% step_epi_naomit() wf <- epi_workflow(r, parsnip::multinom_reg()) %>% fit(jhu) latest <- get_test_data(recipe = r, x = jhu) predict(wf, latest) %>% filter(!is.na(.pred_class)) #> An `epi_df` object, 5 x 3 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 5 × 3 #> geo_value time_value .pred_class #> * #> 1 ca 2021-12-31 up #> 2 fl 2021-12-31 up #> 3 nj 2021-12-31 up #> 4 ny 2021-12-31 up #> 5 tx 2021-12-31 flat extract_fit_engine(wf) #> Call: #> nnet::multinom(formula = ..y ~ ., data = data, trace = FALSE) #> #> Coefficients: #> (Intercept) time_value geo_value_factor_fl geo_value_factor_nj #> flat -58.11177 0.003162471 -0.5978151 1.350320 #> up 46.45080 -0.002429847 -0.4682080 1.572085 #> geo_value_factor_ny geo_value_factor_tx pct_diff_wk1 pct_diff_wk2 #> flat 3.113677 -0.3010305 1.263089 3.610543 #> up 3.172692 -0.2505232 2.194646 4.266267 #> #> Residual Deviance: 1529.929 #> AIC: 1561.929 b <- bake(prep(r, jhu), jhu) epi_workflow() %>% add_formula(response ~ geo_value + time_value + pct_diff_wk1 + pct_diff_wk2) %>% add_model(parsnip::multinom_reg()) %>% fit(data = b) #> ══ Workflow [trained] ══════════════════════════════════════════════════════════ #> Preprocessor: Formula #> Model: multinom_reg() #> #> ── Preprocessor ──────────────────────────────────────────────────────────────── #> response ~ geo_value + time_value + pct_diff_wk1 + pct_diff_wk2 #> #> ── Model ─────────────────────────────────────────────────────────────────────── #> Call: #> nnet::multinom(formula = ..y ~ ., data = data, trace = FALSE) #> #> Coefficients: #> (Intercept) geo_valuefl geo_valuenj geo_valueny geo_valuetx time_value #> flat -58.11158 -0.5978159 1.350325 3.113684 -0.3010308 0.003162461 #> up 46.45071 -0.4682087 1.572090 3.172698 -0.2505236 -0.002429839 #> pct_diff_wk1 pct_diff_wk2 #> flat 1.263093 3.610536 #> up 2.194649 4.266259 #> #> Residual Deviance: 1529.929 #> AIC: 1561.929"},{"path":"https://cmu-delphi.github.io/epipredict/articles/preprocessing-and-models.html","id":"benefits-of-lagging-and-leading-in-epipredict","dir":"Articles","previous_headings":"","what":"Benefits of Lagging and Leading in epipredict","title":"Examples of Preprocessing and Models","text":"step_epi_ahead step_epi_lag functions epipredict package handy creating correct lags leads future predictions. Let’s start simple dataset preprocessing: want predict death rates 2022-01-07, 7 days ahead latest available date dataset. compare two methods trying create lags leads: Notice difference number rows b1 b2 returns. second version, one doesn’t use step_epi_ahead step_epi_lag, omitted dates compared one used epipredict functions. model trained based recipes functions predict 7 days ahead 2021-12-24 instead 7 days ahead 2021-12-31.","code":"ex <- filter( case_death_rate_subset, time_value >= \"2021-12-01\", time_value <= \"2021-12-31\", geo_value == \"ca\" ) dim(ex) #> [1] 31 4 p1 <- epi_recipe(ex) %>% step_epi_lag(case_rate, lag = c(0, 7, 14)) %>% step_epi_lag(death_rate, lag = c(0, 7, 14)) %>% step_epi_ahead(death_rate, ahead = 7, role = \"outcome\") %>% step_epi_naomit() %>% prep() #> Warning in max.default(structure(numeric(0), class = \"Date\"), na.rm = FALSE): #> no non-missing arguments to max; returning -Inf b1 <- bake(p1, ex) b1 #> # A tibble: 17 × 11 #> time_value geo_value case_rate death_rate lag_0_case_rate lag_7_case_rate #> #> 1 2021-12-15 ca 15.8 0.157 15.8 18.0 #> 2 2021-12-16 ca 16.3 0.155 16.3 17.4 #> 3 2021-12-17 ca 16.9 0.158 16.9 17.4 #> 4 2021-12-18 ca 17.6 0.164 17.6 17.2 #> 5 2021-12-19 ca 19.1 0.165 19.1 16.3 #> 6 2021-12-20 ca 20.6 0.164 20.6 16.0 #> 7 2021-12-21 ca 22.6 0.165 22.6 16.6 #> 8 2021-12-22 ca 26.2 0.163 26.2 15.8 #> 9 2021-12-23 ca 30.8 0.167 30.8 16.3 #> 10 2021-12-24 ca 33.8 0.167 33.8 16.9 #> 11 2021-12-25 ca 32.6 0.153 32.6 17.6 #> 12 2021-12-26 ca 34.5 0.153 34.5 19.1 #> 13 2021-12-27 ca 48.4 0.132 48.4 20.6 #> 14 2021-12-28 ca 54.9 0.142 54.9 22.6 #> 15 2021-12-29 ca 63.7 0.140 63.7 26.2 #> 16 2021-12-30 ca 76.0 0.140 76.0 30.8 #> 17 2021-12-31 ca 84.4 0.142 84.4 33.8 #> # ℹ 5 more variables: lag_14_case_rate , lag_0_death_rate , #> # lag_7_death_rate , lag_14_death_rate , ahead_7_death_rate p2 <- epi_recipe(ex) %>% step_mutate( lag0case_rate = lag(case_rate, 0), lag7case_rate = lag(case_rate, 7), lag14case_rate = lag(case_rate, 14), lag0death_rate = lag(death_rate, 0), lag7death_rate = lag(death_rate, 7), lag14death_rate = lag(death_rate, 14), ahead7death_rate = lead(death_rate, 7) ) %>% step_epi_naomit() %>% prep() #> Warning in max.default(structure(numeric(0), class = \"Date\"), na.rm = FALSE): #> no non-missing arguments to max; returning -Inf b2 <- bake(p2, ex) b2 #> # A tibble: 10 × 11 #> time_value geo_value case_rate death_rate lag0case_rate lag7case_rate #> #> 1 2021-12-15 ca 15.8 0.157 15.8 18.0 #> 2 2021-12-16 ca 16.3 0.155 16.3 17.4 #> 3 2021-12-17 ca 16.9 0.158 16.9 17.4 #> 4 2021-12-18 ca 17.6 0.164 17.6 17.2 #> 5 2021-12-19 ca 19.1 0.165 19.1 16.3 #> 6 2021-12-20 ca 20.6 0.164 20.6 16.0 #> 7 2021-12-21 ca 22.6 0.165 22.6 16.6 #> 8 2021-12-22 ca 26.2 0.163 26.2 15.8 #> 9 2021-12-23 ca 30.8 0.167 30.8 16.3 #> 10 2021-12-24 ca 33.8 0.167 33.8 16.9 #> # ℹ 5 more variables: lag14case_rate , lag0death_rate , #> # lag7death_rate , lag14death_rate , ahead7death_rate dates_used_in_training1 <- b1 %>% select(-ahead_7_death_rate) %>% na.omit() %>% pull(time_value) dates_used_in_training1 #> [1] \"2021-12-15\" \"2021-12-16\" \"2021-12-17\" \"2021-12-18\" \"2021-12-19\" #> [6] \"2021-12-20\" \"2021-12-21\" \"2021-12-22\" \"2021-12-23\" \"2021-12-24\" #> [11] \"2021-12-25\" \"2021-12-26\" \"2021-12-27\" \"2021-12-28\" \"2021-12-29\" #> [16] \"2021-12-30\" \"2021-12-31\" dates_used_in_training2 <- b2 %>% select(-ahead7death_rate) %>% na.omit() %>% pull(time_value) dates_used_in_training2 #> [1] \"2021-12-15\" \"2021-12-16\" \"2021-12-17\" \"2021-12-18\" \"2021-12-19\" #> [6] \"2021-12-20\" \"2021-12-21\" \"2021-12-22\" \"2021-12-23\" \"2021-12-24\""},{"path":"https://cmu-delphi.github.io/epipredict/articles/preprocessing-and-models.html","id":"references","dir":"Articles","previous_headings":"","what":"References","title":"Examples of Preprocessing and Models","text":"McDonald, Bien, Green, Hu, et al. “Can auxiliary indicators improve COVID-19 forecasting hotspot prediction?.” Proceedings National Academy Sciences 118.51 (2021): e2111453118. doi:10.1073/pnas.2111453118","code":""},{"path":"https://cmu-delphi.github.io/epipredict/articles/preprocessing-and-models.html","id":"attribution","dir":"Articles","previous_headings":"","what":"Attribution","title":"Examples of Preprocessing and Models","text":"object contains modified part COVID-19 Data Repository Center Systems Science Engineering (CSSE) Johns Hopkins University republished COVIDcast Epidata API. data set licensed terms Creative Commons Attribution 4.0 International license Johns Hopkins University behalf Center Systems Science Engineering. Copyright Johns Hopkins University 2020.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/articles/sliding.html","id":"demonstrations-of-sliding-ar-and-arx-forecasters","dir":"Articles","previous_headings":"","what":"Demonstrations of sliding AR and ARX forecasters","title":"Demonstrations of sliding AR and ARX forecasters","text":"key function epiprocess package epi_slide(), allows user apply function formula-based computation variables epi_df running window n time steps (see following epiprocess vignette go basics function: “Slide computation signal values”). equivalent sliding method epi_archive object can called using wrapper function epix_slide() (refer following vignette basics function: “Work archive objects data revisions”). key difference epi_slide() performs version-aware computations. , function uses data available time t reference time. vignette, use epi_slide() epix_slide() backtesting arx_forecaster historical COVID-19 case data US Canada. precisely, first demonstrate using epi_slide() slide ARX forecasters epi_df object compare results obtained using different forecasting engines. compare results version-aware unaware forecasting, former obtained applying epix_slide() epi_archive object, latter obtained applying epi_slide() latest snapshot data.","code":""},{"path":[]},{"path":"https://cmu-delphi.github.io/epipredict/articles/sliding.html","id":"example-using-cli-and-case-data-from-us-states","dir":"Articles","previous_headings":"Demonstrations of sliding AR and ARX forecasters > Comparing different forecasting engines","what":"Example using CLI and case data from US states","title":"Demonstrations of sliding AR and ARX forecasters","text":"First, download version history (ie. archive) percentage doctor’s visits CLI (COVID-like illness) computed medical insurance claims number new confirmed COVID-19 cases per 100,000 population (daily) 50 states COVIDcast API. process , modification use sync = locf epix_merge() last version observation can carried forward extrapolate unavailable versions less --date input archive. obtaining latest snapshot data, produce forecasts data using default engine simple linear regression compare random forest. Note warnings forecast date less recent update date data suppressed avoid cluttering output. , arx_forecaster() heavy lifting. creates leads target (respecting time stamps locations) along lags features (, response doctors visits), estimates forecasting model using specified engine, creates predictions, non-parametric confidence bands. see predictions compare, plot top latest case rates. Note even though ’ve fitted model states, ’ll just display results two states, California (CA) Florida (FL), get sense model performance keeping graphic simple. two states interest, simple linear regression clearly performs better random forest terms accuracy predictions result overconfident predictions (overly narrow confidence bands). Though, general, neither approach produces amazingly accurate forecasts. behaviour rather different across states effects notable factors age public health measures may important account forecasting. Including factors well making enhancements correcting outliers improvements one make simple model.1","code":"theme_set(theme_bw()) y <- readRDS(system.file( \"extdata\", \"all_states_covidcast_signals.rds\", package = \"epipredict\", mustWork = TRUE )) y <- purrr::map(y, ~ select(.x, geo_value, time_value, version = issue, value)) x <- epix_merge( y[[1]] %>% rename(percent_cli = value) %>% as_epi_archive(compactify = FALSE), y[[2]] %>% rename(case_rate = value) %>% as_epi_archive(compactify = FALSE), sync = \"locf\", compactify = TRUE ) rm(y) # Latest snapshot of data, and forecast dates x_latest <- epix_as_of(x, max_version = max(x$versions_end)) fc_time_values <- seq( from = as.Date(\"2020-08-01\"), to = as.Date(\"2021-11-01\"), by = \"1 month\" ) aheads <- c(7, 14, 21, 28) k_week_ahead <- function(epi_df, outcome, predictors, ahead = 7, engine) { epi_slide( epi_df, ~ arx_forecaster( .x, outcome, predictors, engine, args_list = arx_args_list(ahead = ahead) ) %>% extract2(\"predictions\") %>% select(-geo_value), before = 120 - 1, ref_time_values = fc_time_values, new_col_name = \"fc\" ) %>% select(geo_value, time_value, starts_with(\"fc\")) %>% mutate(engine_type = engine$engine) } # Generate the forecasts and bind them together fc <- bind_rows( map( aheads, ~ k_week_ahead( x_latest, \"case_rate\", c(\"case_rate\", \"percent_cli\"), .x, engine = linear_reg() ) ) %>% list_rbind(), map( aheads, ~ k_week_ahead( x_latest, \"case_rate\", c(\"case_rate\", \"percent_cli\"), .x, engine = rand_forest(mode = \"regression\") ) ) %>% list_rbind() ) %>% pivot_quantiles(fc_.pred_distn) fc_cafl <- fc %>% filter(geo_value %in% c(\"ca\", \"fl\")) x_latest_cafl <- x_latest %>% filter(geo_value %in% c(\"ca\", \"fl\")) ggplot(fc_cafl, aes(fc_target_date, group = time_value, fill = engine_type)) + geom_line( data = x_latest_cafl, aes(x = time_value, y = case_rate), inherit.aes = FALSE, color = \"gray50\" ) + geom_ribbon(aes(ymin = `0.05`, ymax = `0.95`), alpha = 0.4) + geom_line(aes(y = fc_.pred)) + geom_point(aes(y = fc_.pred), size = 0.5) + geom_vline(aes(xintercept = time_value), linetype = 2, alpha = 0.5) + facet_grid(vars(geo_value), vars(engine_type), scales = \"free\") + scale_x_date(minor_breaks = \"month\", date_labels = \"%b %y\") + scale_fill_brewer(palette = \"Set1\") + labs(x = \"Date\", y = \"Reported COVID-19 case rates\") + theme(legend.position = \"none\")"},{"path":"https://cmu-delphi.github.io/epipredict/articles/sliding.html","id":"example-using-case-data-from-canada","dir":"Articles","previous_headings":"Demonstrations of sliding AR and ARX forecasters > Comparing different forecasting engines","what":"Example using case data from Canada","title":"Demonstrations of sliding AR and ARX forecasters","text":"leveraging flexibility epiprocess, can apply techniques data sources. Since collaborators British Columbia, Canada, ’ll essentially thing Canada . COVID-19 Canada Open Data Working Group collects daily time series data COVID-19 cases, deaths, recoveries, testing vaccinations health region province levels. Data collected publicly available sources government datasets news releases. Unfortunately, simple versioned source, created Github commit history. First, load versioned case rates provincial level. converting 7-day averages (due highly variable provincial reporting mismatches), convert data epi_archive object, extract latest version . Finally, run forcasting exercise American data, compare forecasts produced using simple linear regression using boosted regression trees. figures shows results provinces. approaches tend produce quite volatile forecasts (point predictions) /overly confident (narrow bands), particularly boosted regression trees used. meant simple demonstration sliding different engines arx_forecaster, may devote another vignette work improving predictive modelling using suite tools available epipredict.","code":"# source(\"drafts/canada-case-rates.R) can <- readRDS(system.file( \"extdata\", \"can_prov_cases.rds\", package = \"epipredict\", mustWork = TRUE )) can <- can %>% group_by(version, geo_value) %>% arrange(time_value) %>% mutate(cr_7dav = RcppRoll::roll_meanr(case_rate, n = 7L)) %>% as_epi_archive(compactify = TRUE) can_latest <- epix_as_of(can, max_version = max(can$DT$version)) # Generate the forecasts, and bind them together can_fc <- bind_rows( map( aheads, ~ k_week_ahead(can_latest, \"cr_7dav\", \"cr_7dav\", .x, linear_reg()) ) %>% list_rbind(), map( aheads, ~ k_week_ahead( can_latest, \"cr_7dav\", \"cr_7dav\", .x, boost_tree(mode = \"regression\", trees = 20) ) ) %>% list_rbind() ) %>% pivot_quantiles(fc_.pred_distn) ggplot( can_fc %>% filter(engine_type == \"lm\"), aes(x = fc_target_date, group = time_value) ) + coord_cartesian(xlim = lubridate::ymd(c(\"2020-12-01\", NA))) + geom_line( data = can_latest, aes(x = time_value, y = cr_7dav), inherit.aes = FALSE, color = \"gray50\" ) + geom_ribbon(aes(ymin = `0.05`, ymax = `0.95`, fill = geo_value), alpha = 0.4 ) + geom_line(aes(y = fc_.pred)) + geom_point(aes(y = fc_.pred), size = 0.5) + geom_vline(aes(xintercept = time_value), linetype = 2, alpha = 0.5) + facet_wrap(~geo_value, scales = \"free_y\", ncol = 3) + scale_x_date(minor_breaks = \"month\", date_labels = \"%b %y\") + labs( title = \"Using simple linear regression\", x = \"Date\", y = \"Reported COVID-19 case rates\" ) + theme(legend.position = \"none\") ggplot( can_fc %>% filter(engine_type == \"xgboost\"), aes(x = fc_target_date, group = time_value) ) + coord_cartesian(xlim = lubridate::ymd(c(\"2020-12-01\", NA))) + geom_line( data = can_latest, aes(x = time_value, y = cr_7dav), inherit.aes = FALSE, color = \"gray50\" ) + geom_ribbon(aes(ymin = `0.05`, ymax = `0.95`, fill = geo_value), alpha = 0.4 ) + geom_line(aes(y = fc_.pred)) + geom_point(aes(y = fc_.pred), size = 0.5) + geom_vline(aes(xintercept = time_value), linetype = 2, alpha = 0.5) + facet_wrap(~geo_value, scales = \"free_y\", ncol = 3) + scale_x_date(minor_breaks = \"month\", date_labels = \"%b %y\") + labs( title = \"Using boosted regression trees\", x = \"Date\", y = \"Reported COVID-19 case rates\" ) + theme(legend.position = \"none\")"},{"path":[]},{"path":"https://cmu-delphi.github.io/epipredict/articles/sliding.html","id":"example-using-case-data-from-us-states","dir":"Articles","previous_headings":"Demonstrations of sliding AR and ARX forecasters > Version-aware and unaware forecasting","what":"Example using case data from US states","title":"Demonstrations of sliding AR and ARX forecasters","text":"now employ forecaster uses properly-versioned data (available real-time) forecast future COVID-19 case rates current past COVID-19 case rates states. , can make forecasts archive, x, compare forecasts latest data, x_latest using general set-. version-aware forecasting, note x fed epix_slide(), version-unaware forecasting, x_latest fed epi_slide(). Now can plot results top latest case rates. , display focus results FL CA simplicity. , observe results great two states, ’s likely due simplicity model (ex. omission key factors age public health measures) quality data (ex. personally corrected anomalies data). shall leave reader try version aware unaware forecasting exercise Canadian case rate data. code American state data readily adaptable purpose.","code":"k_week_version_aware <- function(ahead = 7, version_aware = TRUE) { if (version_aware) { epix_slide( x, ~ arx_forecaster( .x, \"case_rate\", c(\"case_rate\", \"percent_cli\"), args_list = arx_args_list(ahead = ahead) ) %>% extract2(\"predictions\"), before = 120 - 1, ref_time_values = fc_time_values, new_col_name = \"fc\" ) %>% mutate(engine_type = \"lm\", version_aware = version_aware) %>% rename(geo_value = fc_geo_value) } else { k_week_ahead( x_latest, \"case_rate\", c(\"case_rate\", \"percent_cli\"), ahead, linear_reg() ) %>% mutate(version_aware = version_aware) } } # Generate the forecasts, and bind them together fc <- bind_rows( map(aheads, ~ k_week_version_aware(.x, TRUE)) %>% list_rbind(), map(aheads, ~ k_week_version_aware(.x, FALSE)) %>% list_rbind() ) %>% pivot_quantiles(fc_.pred_distn) fc_cafl <- fc %>% filter(geo_value %in% c(\"ca\", \"fl\")) x_latest_cafl <- x_latest %>% filter(geo_value %in% c(\"ca\", \"fl\")) ggplot(fc_cafl, aes(x = fc_target_date, group = time_value, fill = version_aware)) + geom_line( data = x_latest_cafl, aes(x = time_value, y = case_rate), inherit.aes = FALSE, color = \"gray50\" ) + geom_ribbon(aes(ymin = `0.05`, ymax = `0.95`), alpha = 0.4) + geom_line(aes(y = fc_.pred)) + geom_point(aes(y = fc_.pred), size = 0.5) + geom_vline(aes(xintercept = time_value), linetype = 2, alpha = 0.5) + facet_grid(geo_value ~ version_aware, scales = \"free\", labeller = labeller(version_aware = label_both) ) + scale_x_date(minor_breaks = \"month\", date_labels = \"%b %y\") + labs(x = \"Date\", y = \"Reported COVID-19 case rates\") + scale_fill_brewer(palette = \"Set1\") + theme(legend.position = \"none\")"},{"path":"https://cmu-delphi.github.io/epipredict/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Daniel McDonald. Author, maintainer. Ryan Tibshirani. Author. Logan Brooks. Author. Rachel Lobay. Author. Maggie Liu. Author. Ken Mawer. Author. Chloe . Author. Jacob Bien. Contributor.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"McDonald D, Tibshirani R, Brooks L, Lobay R, Liu M, Mawer K, C (2023). epipredict: Basic epidemiology forecasting methods. https://github.com/cmu-delphi/epipredict/, https://cmu-delphi.github.io/epipredict.","code":"@Manual{, title = {epipredict: Basic epidemiology forecasting methods}, author = {Daniel McDonald and Ryan Tibshirani and Logan Brooks and Rachel Lobay and Maggie Liu and Ken Mawer and Chloe You}, year = {2023}, note = {https://github.com/cmu-delphi/epipredict/, https://cmu-delphi.github.io/epipredict}, }"},{"path":"https://cmu-delphi.github.io/epipredict/index.html","id":"epipredict","dir":"","previous_headings":"","what":"Basic epidemiology forecasting methods","title":"Basic epidemiology forecasting methods","text":"Note: package currently development may work expected. Please file bug reports issues repo, best address quickly.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"Basic epidemiology forecasting methods","text":"can install development version epipredict GitHub :","code":"# install.packages(\"remotes\") remotes::install_github(\"cmu-delphi/epipredict\")"},{"path":"https://cmu-delphi.github.io/epipredict/index.html","id":"documentation","dir":"","previous_headings":"","what":"Documentation","title":"Basic epidemiology forecasting methods","text":"can view documentation main branch https://cmu-delphi.github.io/epipredict.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/index.html","id":"goals-for-epipredict","dir":"","previous_headings":"","what":"Goals for epipredict","title":"Basic epidemiology forecasting methods","text":"hope provide: Baseline flat-line forecaster Autoregressive forecaster Autoregressive classifier Preprocessor: things data model training Trainer: train model data, resulting fitted model object Predictor: make predictions, using fitted model object Postprocessor: things predictions returning Target audiences: Basic. data, calls forecaster default arguments. Intermediate. Wants examine changes arguments, take advantage built flexibility. Advanced. Wants write forecasters. Maybe willing build components write. Advanced user find task relatively easy. Examples tasks illustrated vignettes articles.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/index.html","id":"intermediate-example","dir":"","previous_headings":"","what":"Intermediate example","title":"Basic epidemiology forecasting methods","text":"package comes built-historical data illustration, --date versions downloaded {covidcast} package processed using {epiprocess}.1 create train simple auto-regressive forecaster predict death rate two weeks future using past (lagged) deaths cases, use following function. case, used number different lags case rate, using 3 weekly lags death rate (predictors). result fitted model object used time future create different forecasts, well set predicted values (prediction intervals) location 14 days last available time value data. fitted model involved preprocessing data appropriately generate lagged predictors, estimating linear model stats::lm() postprocessing results meaningful epidemiological tasks. can also examine predictions. results show distributional forecast produced using data end 2021 14th January 2022. prediction death rate per 100K inhabitants available every state (geo_value) along 90% predictive interval.","code":"library(tidyverse) library(epipredict) jhu <- case_death_rate_subset jhu #> An `epi_df` object, 20,496 x 4 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 12:08:25.791826 #> #> # A tibble: 20,496 × 4 #> geo_value time_value case_rate death_rate #> * #> 1 ak 2020-12-31 35.9 0.158 #> 2 al 2020-12-31 65.1 0.438 #> 3 ar 2020-12-31 66.0 1.27 #> 4 as 2020-12-31 0 0 #> 5 az 2020-12-31 76.8 1.10 #> 6 ca 2020-12-31 96.0 0.751 #> 7 co 2020-12-31 35.8 0.649 #> 8 ct 2020-12-31 52.1 0.819 #> 9 dc 2020-12-31 31.0 0.601 #> 10 de 2020-12-31 65.2 0.807 #> # ℹ 20,486 more rows two_week_ahead <- arx_forecaster( jhu, outcome = \"death_rate\", predictors = c(\"case_rate\", \"death_rate\"), args_list = arx_args_list( lags = list(c(0,1,2,3,7,14), c(0,7,14)), ahead = 14 ) ) two_week_ahead$epi_workflow #> ══ Epi Workflow [trained] ══════════════════════════════════════════════════════ #> Preprocessor: Recipe #> Model: linear_reg() #> Postprocessor: Frosting #> #> ── Preprocessor ──────────────────────────────────────────────────────────────── #> 6 Recipe Steps #> #> • step_epi_lag() #> • step_epi_lag() #> • step_epi_ahead() #> • step_naomit() #> • step_naomit() #> • step_training_window() #> #> ── Model ─────────────────────────────────────────────────────────────────────── #> #> Call: #> stats::lm(formula = ..y ~ ., data = data) #> #> Coefficients: #> (Intercept) lag_0_case_rate lag_1_case_rate lag_2_case_rate #> -0.0073358 0.0030365 0.0012467 0.0009536 #> lag_3_case_rate lag_7_case_rate lag_14_case_rate lag_0_death_rate #> 0.0011425 0.0012481 0.0003041 0.1351769 #> lag_7_death_rate lag_14_death_rate #> 0.1471127 0.1062473 #> #> ── Postprocessor ─────────────────────────────────────────────────────────────── #> 5 Frosting Layers #> #> • layer_predict() #> • layer_residual_quantiles() #> • layer_add_forecast_date() #> • layer_add_target_date() #> • layer_threshold() two_week_ahead$predictions #> # A tibble: 56 × 5 #> geo_value .pred .pred_distn forecast_date target_date #> #> 1 ak 0.449 [0.05, 0.95] 2021-12-31 2022-01-14 #> 2 al 0.574 [0.05, 0.95] 2021-12-31 2022-01-14 #> 3 ar 0.673 [0.05, 0.95] 2021-12-31 2022-01-14 #> 4 as 0 [0.05, 0.95] 2021-12-31 2022-01-14 #> 5 az 0.679 [0.05, 0.95] 2021-12-31 2022-01-14 #> 6 ca 0.575 [0.05, 0.95] 2021-12-31 2022-01-14 #> 7 co 0.862 [0.05, 0.95] 2021-12-31 2022-01-14 #> 8 ct 1.07 [0.05, 0.95] 2021-12-31 2022-01-14 #> 9 dc 2.12 [0.05, 0.95] 2021-12-31 2022-01-14 #> 10 de 1.09 [0.05, 0.95] 2021-12-31 2022-01-14 #> # ℹ 46 more rows"},{"path":"https://cmu-delphi.github.io/epipredict/reference/add_epi_recipe.html","id":null,"dir":"Reference","previous_headings":"","what":"Add an epi_recipe to a workflow — add_epi_recipe","title":"Add an epi_recipe to a workflow — add_epi_recipe","text":"Add epi_recipe workflow","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/add_epi_recipe.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Add an epi_recipe to a workflow — add_epi_recipe","text":"","code":"add_epi_recipe(x, recipe, ..., blueprint = default_epi_recipe_blueprint())"},{"path":"https://cmu-delphi.github.io/epipredict/reference/add_epi_recipe.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Add an epi_recipe to a workflow — add_epi_recipe","text":"x workflow epi_workflow recipe recipe created using recipes::recipe() ... used. blueprint hardhat blueprint used fine tuning preprocessing. default_epi_recipe_blueprint() used. Note preprocessing done separate preprocessing might done automatically underlying model.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/add_epi_recipe.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Add an epi_recipe to a workflow — add_epi_recipe","text":"x, updated new recipe preprocessor.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/add_epi_recipe.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Add an epi_recipe to a workflow — add_epi_recipe","text":"behaviour workflows::add_recipe() sets different default blueprint automatically handle epiprocess::epi_df data.","code":""},{"path":[]},{"path":"https://cmu-delphi.github.io/epipredict/reference/add_epi_recipe.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Add an epi_recipe to a workflow — add_epi_recipe","text":"","code":"library(epiprocess) library(dplyr) #> #> Attaching package: ‘dplyr’ #> The following objects are masked from ‘package:stats’: #> #> filter, lag #> The following objects are masked from ‘package:base’: #> #> intersect, setdiff, setequal, union library(recipes) #> #> Attaching package: ‘recipes’ #> The following object is masked from ‘package:stats’: #> #> step jhu <- case_death_rate_subset %>% filter(time_value > \"2021-08-01\") %>% dplyr::arrange(geo_value, time_value) r <- epi_recipe(jhu) %>% step_epi_lag(death_rate, lag = c(0, 7, 14)) %>% step_epi_ahead(death_rate, ahead = 7) %>% step_epi_lag(case_rate, lag = c(0, 7, 14)) %>% step_naomit(all_predictors()) %>% step_naomit(all_outcomes(), skip = TRUE) workflow <- epi_workflow() %>% add_epi_recipe(r) workflow #> ══ Epi Workflow ════════════════════════════════════════════════════════════════ #> Preprocessor: Recipe #> Model: None #> Postprocessor: None #> #> ── Preprocessor ──────────────────────────────────────────────────────────────── #> 5 Recipe Steps #> #> • step_epi_lag() #> • step_epi_ahead() #> • step_epi_lag() #> • step_naomit() #> • step_naomit()"},{"path":"https://cmu-delphi.github.io/epipredict/reference/add_frosting.html","id":null,"dir":"Reference","previous_headings":"","what":"Add frosting to a workflow — add_frosting","title":"Add frosting to a workflow — add_frosting","text":"Add frosting workflow","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/add_frosting.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Add frosting to a workflow — add_frosting","text":"","code":"add_frosting(x, frosting, ...) remove_frosting(x)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/add_frosting.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Add frosting to a workflow — add_frosting","text":"x workflow frosting frosting layer created using frosting() ... used.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/add_frosting.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Add frosting to a workflow — add_frosting","text":"x, updated new removed frosting postprocessor","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/add_frosting.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Add frosting to a workflow — add_frosting","text":"","code":"jhu <- case_death_rate_subset %>% filter(time_value > \"2021-11-01\", geo_value %in% c(\"ak\", \"ca\", \"ny\")) r <- epi_recipe(jhu) %>% step_epi_lag(death_rate, lag = c(0, 7, 14)) %>% step_epi_ahead(death_rate, ahead = 7) %>% step_epi_naomit() wf <- epi_workflow(r, parsnip::linear_reg()) %>% fit(jhu) latest <- jhu %>% dplyr::filter(time_value >= max(time_value) - 14) # Add frosting to a workflow and predict f <- frosting() %>% layer_predict() %>% layer_naomit(.pred) wf1 <- wf %>% add_frosting(f) p1 <- predict(wf1, latest) p1 #> An `epi_df` object, 3 x 3 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 3 × 3 #> geo_value time_value .pred #> * #> 1 ak 2021-12-31 0.245 #> 2 ca 2021-12-31 0.313 #> 3 ny 2021-12-31 0.295 # Remove frosting from the workflow and predict wf2 <- wf1 %>% remove_frosting() p2 <- predict(wf2, latest) p2 #> An `epi_df` object, 3 x 3 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 3 × 3 #> geo_value time_value .pred #> * #> 1 ak 2021-12-31 0.245 #> 2 ca 2021-12-31 0.313 #> 3 ny 2021-12-31 0.295"},{"path":"https://cmu-delphi.github.io/epipredict/reference/add_layer.html","id":null,"dir":"Reference","previous_headings":"","what":"Add layer to a frosting object — add_layer","title":"Add layer to a frosting object — add_layer","text":"Add layer frosting object","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/add_layer.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Add layer to a frosting object — add_layer","text":"","code":"add_layer(frosting, object)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/add_layer.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Add layer to a frosting object — add_layer","text":"frosting frosting postprocessor object frosting layer","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/add_layer.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Add layer to a frosting object — add_layer","text":"updated frosting postprocessor","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/apply_frosting.html","id":null,"dir":"Reference","previous_headings":"","what":"Apply postprocessing to a fitted workflow — apply_frosting","title":"Apply postprocessing to a fitted workflow — apply_frosting","text":"function intended internal use. implements postprocessing inside predict() method fitted workflow.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/apply_frosting.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Apply postprocessing to a fitted workflow — apply_frosting","text":"","code":"apply_frosting(workflow, ...) # S3 method for default apply_frosting(workflow, components, ...) # S3 method for epi_workflow apply_frosting(workflow, components, new_data, ...)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/apply_frosting.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Apply postprocessing to a fitted workflow — apply_frosting","text":"workflow object class workflow ... additional arguments passed methods components list components containing model information. updated returned layer. mold - output calling hardhat::mold() workflow. contains information preprocessing, including recipe. forged - output calling hardhat::forge() workflow. predictors outcomes new_data. three components predictors, outcomes (new_data), extras (usually rest data, including keys). keys - put keys (time_value, geo_value, others) ease. new_data data frame containing new predictors preprocess predict ","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_args_list.html","id":null,"dir":"Reference","previous_headings":"","what":"ARX forecaster argument constructor — arx_args_list","title":"ARX forecaster argument constructor — arx_args_list","text":"Constructs list arguments arx_forecaster().","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_args_list.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"ARX forecaster argument constructor — arx_args_list","text":"","code":"arx_args_list( lags = c(0L, 7L, 14L), ahead = 7L, n_training = Inf, forecast_date = NULL, target_date = NULL, levels = c(0.05, 0.95), symmetrize = TRUE, nonneg = TRUE, quantile_by_key = character(0L), nafill_buffer = Inf )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_args_list.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"ARX forecaster argument constructor — arx_args_list","text":"lags Vector List. Positive integers enumerating lags use autoregressive-type models (days). default, unnamed list lags set correspond order predictors. ahead Integer. Number time steps ahead (days) forecast date forecasts produced. n_training Integer. upper limit number rows per key used training (time unit epi_df). forecast_date Date. date forecast created. default NULL attempt determine automatically. target_date Date. date forecast intended. default NULL attempt determine automatically. levels Vector NULL. vector probabilities produce prediction intervals. created computing quantiles training residuals. NULL value result point forecasts . symmetrize Logical. default TRUE calculates symmetric prediction intervals. argument applies residual quantiles used. applicable trainer = quantile_reg(), example. nonneg Logical. default TRUE enforces nonnegative predictions hard-thresholding 0. quantile_by_key Character vector. Groups residuals listed keys calculating residual quantiles. See by_key argument layer_residual_quantiles() information. default, character(0) performs grouping. argument applies residual quantiles used. applicable trainer = quantile_reg(), example. nafill_buffer predict time, recent values training data used create forecast. However, can NA due , e.g., data latency issues. default, missing values get filled less recent data. Setting value NULL result 1 extra recent row (beyond required lag creation) used. Note require least min(lags) rows recent data per geo_value create prediction. reason, setting nafill_buffer < min(lags) treated additional allowed recent data rather total amount recent data examine.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_args_list.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"ARX forecaster argument constructor — arx_args_list","text":"list containing updated parameter choices class arx_flist.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_args_list.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"ARX forecaster argument constructor — arx_args_list","text":"","code":"arx_args_list() #> List of 11 #> $ lags : int [1:3] 0 7 14 #> $ ahead : int 7 #> $ n_training : num Inf #> $ levels : num [1:2] 0.05 0.95 #> $ forecast_date : NULL #> $ target_date : NULL #> $ symmetrize : logi TRUE #> $ nonneg : logi TRUE #> $ max_lags : int 14 #> $ quantile_by_key: chr(0) #> $ nafill_buffer : num Inf #> - attr(*, \"class\")= chr [1:2] \"arx_fcast\" \"alist\" arx_args_list(symmetrize = FALSE) #> List of 11 #> $ lags : int [1:3] 0 7 14 #> $ ahead : int 7 #> $ n_training : num Inf #> $ levels : num [1:2] 0.05 0.95 #> $ forecast_date : NULL #> $ target_date : NULL #> $ symmetrize : logi FALSE #> $ nonneg : logi TRUE #> $ max_lags : int 14 #> $ quantile_by_key: chr(0) #> $ nafill_buffer : num Inf #> - attr(*, \"class\")= chr [1:2] \"arx_fcast\" \"alist\" arx_args_list(levels = c(.1, .3, .7, .9), n_training = 120) #> List of 11 #> $ lags : int [1:3] 0 7 14 #> $ ahead : int 7 #> $ n_training : num 120 #> $ levels : num [1:4] 0.1 0.3 0.7 0.9 #> $ forecast_date : NULL #> $ target_date : NULL #> $ symmetrize : logi TRUE #> $ nonneg : logi TRUE #> $ max_lags : int 14 #> $ quantile_by_key: chr(0) #> $ nafill_buffer : num Inf #> - attr(*, \"class\")= chr [1:2] \"arx_fcast\" \"alist\""},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_class_args_list.html","id":null,"dir":"Reference","previous_headings":"","what":"ARX classifier argument constructor — arx_class_args_list","title":"ARX classifier argument constructor — arx_class_args_list","text":"Constructs list arguments arx_classifier().","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_class_args_list.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"ARX classifier argument constructor — arx_class_args_list","text":"","code":"arx_class_args_list( lags = c(0L, 7L, 14L), ahead = 7L, n_training = Inf, forecast_date = NULL, target_date = NULL, outcome_transform = c(\"growth_rate\", \"lag_difference\"), breaks = 0.25, horizon = 7L, method = c(\"rel_change\", \"linear_reg\", \"smooth_spline\", \"trend_filter\"), log_scale = FALSE, additional_gr_args = list(), nafill_buffer = Inf )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_class_args_list.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"ARX classifier argument constructor — arx_class_args_list","text":"lags Vector List. Positive integers enumerating lags use autoregressive-type models (days). default, unnamed list lags set correspond order predictors. ahead Integer. Number time steps ahead (days) forecast date forecasts produced. n_training Integer. upper limit number rows per key used training (time unit epi_df). forecast_date Date. date forecast created. default NULL attempt determine automatically. target_date Date. date forecast intended. default NULL attempt determine automatically. outcome_transform Scalar character. Whether outcome created using growth rates (predictors ) lagged differences. second case closer requirements 2022-23 CDC Flusight Hospitalization Experimental Target. See Classification Vignette details create reasonable baseline case. Selecting \"growth_rate\" (default) uses epiprocess::growth_rate() create outcome using additional arguments . Choosing \"lag_difference\" instead simply uses change value selected horizon. breaks Vector. vector breaks turn real-valued growth rates discrete classes. default gives binary upswing classification McDonald, Bien, Green, Hu, et al.. coincides default trainer = parsnip::logistic_reg() argument arx_classifier(). However, multiclass classification also supported (e.g. breaks = c(-.2, .25)) provided trainer = parsnip::multinom_reg() (another multiclass trainer) used well. sliently expanded cover entire real line (default become breaks = c(-Inf, .25, Inf)) used discretize response. different behaviour recipes::step_cut() creates classes cover range training data. horizon Scalar integer. passed h argument epiprocess::growth_rate(). determines amount data used calculate growth rate. method Character. Options available growth rate calculation. log_scale Scalar logical. Whether compute growth rates log scale. additional_gr_args List. Optional arguments controlling growth rate calculation. See epiprocess::growth_rate() related Vignette details. nafill_buffer predict time, recent values training data used create forecast. However, can NA due , e.g., data latency issues. default, missing values get filled less recent data. Setting value NULL result 1 extra recent row (beyond required lag creation) used. Note require least min(lags) rows recent data per geo_value create prediction. reason, setting nafill_buffer < min(lags) treated additional allowed recent data rather total amount recent data examine.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_class_args_list.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"ARX classifier argument constructor — arx_class_args_list","text":"list containing updated parameter choices class arx_clist.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_class_args_list.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"ARX classifier argument constructor — arx_class_args_list","text":"","code":"arx_class_args_list() #> List of 13 #> $ lags : int [1:3] 0 7 14 #> $ ahead : int 7 #> $ n_training : num Inf #> $ breaks : num [1:3] -Inf 0.25 Inf #> $ forecast_date : NULL #> $ target_date : NULL #> $ outcome_transform : chr \"growth_rate\" #> $ max_lags : int 14 #> $ horizon : int 7 #> $ method : chr \"rel_change\" #> $ log_scale : logi FALSE #> $ additional_gr_args: list() #> $ nafill_buffer : num Inf #> - attr(*, \"class\")= chr [1:2] \"arx_class\" \"alist\" # 3-class classsification, # also needs arx_classifier(trainer = parsnip::multinom_reg()) arx_class_args_list(breaks = c(-.2, .25)) #> List of 13 #> $ lags : int [1:3] 0 7 14 #> $ ahead : int 7 #> $ n_training : num Inf #> $ breaks : num [1:4] -Inf -0.2 0.25 Inf #> $ forecast_date : NULL #> $ target_date : NULL #> $ outcome_transform : chr \"growth_rate\" #> $ max_lags : int 14 #> $ horizon : int 7 #> $ method : chr \"rel_change\" #> $ log_scale : logi FALSE #> $ additional_gr_args: list() #> $ nafill_buffer : num Inf #> - attr(*, \"class\")= chr [1:2] \"arx_class\" \"alist\""},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_class_epi_workflow.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a template arx_classifier workflow — arx_class_epi_workflow","title":"Create a template arx_classifier workflow — arx_class_epi_workflow","text":"function creates unfit workflow use arx_classifier(). useful want make small modifications classifier fitting predicting. Supplying trainer function may alter returned epi_workflow object can omitted.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_class_epi_workflow.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a template arx_classifier workflow — arx_class_epi_workflow","text":"","code":"arx_class_epi_workflow( epi_data, outcome, predictors, trainer = NULL, args_list = arx_class_args_list() )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_class_epi_workflow.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a template arx_classifier workflow — arx_class_epi_workflow","text":"epi_data epi_df object outcome character (scalar) specifying outcome (epi_df). Note arx_forecaster(), expected real-valued. Conversion data unordered classes handled internally based breaks argument arx_class_args_list(). discrete classes already epi_df, recommended code classifier scratch using epi_recipe(). predictors character vector giving column(s) predictor variables. trainer {parsnip} model describing type estimation. now, enforce mode = \"classification\". Typical values parsnip::logistic_reg() parsnip::multinom_reg(). complicated trainers like parsnip::naive_Bayes() parsnip::rand_forest() can also used. May NULL (default). args_list list customization arguments determine type forecasting model. See arx_class_args_list().","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_class_epi_workflow.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a template arx_classifier workflow — arx_class_epi_workflow","text":"unfit epi_workflow.","code":""},{"path":[]},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_class_epi_workflow.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create a template arx_classifier workflow — arx_class_epi_workflow","text":"","code":"jhu <- case_death_rate_subset %>% dplyr::filter(time_value >= as.Date(\"2021-11-01\")) arx_class_epi_workflow(jhu, \"death_rate\", c(\"case_rate\", \"death_rate\")) #> ══ Epi Workflow ════════════════════════════════════════════════════════════════ #> Preprocessor: Recipe #> Model: None #> Postprocessor: Frosting #> #> ── Preprocessor ──────────────────────────────────────────────────────────────── #> 8 Recipe Steps #> #> • step_growth_rate() #> • step_epi_lag() #> • step_epi_lag() #> • step_epi_ahead() #> • step_mutate() #> • step_naomit() #> • step_naomit() #> • step_training_window() #> ── Postprocessor ─────────────────────────────────────────────────────────────── #> 3 Frosting Layers #> #> • layer_predict() #> • layer_add_forecast_date() #> • layer_add_target_date() arx_class_epi_workflow( jhu, \"death_rate\", c(\"case_rate\", \"death_rate\"), trainer = parsnip::multinom_reg(), args_list = arx_class_args_list( breaks = c(-.05, .1), ahead = 14, horizon = 14, method = \"linear_reg\" ) ) #> ══ Epi Workflow ════════════════════════════════════════════════════════════════ #> Preprocessor: Recipe #> Model: multinom_reg() #> Postprocessor: Frosting #> #> ── Preprocessor ──────────────────────────────────────────────────────────────── #> 8 Recipe Steps #> #> • step_growth_rate() #> • step_epi_lag() #> • step_epi_lag() #> • step_epi_ahead() #> • step_mutate() #> • step_naomit() #> • step_naomit() #> • step_training_window() #> #> ── Model ─────────────────────────────────────────────────────────────────────── #> Multinomial Regression Model Specification (classification) #> #> Computational engine: nnet #> #> ── Postprocessor ─────────────────────────────────────────────────────────────── #> 3 Frosting Layers #> #> • layer_predict() #> • layer_add_forecast_date() #> • layer_add_target_date()"},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_classifier.html","id":null,"dir":"Reference","previous_headings":"","what":"Direct autoregressive classifier with covariates — arx_classifier","title":"Direct autoregressive classifier with covariates — arx_classifier","text":"autoregressive classification model epiprocess::epi_df data. \"direct\" forecasting, meaning estimates class particular target horizon.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_classifier.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Direct autoregressive classifier with covariates — arx_classifier","text":"","code":"arx_classifier( epi_data, outcome, predictors, trainer = parsnip::logistic_reg(), args_list = arx_class_args_list() )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_classifier.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Direct autoregressive classifier with covariates — arx_classifier","text":"epi_data epi_df object outcome character (scalar) specifying outcome (epi_df). Note arx_forecaster(), expected real-valued. Conversion data unordered classes handled internally based breaks argument arx_class_args_list(). discrete classes already epi_df, recommended code classifier scratch using epi_recipe(). predictors character vector giving column(s) predictor variables. trainer {parsnip} model describing type estimation. now, enforce mode = \"classification\". Typical values parsnip::logistic_reg() parsnip::multinom_reg(). complicated trainers like parsnip::naive_Bayes() parsnip::rand_forest() can also used. args_list list customization arguments determine type forecasting model. See arx_class_args_list().","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_classifier.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Direct autoregressive classifier with covariates — arx_classifier","text":"list (1) predictions epi_df predicted classes (2) epi_workflow, list encapsulates entire estimation workflow","code":""},{"path":[]},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_classifier.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Direct autoregressive classifier with covariates — arx_classifier","text":"","code":"jhu <- case_death_rate_subset %>% dplyr::filter(time_value >= as.Date(\"2021-11-01\")) out <- arx_classifier(jhu, \"death_rate\", c(\"case_rate\", \"death_rate\")) #> Warning: The forecast_date is less than the most recent update date of the data: forecast_date = 2021-12-31 while data is from 2022-05-31. out <- arx_classifier( jhu, \"death_rate\", c(\"case_rate\", \"death_rate\"), trainer = parsnip::multinom_reg(), args_list = arx_class_args_list( breaks = c(-.05, .1), ahead = 14, horizon = 14, method = \"linear_reg\" ) ) #> Warning: The forecast_date is less than the most recent update date of the data: forecast_date = 2021-12-31 while data is from 2022-05-31."},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_fcast_epi_workflow.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a template arx_forecaster workflow — arx_fcast_epi_workflow","title":"Create a template arx_forecaster workflow — arx_fcast_epi_workflow","text":"function creates unfit workflow use arx_forecaster(). useful want make small modifications forecaster fitting predicting. Supplying trainer function may alter returned epi_workflow object (e.g., intend use quantile_reg()) can omitted.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_fcast_epi_workflow.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a template arx_forecaster workflow — arx_fcast_epi_workflow","text":"","code":"arx_fcast_epi_workflow( epi_data, outcome, predictors, trainer = NULL, args_list = arx_args_list() )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_fcast_epi_workflow.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a template arx_forecaster workflow — arx_fcast_epi_workflow","text":"epi_data epi_df object outcome character (scalar) specifying outcome (epi_df). predictors character vector giving column(s) predictor variables. trainer {parsnip} model describing type estimation. now, enforce mode = \"regression\". May NULL (default). args_list list customization arguments determine type forecasting model. See arx_args_list().","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_fcast_epi_workflow.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a template arx_forecaster workflow — arx_fcast_epi_workflow","text":"unfitted epi_workflow.","code":""},{"path":[]},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_fcast_epi_workflow.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create a template arx_forecaster workflow — arx_fcast_epi_workflow","text":"","code":"jhu <- case_death_rate_subset %>% dplyr::filter(time_value >= as.Date(\"2021-12-01\")) arx_fcast_epi_workflow(jhu, \"death_rate\", c(\"case_rate\", \"death_rate\")) #> ══ Epi Workflow ════════════════════════════════════════════════════════════════ #> Preprocessor: Recipe #> Model: None #> Postprocessor: Frosting #> #> ── Preprocessor ──────────────────────────────────────────────────────────────── #> 6 Recipe Steps #> #> • step_epi_lag() #> • step_epi_lag() #> • step_epi_ahead() #> • step_naomit() #> • step_naomit() #> • step_training_window() #> ── Postprocessor ─────────────────────────────────────────────────────────────── #> 5 Frosting Layers #> #> • layer_predict() #> • layer_residual_quantiles() #> • layer_add_forecast_date() #> • layer_add_target_date() #> • layer_threshold() arx_fcast_epi_workflow(jhu, \"death_rate\", c(\"case_rate\", \"death_rate\"), trainer = quantile_reg(), args_list = arx_args_list(levels = 1:9 / 10)) #> ══ Epi Workflow ════════════════════════════════════════════════════════════════ #> Preprocessor: Recipe #> Model: quantile_reg() #> Postprocessor: Frosting #> #> ── Preprocessor ──────────────────────────────────────────────────────────────── #> 6 Recipe Steps #> #> • step_epi_lag() #> • step_epi_lag() #> • step_epi_ahead() #> • step_naomit() #> • step_naomit() #> • step_training_window() #> #> ── Model ─────────────────────────────────────────────────────────────────────── #> quantile reg Model Specification (regression) #> #> Main Arguments: #> tau = c(0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9) #> #> Computational engine: rq #> #> ── Postprocessor ─────────────────────────────────────────────────────────────── #> 6 Frosting Layers #> #> • layer_predict() #> • layer_quantile_distn() #> • layer_point_from_distn() #> • layer_add_forecast_date() #> • layer_add_target_date() #> • layer_threshold()"},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_forecaster.html","id":null,"dir":"Reference","previous_headings":"","what":"Direct autoregressive forecaster with covariates — arx_forecaster","title":"Direct autoregressive forecaster with covariates — arx_forecaster","text":"autoregressive forecasting model epiprocess::epi_df data. \"direct\" forecasting, meaning estimates model particular target horizon.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_forecaster.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Direct autoregressive forecaster with covariates — arx_forecaster","text":"","code":"arx_forecaster( epi_data, outcome, predictors, trainer = parsnip::linear_reg(), args_list = arx_args_list() )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_forecaster.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Direct autoregressive forecaster with covariates — arx_forecaster","text":"epi_data epi_df object outcome character (scalar) specifying outcome (epi_df). predictors character vector giving column(s) predictor variables. trainer {parsnip} model describing type estimation. now, enforce mode = \"regression\". args_list list customization arguments determine type forecasting model. See arx_args_list().","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_forecaster.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Direct autoregressive forecaster with covariates — arx_forecaster","text":"list (1) predictions epi_df predicted values (2) epi_workflow, list encapsulates entire estimation workflow","code":""},{"path":[]},{"path":"https://cmu-delphi.github.io/epipredict/reference/arx_forecaster.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Direct autoregressive forecaster with covariates — arx_forecaster","text":"","code":"jhu <- case_death_rate_subset %>% dplyr::filter(time_value >= as.Date(\"2021-12-01\")) out <- arx_forecaster(jhu, \"death_rate\", c(\"case_rate\", \"death_rate\")) #> Warning: The forecast_date is less than the most recent update date of the data: forecast_date = 2021-12-31 while data is from 2022-05-31. out <- arx_forecaster(jhu, \"death_rate\", c(\"case_rate\", \"death_rate\"), trainer = quantile_reg(), args_list = arx_args_list(levels = 1:9 / 10)) #> Warning: The forecast_date is less than the most recent update date of the data: forecast_date = 2021-12-31 while data is from 2022-05-31."},{"path":"https://cmu-delphi.github.io/epipredict/reference/augment.epi_workflow.html","id":null,"dir":"Reference","previous_headings":"","what":"Augment data with predictions — augment.epi_workflow","title":"Augment data with predictions — augment.epi_workflow","text":"Augment data predictions","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/augment.epi_workflow.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Augment data with predictions — augment.epi_workflow","text":"","code":"# S3 method for epi_workflow augment(x, new_data, ...)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/augment.epi_workflow.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Augment data with predictions — augment.epi_workflow","text":"x trained epi_workflow new_data epi_df predictors ... Arguments passed predict method.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/augment.epi_workflow.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Augment data with predictions — augment.epi_workflow","text":"new_data additional columns containing predicted values","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/bake.html","id":null,"dir":"Reference","previous_headings":"","what":"Bake an epi_recipe — bake.epi_recipe","title":"Bake an epi_recipe — bake.epi_recipe","text":"Bake epi_recipe","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/bake.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Bake an epi_recipe — bake.epi_recipe","text":"","code":"# S3 method for epi_recipe bake(object, new_data, ...)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/bake.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Bake an epi_recipe — bake.epi_recipe","text":"object trained object recipe() least one preprocessing operation. new_data epi_df, data frame tibble preprocessing applied. NULL given new_data, pre-processed training data returned. ... One selector functions choose variables returned function. See recipes::selections() details. selectors given, default use tidyselect::everything().","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/bake.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Bake an epi_recipe — bake.epi_recipe","text":"epi_df may different columns original columns new_data.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/case_death_rate_subset.html","id":null,"dir":"Reference","previous_headings":"","what":"Subset of JHU daily state cases and deaths — case_death_rate_subset","title":"Subset of JHU daily state cases and deaths — case_death_rate_subset","text":"data source confirmed COVID-19 cases deaths based reports made available Center Systems Science Engineering Johns Hopkins University. example data ranges Dec 31, 2020 Dec 31, 2021, includes states.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/case_death_rate_subset.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Subset of JHU daily state cases and deaths — case_death_rate_subset","text":"","code":"case_death_rate_subset"},{"path":"https://cmu-delphi.github.io/epipredict/reference/case_death_rate_subset.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Subset of JHU daily state cases and deaths — case_death_rate_subset","text":"tibble 20,496 rows 4 variables: geo_value geographic value associated row measurements. time_value time value associated row measurements. case_rate 7-day average signal number new confirmed COVID-19 cases per 100,000 population, daily death_rate 7-day average signal number new confirmed deaths due COVID-19 per 100,000 population, daily","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/case_death_rate_subset.html","id":"source","dir":"Reference","previous_headings":"","what":"Source","title":"Subset of JHU daily state cases and deaths — case_death_rate_subset","text":"object contains modified part COVID-19 Data Repository Center Systems Science Engineering (CSSE) Johns Hopkins University republished COVIDcast Epidata API. data set licensed terms Creative Commons Attribution 4.0 International license Johns Hopkins University behalf Center Systems Science Engineering. Copyright Johns Hopkins University 2020. Modifications: COVIDcast Epidata API: signals taken directly JHU CSSE COVID-19 GitHub repository without changes. 7-day average signals computed Delphi calculating moving averages preceding 7 days, signal June 7 average underlying data June 1 7, inclusive.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/check_pname.html","id":null,"dir":"Reference","previous_headings":"","what":"Check that newly created variable names don't overlap — check_pname","title":"Check that newly created variable names don't overlap — check_pname","text":"check_pname used slather method ensure newly created variable names overlap existing names. Throws warning check fails, creates random string.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/check_pname.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Check that newly created variable names don't overlap — check_pname","text":"","code":"check_pname(res, preds, object, newname = NULL)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/check_pname.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Check that newly created variable names don't overlap — check_pname","text":"res data frame tibble newly created variables. preds epi_df tibble containing predictions. object layer object passed slather(). newname string variable names object contain $name element","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/create_layer.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a new layer — create_layer","title":"Create a new layer — create_layer","text":"function creates skeleton new frosting layer. called inside package, create R script R/ directory, fill name layer, open file.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/create_layer.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a new layer — create_layer","text":"","code":"create_layer(name = NULL, open = rlang::is_interactive())"},{"path":"https://cmu-delphi.github.io/epipredict/reference/create_layer.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a new layer — create_layer","text":"name Either string giving file name (without directory) NULL take name currently open file RStudio. open Whether open file interactive editing.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/create_layer.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create a new layer — create_layer","text":"","code":"if (FALSE) { # Note: running this will write `layer_strawberry.R` to # the `R/` directory of your current project create_layer(\"strawberry\") }"},{"path":"https://cmu-delphi.github.io/epipredict/reference/dist_quantiles.html","id":null,"dir":"Reference","previous_headings":"","what":"A distribution parameterized by a set of quantiles — dist_quantiles","title":"A distribution parameterized by a set of quantiles — dist_quantiles","text":"distribution parameterized set quantiles","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/dist_quantiles.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"A distribution parameterized by a set of quantiles — dist_quantiles","text":"","code":"dist_quantiles(x, tau)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/dist_quantiles.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"A distribution parameterized by a set of quantiles — dist_quantiles","text":"x vector values tau vector probabilities corresponding x","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/dist_quantiles.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"A distribution parameterized by a set of quantiles — dist_quantiles","text":"","code":"dstn <- dist_quantiles(list(1:4, 8:11), list(c(.2,.4,.6,.8))) quantile(dstn, p = c(.1, .25, .5, .9)) #> [[1]] #> [1] 0.124961 1.250000 2.500000 4.875039 #> #> [[2]] #> [1] 7.124961 8.250000 9.500000 11.875039 #> median(dstn) #> [1] 2.5 9.5 # it's a bit annoying to inspect the data vctrs::vec_data(vctrs::vec_data(dstn[1])[[1]]) #> q tau #> 1 1 0.2 #> 2 2 0.4 #> 3 3 0.6 #> 4 4 0.8"},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_juice.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract transformed training set — epi_juice","title":"Extract transformed training set — epi_juice","text":"Extract transformed training set","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_juice.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract transformed training set — epi_juice","text":"","code":"epi_juice(object, ...)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_juice.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Extract transformed training set — epi_juice","text":"object trained object recipe() least one preprocessing operation. ... One selector functions choose variables returned function. See recipes::selections() details. selectors given, default use tidyselect::everything().","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_keys.html","id":null,"dir":"Reference","previous_headings":"","what":"Grab any keys associated to an epi_df — epi_keys","title":"Grab any keys associated to an epi_df — epi_keys","text":"Grab keys associated epi_df","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_keys.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Grab any keys associated to an epi_df — epi_keys","text":"","code":"epi_keys(x, ...)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_keys.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Grab any keys associated to an epi_df — epi_keys","text":"x data.frame, tibble, epi_df ... additional arguments passed methods","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_keys.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Grab any keys associated to an epi_df — epi_keys","text":"epi_df, returns \"keys\". Otherwise NULL","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_recipe.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a epi_recipe for preprocessing data — epi_recipe","title":"Create a epi_recipe for preprocessing data — epi_recipe","text":"recipe description steps applied data set order prepare data analysis. loose wrapper around recipes::recipe() properly handle additional columns present epi_df","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_recipe.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a epi_recipe for preprocessing data — epi_recipe","text":"","code":"epi_recipe(x, ...) # S3 method for default epi_recipe(x, ...) # S3 method for epi_df epi_recipe(x, formula = NULL, ..., vars = NULL, roles = NULL) # S3 method for formula epi_recipe(formula, data, ...)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_recipe.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a epi_recipe for preprocessing data — epi_recipe","text":"x, data data frame, tibble, epi_df template data set (see ). always coerced first row avoid memory issues ... arguments passed methods (currently used). formula model formula. -line functions used (e.g. log(x), x:y, etc.) minus signs allowed. types transformations enacted using step functions package. Dots allowed simple multivariate outcome terms (.e. need cbind; see Examples). vars character string column names corresponding variables used context (see ) roles character string (length vars) describes single role variable take. value anything common roles \"outcome\", \"predictor\", \"time_value\", \"geo_value\"","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_recipe.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a epi_recipe for preprocessing data — epi_recipe","text":"object class recipe sub-objects: var_info tibble containing information original data set columns term_info tibble contains current set terms data set. initially defaults data contained var_info. steps list step check objects define sequence preprocessing operations applied data. default value NULL template tibble data. initialized data given data argument can different recipe trained.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_recipe.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create a epi_recipe for preprocessing data — epi_recipe","text":"","code":"library(epiprocess) library(dplyr) library(recipes) jhu <- case_death_rate_subset %>% dplyr::filter(time_value > \"2021-08-01\") %>% dplyr::arrange(geo_value, time_value) r <- epi_recipe(jhu) %>% step_epi_lag(death_rate, lag = c(0, 7, 14)) %>% step_epi_ahead(death_rate, ahead = 7) %>% step_epi_lag(case_rate, lag = c(0, 7, 14)) %>% step_naomit(all_predictors()) %>% # below, `skip` means we don't do this at predict time step_naomit(all_outcomes(), skip = TRUE) r #> #> ── Recipe ────────────────────────────────────────────────────────────────────── #> #> ── Inputs #> Number of variables by role #> raw: 2 #> geo_value: 1 #> time_value: 1 #> #> ── Operations #> • Lagging: death_rate by 0, 7, 14 #> • Leading: death_rate by 7 #> • Lagging: case_rate by 0, 7, 14 #> • Removing rows with NA values in: all_predictors() #> • Removing rows with NA values in: all_outcomes()"},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_shift.html","id":null,"dir":"Reference","previous_headings":"","what":"Shift predictors while maintaining grouping and time_value ordering — epi_shift","title":"Shift predictors while maintaining grouping and time_value ordering — epi_shift","text":"lower-level function. performs error checking.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_shift.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Shift predictors while maintaining grouping and time_value ordering — epi_shift","text":"","code":"epi_shift(x, shifts, time_value, keys = NULL, out_name = \"x\")"},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_shift.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Shift predictors while maintaining grouping and time_value ordering — epi_shift","text":"x Data frame. Variables shift shifts List. list element vector shifts. Negative values produce leads. list length number columns x. time_value Vector. length x giving time stamps. keys Data frame, vector, NULL. Additional grouping vars. out_name Chr. output list use prefix.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_shift.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Shift predictors while maintaining grouping and time_value ordering — epi_shift","text":"list tibbles","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_workflow.html","id":null,"dir":"Reference","previous_headings":"","what":"Create an epi_workflow — epi_workflow","title":"Create an epi_workflow — epi_workflow","text":"container object unifies preprocessing, fitting, prediction, postprocessing predictive modeling epidemiological data. extends functionality workflows::workflow() handle typical panel data structures found field. extension handled completely internally, invisible user. intents purposes, operates exactly like workflows::workflow(). details numerous examples, see .","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_workflow.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create an epi_workflow — epi_workflow","text":"","code":"epi_workflow(preprocessor = NULL, spec = NULL, postprocessor = NULL)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_workflow.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create an epi_workflow — epi_workflow","text":"preprocessor optional preprocessor add workflow. One : formula, passed add_formula(). recipe, passed add_recipe(). workflow_variables() object, passed add_variables(). spec optional parsnip model specification add workflow. Passed add_model(). postprocessor optional postprocessor add workflow. Currently frosting allowed using, add_frosting().","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_workflow.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create an epi_workflow — epi_workflow","text":"new epi_workflow object.","code":""},{"path":[]},{"path":"https://cmu-delphi.github.io/epipredict/reference/epi_workflow.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create an epi_workflow — epi_workflow","text":"","code":"jhu <- case_death_rate_subset r <- epi_recipe(jhu) %>% step_epi_lag(death_rate, lag = c(0, 7, 14)) %>% step_epi_ahead(death_rate, ahead = 7) %>% step_epi_lag(case_rate, lag = c(0, 7, 14)) %>% step_epi_naomit() wf <- epi_workflow(r, parsnip::linear_reg()) wf #> ══ Epi Workflow ════════════════════════════════════════════════════════════════ #> Preprocessor: Recipe #> Model: linear_reg() #> Postprocessor: None #> #> ── Preprocessor ──────────────────────────────────────────────────────────────── #> 5 Recipe Steps #> #> • step_epi_lag() #> • step_epi_ahead() #> • step_epi_lag() #> • step_naomit() #> • step_naomit() #> #> ── Model ─────────────────────────────────────────────────────────────────────── #> Linear Regression Model Specification (regression) #> #> Computational engine: lm #>"},{"path":"https://cmu-delphi.github.io/epipredict/reference/extract_argument.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract an argument made to a frosting layer or recipe step — extract_argument","title":"Extract an argument made to a frosting layer or recipe step — extract_argument","text":"Extract argument made frosting layer recipe step","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/extract_argument.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract an argument made to a frosting layer or recipe step — extract_argument","text":"","code":"extract_argument(x, name, arg, ...)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/extract_argument.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Extract an argument made to a frosting layer or recipe step — extract_argument","text":"x epi_workflow, epi_recipe, frosting, step, layer object name name layer arg name argument ... used","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/extract_argument.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Extract an argument made to a frosting layer or recipe step — extract_argument","text":"object originally passed argument layer step","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/extract_argument.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Extract an argument made to a frosting layer or recipe step — extract_argument","text":"","code":"f <- frosting() %>% layer_predict() %>% layer_residual_quantiles(probs = c(0.0275, 0.975), symmetrize = FALSE) %>% layer_naomit(.pred) extract_argument(f, \"layer_residual_quantiles\", \"symmetrize\") #> [1] FALSE"},{"path":"https://cmu-delphi.github.io/epipredict/reference/extract_frosting.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract the frosting object from a workflow — extract_frosting","title":"Extract the frosting object from a workflow — extract_frosting","text":"Extract frosting object workflow","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/extract_frosting.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract the frosting object from a workflow — extract_frosting","text":"","code":"extract_frosting(x, ...)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/extract_frosting.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Extract the frosting object from a workflow — extract_frosting","text":"x epi_workflow object ... used","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/extract_frosting.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Extract the frosting object from a workflow — extract_frosting","text":"frosting object","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/extrapolate_quantiles.html","id":null,"dir":"Reference","previous_headings":"","what":"Summarize a distribution with a set of quantiles — extrapolate_quantiles","title":"Summarize a distribution with a set of quantiles — extrapolate_quantiles","text":"Summarize distribution set quantiles","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/extrapolate_quantiles.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Summarize a distribution with a set of quantiles — extrapolate_quantiles","text":"","code":"extrapolate_quantiles(x, p, ...)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/extrapolate_quantiles.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Summarize a distribution with a set of quantiles — extrapolate_quantiles","text":"x distribution vector p vector probabilities calculate quantiles ... additional arguments passed quantile method","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/extrapolate_quantiles.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Summarize a distribution with a set of quantiles — extrapolate_quantiles","text":"distribution vector containing dist_quantiles","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/extrapolate_quantiles.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Summarize a distribution with a set of quantiles — extrapolate_quantiles","text":"","code":"library(distributional) dstn <- dist_normal(c(10, 2), c(5, 10)) extrapolate_quantiles(dstn, p = c(.25, 0.5, .75)) #> #> [1] [0.25, 0.75] [0.25, 0.75] dstn <- dist_quantiles(list(1:4, 8:11), list(c(.2,.4,.6,.8))) # because this distribution is already quantiles, any extra quantiles are # appended extrapolate_quantiles(dstn, p = c(.25, 0.5, .75)) #> #> [1] [0.2, 0.8] [0.2, 0.8] dstn <- c(dist_normal(c(10, 2), c(5, 10)), dist_quantiles(list(1:4, 8:11), list(c(.2,.4,.6,.8)))) extrapolate_quantiles(dstn, p = c(.25, 0.5, .75)) #> #> [1] [0.25, 0.75] [0.25, 0.75] [0.2, 0.8] #> [4] [0.2, 0.8]"},{"path":"https://cmu-delphi.github.io/epipredict/reference/fit-epi_workflow.html","id":null,"dir":"Reference","previous_headings":"","what":"Fit an epi_workflow object — fit-epi_workflow","title":"Fit an epi_workflow object — fit-epi_workflow","text":"fit() method epi_workflow object estimates parameters given model set data. Fitting epi_workflow involves two main steps, preprocessing data fitting underlying parsnip model.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/fit-epi_workflow.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Fit an epi_workflow object — fit-epi_workflow","text":"","code":"# S3 method for epi_workflow fit(object, data, ..., control = workflows::control_workflow())"},{"path":"https://cmu-delphi.github.io/epipredict/reference/fit-epi_workflow.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Fit an epi_workflow object — fit-epi_workflow","text":"object epi_workflow object data epi_df predictors outcomes use fitting epi_workflow ... used control workflows::control_workflow() object","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/fit-epi_workflow.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Fit an epi_workflow object — fit-epi_workflow","text":"epi_workflow object, updated fit parsnip model object$fit$fit slot.","code":""},{"path":[]},{"path":"https://cmu-delphi.github.io/epipredict/reference/fit-epi_workflow.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Fit an epi_workflow object — fit-epi_workflow","text":"","code":"jhu <- case_death_rate_subset %>% filter(time_value > \"2021-11-01\", geo_value %in% c(\"ak\", \"ca\", \"ny\")) r <- epi_recipe(jhu) %>% step_epi_lag(death_rate, lag = c(0, 7, 14)) %>% step_epi_ahead(death_rate, ahead = 7) wf <- epi_workflow(r, parsnip::linear_reg()) %>% fit(jhu) wf #> ══ Epi Workflow [trained] ══════════════════════════════════════════════════════ #> Preprocessor: Recipe #> Model: linear_reg() #> Postprocessor: None #> #> ── Preprocessor ──────────────────────────────────────────────────────────────── #> 2 Recipe Steps #> #> • step_epi_lag() #> • step_epi_ahead() #> #> ── Model ─────────────────────────────────────────────────────────────────────── #> #> Call: #> stats::lm(formula = ..y ~ ., data = data) #> #> Coefficients: #> (Intercept) lag_0_death_rate lag_7_death_rate lag_14_death_rate #> 0.32848 -0.01957 -0.02176 -0.05895 #>"},{"path":"https://cmu-delphi.github.io/epipredict/reference/flatline.html","id":null,"dir":"Reference","previous_headings":"","what":"(Internal) implementation of the flatline forecaster — flatline","title":"(Internal) implementation of the flatline forecaster — flatline","text":"internal function used create parsnip::linear_reg() model. somewhat odd behaviour (see ).","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/flatline.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"(Internal) implementation of the flatline forecaster — flatline","text":"","code":"flatline(formula, data)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/flatline.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"(Internal) implementation of the flatline forecaster — flatline","text":"formula lhs single variable. standard usage, actually observed time series shifted forward forecast horizon. right hand side must contain keys (locations) panel data separated plus. observed time series must come last. example Note function shifting, done outside. data data frame containing least variables used formula. must also contain column time_value giving observed time points.","code":"form <- as.formula(lead7_y ~ state + age + y)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/flatline.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"(Internal) implementation of the flatline forecaster — flatline","text":"S3 object class flatline two components: residuals - tibble keys .resid column contains forecast errors. .pred - tibble keys .pred column containing predictions future data (last observed outcome combination keys.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/flatline.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"(Internal) implementation of the flatline forecaster — flatline","text":"","code":"tib <- data.frame(y = runif(100), expand.grid(k = letters[1:4], j = letters[5:9], time_value = 1:5)) %>% dplyr::group_by(k, j) %>% dplyr::mutate(y2 = dplyr::lead(y, 2)) # predict 2 steps ahead flat <- flatline(y2 ~ j + k + y, tib) # predictions for 20 locations sum(!is.na(flat$residuals$.resid)) # 100 residuals, but 40 are NA #> [1] 60"},{"path":"https://cmu-delphi.github.io/epipredict/reference/flatline_args_list.html","id":null,"dir":"Reference","previous_headings":"","what":"Flatline forecaster argument constructor — flatline_args_list","title":"Flatline forecaster argument constructor — flatline_args_list","text":"Constructs list arguments flatline_forecaster().","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/flatline_args_list.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Flatline forecaster argument constructor — flatline_args_list","text":"","code":"flatline_args_list( ahead = 7L, n_training = Inf, forecast_date = NULL, target_date = NULL, levels = c(0.05, 0.95), symmetrize = TRUE, nonneg = TRUE, quantile_by_key = character(0L), nafill_buffer = Inf )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/flatline_args_list.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Flatline forecaster argument constructor — flatline_args_list","text":"ahead Integer. Number time steps ahead (days) forecast date forecasts produced. n_training Integer. upper limit number rows per key used training (time unit epi_df). forecast_date Date. date forecast created. default NULL attempt determine automatically. target_date Date. date forecast intended. default NULL attempt determine automatically. levels Vector NULL. vector probabilities produce prediction intervals. created computing quantiles training residuals. NULL value result point forecasts . symmetrize Logical. default TRUE calculates symmetric prediction intervals. argument applies residual quantiles used. applicable trainer = quantile_reg(), example. nonneg Logical. default TRUE enforces nonnegative predictions hard-thresholding 0. quantile_by_key Character vector. Groups residuals listed keys calculating residual quantiles. See by_key argument layer_residual_quantiles() information. default, character(0) performs grouping. argument applies residual quantiles used. applicable trainer = quantile_reg(), example. nafill_buffer predict time, recent values training data used create forecast. However, can NA due , e.g., data latency issues. default, missing values get filled less recent data. Setting value NULL result 1 extra recent row (beyond required lag creation) used. Note require least min(lags) rows recent data per geo_value create prediction. reason, setting nafill_buffer < min(lags) treated additional allowed recent data rather total amount recent data examine.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/flatline_args_list.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Flatline forecaster argument constructor — flatline_args_list","text":"list containing updated parameter choices class flatline_alist.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/flatline_args_list.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Flatline forecaster argument constructor — flatline_args_list","text":"","code":"flatline_args_list() #> List of 9 #> $ ahead : int 7 #> $ n_training : num Inf #> $ forecast_date : NULL #> $ target_date : NULL #> $ levels : num [1:2] 0.05 0.95 #> $ symmetrize : logi TRUE #> $ nonneg : logi TRUE #> $ quantile_by_key: chr(0) #> $ nafill_buffer : num Inf #> - attr(*, \"class\")= chr [1:2] \"flat_fcast\" \"alist\" flatline_args_list(symmetrize = FALSE) #> List of 9 #> $ ahead : int 7 #> $ n_training : num Inf #> $ forecast_date : NULL #> $ target_date : NULL #> $ levels : num [1:2] 0.05 0.95 #> $ symmetrize : logi FALSE #> $ nonneg : logi TRUE #> $ quantile_by_key: chr(0) #> $ nafill_buffer : num Inf #> - attr(*, \"class\")= chr [1:2] \"flat_fcast\" \"alist\" flatline_args_list(levels = c(.1, .3, .7, .9), n_training = 120) #> List of 9 #> $ ahead : int 7 #> $ n_training : num 120 #> $ forecast_date : NULL #> $ target_date : NULL #> $ levels : num [1:4] 0.1 0.3 0.7 0.9 #> $ symmetrize : logi TRUE #> $ nonneg : logi TRUE #> $ quantile_by_key: chr(0) #> $ nafill_buffer : num Inf #> - attr(*, \"class\")= chr [1:2] \"flat_fcast\" \"alist\""},{"path":"https://cmu-delphi.github.io/epipredict/reference/flatline_forecaster.html","id":null,"dir":"Reference","previous_headings":"","what":"Predict the future with today's value — flatline_forecaster","title":"Predict the future with today's value — flatline_forecaster","text":"simple forecasting model epiprocess::epi_df data. uses recent observation forcast future date, produces intervals based quantiles residuals \"flatline\" forecast available training data.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/flatline_forecaster.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Predict the future with today's value — flatline_forecaster","text":"","code":"flatline_forecaster(epi_data, outcome, args_list = flatline_args_list())"},{"path":"https://cmu-delphi.github.io/epipredict/reference/flatline_forecaster.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Predict the future with today's value — flatline_forecaster","text":"epi_data epiprocess::epi_df outcome scalar character column name wish predict. args_list list dditional arguments created flatline_args_list() constructor function.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/flatline_forecaster.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Predict the future with today's value — flatline_forecaster","text":"data frame point (optionally interval) forecasts single ahead (unique horizon) unique combination key_vars.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/flatline_forecaster.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Predict the future with today's value — flatline_forecaster","text":"default, predictive intervals computed separately combination key values (geo_value + additional keys) epi_data argument. forecaster similar used COVID19ForecastHub","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/flatline_forecaster.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Predict the future with today's value — flatline_forecaster","text":"","code":"jhu <- case_death_rate_subset %>% dplyr::filter(time_value >= as.Date(\"2021-12-01\")) out <- flatline_forecaster(jhu, \"death_rate\")"},{"path":"https://cmu-delphi.github.io/epipredict/reference/frosting.html","id":null,"dir":"Reference","previous_headings":"","what":"Create frosting for postprocessing predictions — frosting","title":"Create frosting for postprocessing predictions — frosting","text":"generates postprocessing container (much like recipes::recipe()) hold steps postprocessing predictions.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/frosting.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create frosting for postprocessing predictions — frosting","text":"","code":"frosting(layers = NULL, requirements = NULL)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/frosting.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create frosting for postprocessing predictions — frosting","text":"layers Must NULL. requirements Must NULL.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/frosting.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create frosting for postprocessing predictions — frosting","text":"frosting object.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/frosting.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Create frosting for postprocessing predictions — frosting","text":"arguments currently placeholders must NULL","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/frosting.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create frosting for postprocessing predictions — frosting","text":"","code":"# Toy example to show that frosting can be created and added for postprocessing f <- frosting() wf <- epi_workflow() %>% add_frosting(f) # A more realistic example jhu <- case_death_rate_subset %>% dplyr::filter(time_value > \"2021-11-01\", geo_value %in% c(\"ak\", \"ca\", \"ny\")) r <- epi_recipe(jhu) %>% step_epi_lag(death_rate, lag = c(0, 7, 14)) %>% step_epi_ahead(death_rate, ahead = 7) %>% step_epi_naomit() wf <- epi_workflow(r, parsnip::linear_reg()) %>% fit(jhu) latest <- get_test_data(recipe = r, x = jhu) f <- frosting() %>% layer_predict() %>% layer_naomit(.pred) wf1 <- wf %>% add_frosting(f) p <- predict(wf1, latest) p #> An `epi_df` object, 3 x 3 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 3 × 3 #> geo_value time_value .pred #> * #> 1 ak 2021-12-31 0.245 #> 2 ca 2021-12-31 0.313 #> 3 ny 2021-12-31 0.295"},{"path":"https://cmu-delphi.github.io/epipredict/reference/get_test_data.html","id":null,"dir":"Reference","previous_headings":"","what":"Get test data for prediction based on longest lag period — get_test_data","title":"Get test data for prediction based on longest lag period — get_test_data","text":"Based longest lag period recipe, get_test_data() creates epi_df columns geo_value, time_value variables original dataset, used create features necessary produce forecasts.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/get_test_data.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Get test data for prediction based on longest lag period — get_test_data","text":"","code":"get_test_data( recipe, x, fill_locf = FALSE, n_recent = NULL, forecast_date = max(x$time_value) )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/get_test_data.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Get test data for prediction based on longest lag period — get_test_data","text":"recipe recipe object. x epi_df. typical usage pass data used fitting recipe. fill_locf Logical. use locf fill missing data? n_recent Integer NULL. filling missing data locf = TRUE, far back willing tolerate missing data? Larger values allow filling. default NULL determine recipe. example, suppose n_recent = 3, 3 recent observations geo_value NA’s, won’t able fill anything, error message thrown. (See details.) forecast_date default, set maximum time_value x. data latency recent NA's filled, may last available time_value.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/get_test_data.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Get test data for prediction based on longest lag period — get_test_data","text":"object type x columns geo_value, time_value, additional keys, well variables original dataset.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/get_test_data.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Get test data for prediction based on longest lag period — get_test_data","text":"minimum required (recent) data produce forecast equal maximum lag requested (predictor) plus longest horizon used growth rate calculations requested recipe. calculated internally. also optionally fills missing values using last-observation-carried-forward (LOCF) method. possible (say NA's location), produce error suggesting alternative options handle missing values advanced techniques.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/get_test_data.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Get test data for prediction based on longest lag period — get_test_data","text":"","code":"# create recipe rec <- epi_recipe(case_death_rate_subset) %>% step_epi_ahead(death_rate, ahead = 7) %>% step_epi_lag(death_rate, lag = c(0, 7, 14)) %>% step_epi_lag(case_rate, lag = c(0, 7, 14)) get_test_data(recipe = rec, x = case_death_rate_subset) #> An `epi_df` object, 840 x 4 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 840 × 4 #> geo_value time_value case_rate death_rate #> * #> 1 ak 2021-12-17 23.1 1.19 #> 2 al 2021-12-17 15.6 0.290 #> 3 ar 2021-12-17 23.4 0.467 #> 4 as 2021-12-17 0 0 #> 5 az 2021-12-17 41.2 1.04 #> 6 ca 2021-12-17 16.9 0.158 #> 7 co 2021-12-17 30.5 0.578 #> 8 ct 2021-12-17 64.8 0.120 #> 9 dc 2021-12-17 50.4 0.140 #> 10 de 2021-12-17 67.9 0.333 #> # ℹ 830 more rows"},{"path":"https://cmu-delphi.github.io/epipredict/reference/grab_names.html","id":null,"dir":"Reference","previous_headings":"","what":"Get the names from a data frame via tidy select — grab_names","title":"Get the names from a data frame via tidy select — grab_names","text":"Given data.frame, use syntax choose variables. Return names variables","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/grab_names.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Get the names from a data frame via tidy select — grab_names","text":"","code":"grab_names(dat, ...)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/grab_names.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Get the names from a data frame via tidy select — grab_names","text":"dat data.frame ... One unquoted expressions separated commas. Variable names can used positions data frame, expressions like x:y can used select range variables.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/grab_names.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Get the names from a data frame via tidy select — grab_names","text":"character vector","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/grab_names.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Get the names from a data frame via tidy select — grab_names","text":"internal function, checks performed.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/grab_names.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Get the names from a data frame via tidy select — grab_names","text":"","code":"df <- data.frame(a = 1, b = 2, cc = rep(NA, 3)) grab_names(df, dplyr::starts_with(\"c\")) #> [1] \"cc\""},{"path":"https://cmu-delphi.github.io/epipredict/reference/is_epi_recipe.html","id":null,"dir":"Reference","previous_headings":"","what":"Test for epi_recipe — is_epi_recipe","title":"Test for epi_recipe — is_epi_recipe","text":"Test epi_recipe","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/is_epi_recipe.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Test for epi_recipe — is_epi_recipe","text":"","code":"is_epi_recipe(x)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/is_epi_recipe.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Test for epi_recipe — is_epi_recipe","text":"x object.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/is_epi_recipe.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Test for epi_recipe — is_epi_recipe","text":"TRUE object inherits epi_recipe.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/is_epi_workflow.html","id":null,"dir":"Reference","previous_headings":"","what":"Test for an epi_workflow — is_epi_workflow","title":"Test for an epi_workflow — is_epi_workflow","text":"Test epi_workflow","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/is_epi_workflow.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Test for an epi_workflow — is_epi_workflow","text":"","code":"is_epi_workflow(x)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/is_epi_workflow.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Test for an epi_workflow — is_epi_workflow","text":"x object.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/is_epi_workflow.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Test for an epi_workflow — is_epi_workflow","text":"TRUE object inherits epi_workflow.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer-processors.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract, validate, or detect layers of frosting — extract_layers","title":"Extract, validate, or detect layers of frosting — extract_layers","text":"functions mainly internal. can access validate different layers frosting.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer-processors.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract, validate, or detect layers of frosting — extract_layers","text":"","code":"extract_layers(x, ...) # S3 method for frosting extract_layers(x, ...) # S3 method for workflow extract_layers(x, ...) is_layer(x) validate_layer(x, ..., arg = \"`x`\", call = caller_env()) detect_layer(x, name, ...) # S3 method for frosting detect_layer(x, name, ...) # S3 method for workflow detect_layer(x, name, ...)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer-processors.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Extract, validate, or detect layers of frosting — extract_layers","text":"x epi_workflow, frosting, layer object ... additional arguments possible future methods arg name input (error reporting) call environment (error reporting) name layer name detect","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer-processors.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Extract, validate, or detect layers of frosting — extract_layers","text":"logical validators/detectors list layers extractors","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer-processors.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Extract, validate, or detect layers of frosting — extract_layers","text":"","code":"f <- frosting() %>% layer_predict() wf <- epi_workflow(postprocessor = f) is_layer(layer(\"what_the_what\")) #> [1] TRUE detect_layer(f, \"layer_predict\") #> [1] TRUE detect_layer(wf, \"layer_predict\") #> [1] TRUE extract_layers(f) #> [[1]] #> • Creating predictions: \"\" #> extract_layers(wf) #> [[1]] #> • Creating predictions: \"\" #>"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer.html","id":null,"dir":"Reference","previous_headings":"","what":"layer sets the class of the layer — layer","title":"layer sets the class of the layer — layer","text":"layer sets class layer","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"layer sets the class of the layer — layer","text":"","code":"layer(subclass, ..., .prefix = \"layer_\")"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"layer sets the class of the layer — layer","text":"subclass character string resulting class. example, subclass = \"blah\" layer object returned class layer_blah. ... arguments operator returned. .prefix Prefix subclass created.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"layer sets the class of the layer — layer","text":"updated layer new class","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_add_forecast_date.html","id":null,"dir":"Reference","previous_headings":"","what":"Postprocessing step to add the forecast date — layer_add_forecast_date","title":"Postprocessing step to add the forecast date — layer_add_forecast_date","text":"Postprocessing step add forecast date","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_add_forecast_date.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Postprocessing step to add the forecast date — layer_add_forecast_date","text":"","code":"layer_add_forecast_date( frosting, forecast_date = NULL, id = rand_id(\"add_forecast_date\") )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_add_forecast_date.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Postprocessing step to add the forecast date — layer_add_forecast_date","text":"frosting frosting postprocessor forecast_date forecast date add column epi_df. cases, specified form \"yyyy-mm-dd\". Note forecast date left unspecified, set maximum time value data used pre-processing, fitting model, postprocessing. id random id string","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_add_forecast_date.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Postprocessing step to add the forecast date — layer_add_forecast_date","text":"updated frosting postprocessor","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_add_forecast_date.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Postprocessing step to add the forecast date — layer_add_forecast_date","text":"use function, either specify forecast date leave forecast date unspecifed . latter case, forecast date set maximum time value data used pre-processing, fitting model, postprocessing. case, forecast date less maximum as_of value (data used pre-processing, model fitting, postprocessing), appropriate warning thrown.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_add_forecast_date.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Postprocessing step to add the forecast date — layer_add_forecast_date","text":"","code":"jhu <- case_death_rate_subset %>% dplyr::filter(time_value > \"2021-11-01\", geo_value %in% c(\"ak\", \"ca\", \"ny\")) r <- epi_recipe(jhu) %>% step_epi_lag(death_rate, lag = c(0, 7, 14)) %>% step_epi_ahead(death_rate, ahead = 7) %>% step_epi_naomit() wf <- epi_workflow(r, parsnip::linear_reg()) %>% fit(jhu) latest <- jhu %>% dplyr::filter(time_value >= max(time_value) - 14) # Don't specify `forecast_date` (by default, this should be last date in latest) f <- frosting() %>% layer_predict() %>% layer_naomit(.pred) wf0 <- wf %>% add_frosting(f) p0 <- predict(wf0, latest) p0 #> An `epi_df` object, 3 x 3 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 3 × 3 #> geo_value time_value .pred #> * #> 1 ak 2021-12-31 0.245 #> 2 ca 2021-12-31 0.313 #> 3 ny 2021-12-31 0.295 # Specify a `forecast_date` that is greater than or equal to `as_of` date f <- frosting() %>% layer_predict() %>% layer_add_forecast_date(forecast_date = \"2022-05-31\") %>% layer_naomit(.pred) wf1 <- wf %>% add_frosting(f) p1 <- predict(wf1, latest) p1 #> An `epi_df` object, 3 x 4 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 3 × 4 #> geo_value time_value .pred forecast_date #> * #> 1 ak 2021-12-31 0.245 2022-05-31 #> 2 ca 2021-12-31 0.313 2022-05-31 #> 3 ny 2021-12-31 0.295 2022-05-31 # Specify a `forecast_date` that is less than `as_of` date f2 <- frosting() %>% layer_predict() %>% layer_add_forecast_date(forecast_date = \"2021-12-31\") %>% layer_naomit(.pred) wf2 <- wf %>% add_frosting(f2) p2 <- predict(wf2, latest) #> Warning: The forecast_date is less than the most recent update date of the data: forecast_date = 2021-12-31 while data is from 2022-05-31. p2 #> An `epi_df` object, 3 x 4 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 3 × 4 #> geo_value time_value .pred forecast_date #> * #> 1 ak 2021-12-31 0.245 2021-12-31 #> 2 ca 2021-12-31 0.313 2021-12-31 #> 3 ny 2021-12-31 0.295 2021-12-31 # Do not specify a forecast_date f3 <- frosting() %>% layer_predict() %>% layer_add_forecast_date() %>% layer_naomit(.pred) wf3 <- wf %>% add_frosting(f3) p3 <- predict(wf3, latest) #> Warning: The forecast_date is less than the most recent update date of the data: forecast_date = 2021-12-31 while data is from 2022-05-31. p3 #> An `epi_df` object, 3 x 4 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 3 × 4 #> geo_value time_value .pred forecast_date #> * #> 1 ak 2021-12-31 0.245 2021-12-31 #> 2 ca 2021-12-31 0.313 2021-12-31 #> 3 ny 2021-12-31 0.295 2021-12-31"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_add_target_date.html","id":null,"dir":"Reference","previous_headings":"","what":"Postprocessing step to add the target date — layer_add_target_date","title":"Postprocessing step to add the target date — layer_add_target_date","text":"Postprocessing step add target date","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_add_target_date.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Postprocessing step to add the target date — layer_add_target_date","text":"","code":"layer_add_target_date( frosting, target_date = NULL, id = rand_id(\"add_target_date\") )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_add_target_date.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Postprocessing step to add the target date — layer_add_target_date","text":"frosting frosting postprocessor target_date target date add column epi_df. forecast date specified layer, forecast date plus ahead (step_epi_ahead epi_recipe). Otherwise, maximum time_value (data used pre-processing, fitting model, postprocessing) plus ahead, ahead specified preprocessing. user may override specifying target date (form \"yyyy-mm-dd\"). id random id string","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_add_target_date.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Postprocessing step to add the target date — layer_add_target_date","text":"updated frosting postprocessor","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_add_target_date.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Postprocessing step to add the target date — layer_add_target_date","text":"default, function assumes value ahead specified preprocessing step (likely step_epi_ahead). , ahead added maximum time_value test data get target date.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_add_target_date.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Postprocessing step to add the target date — layer_add_target_date","text":"","code":"jhu <- case_death_rate_subset %>% dplyr::filter(time_value > \"2021-11-01\", geo_value %in% c(\"ak\", \"ca\", \"ny\")) r <- epi_recipe(jhu) %>% step_epi_lag(death_rate, lag = c(0, 7, 14)) %>% step_epi_ahead(death_rate, ahead = 7) %>% step_epi_naomit() wf <- epi_workflow(r, parsnip::linear_reg()) %>% fit(jhu) latest <- get_test_data(r, jhu) # Use ahead + forecast date f <- frosting() %>% layer_predict() %>% layer_add_forecast_date(forecast_date = \"2022-05-31\") %>% layer_add_target_date() %>% layer_naomit(.pred) wf1 <- wf %>% add_frosting(f) p <- predict(wf1, latest) p #> An `epi_df` object, 3 x 5 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 3 × 5 #> geo_value time_value .pred forecast_date target_date #> * #> 1 ak 2021-12-31 0.245 2022-05-31 2022-06-07 #> 2 ca 2021-12-31 0.313 2022-05-31 2022-06-07 #> 3 ny 2021-12-31 0.295 2022-05-31 2022-06-07 # Use ahead + max time value from pre, fit, post # which is the same if include `layer_add_forecast_date()` f2 <- frosting() %>% layer_predict() %>% layer_add_target_date() %>% layer_naomit(.pred) wf2 <- wf %>% add_frosting(f2) p2 <- predict(wf2, latest) p2 #> An `epi_df` object, 3 x 4 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 3 × 4 #> geo_value time_value .pred target_date #> * #> 1 ak 2021-12-31 0.245 2022-01-07 #> 2 ca 2021-12-31 0.313 2022-01-07 #> 3 ny 2021-12-31 0.295 2022-01-07 # Specify own target date f3 <- frosting() %>% layer_predict() %>% layer_add_target_date(target_date = \"2022-01-08\") %>% layer_naomit(.pred) wf3 <- wf %>% add_frosting(f3) p3 <- predict(wf3, latest) p3 #> An `epi_df` object, 3 x 4 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 3 × 4 #> geo_value time_value .pred target_date #> * #> 1 ak 2021-12-31 0.245 2022-01-08 #> 2 ca 2021-12-31 0.313 2022-01-08 #> 3 ny 2021-12-31 0.295 2022-01-08"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_naomit.html","id":null,"dir":"Reference","previous_headings":"","what":"Omit NAs from predictions or other columns — layer_naomit","title":"Omit NAs from predictions or other columns — layer_naomit","text":"Omit NAs predictions columns","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_naomit.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Omit NAs from predictions or other columns — layer_naomit","text":"","code":"layer_naomit(frosting, ..., id = rand_id(\"naomit\"))"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_naomit.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Omit NAs from predictions or other columns — layer_naomit","text":"frosting frosting postprocessor ... One unquoted expressions separated commas. Variable names can used positions data frame, expressions like x:y can used select range variables. Typical usage .pred remove rows NA predictions. id random id string","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_naomit.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Omit NAs from predictions or other columns — layer_naomit","text":"updated frosting postprocessor","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_naomit.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Omit NAs from predictions or other columns — layer_naomit","text":"","code":"jhu <- case_death_rate_subset %>% dplyr::filter(time_value > \"2021-11-01\", geo_value %in% c(\"ak\", \"ca\", \"ny\")) r <- epi_recipe(jhu) %>% step_epi_lag(death_rate, lag = c(0, 7, 14)) %>% step_epi_ahead(death_rate, ahead = 7) wf <- epi_workflow(r, parsnip::linear_reg()) %>% fit(jhu) latest <- get_test_data(recipe = r, x = jhu) f <- frosting() %>% layer_predict() %>% layer_naomit(.pred) wf1 <- wf %>% add_frosting(f) p <- predict(wf1, latest) p #> An `epi_df` object, 3 x 3 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 3 × 3 #> geo_value time_value .pred #> * #> 1 ak 2021-12-31 0.245 #> 2 ca 2021-12-31 0.313 #> 3 ny 2021-12-31 0.295"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_point_from_distn.html","id":null,"dir":"Reference","previous_headings":"","what":"Converts distributional forecasts to point forecasts — layer_point_from_distn","title":"Converts distributional forecasts to point forecasts — layer_point_from_distn","text":"function adds postprocessing layer extract point forecast distributional forecast. NOTE: default arguments, remove information, one usually call layer_quantile_distn() set name argument something specific.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_point_from_distn.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Converts distributional forecasts to point forecasts — layer_point_from_distn","text":"","code":"layer_point_from_distn( frosting, ..., type = c(\"median\", \"mean\"), name = NULL, id = rand_id(\"point_from_distn\") )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_point_from_distn.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Converts distributional forecasts to point forecasts — layer_point_from_distn","text":"frosting frosting postprocessor ... Unused, include consistency layers. type character. Either mean median. name character. name output column. default NULL overwrite .pred column, removing distribution information. id random id string","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_point_from_distn.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Converts distributional forecasts to point forecasts — layer_point_from_distn","text":"updated frosting postprocessor.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_point_from_distn.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Converts distributional forecasts to point forecasts — layer_point_from_distn","text":"","code":"jhu <- case_death_rate_subset %>% dplyr::filter(time_value > \"2021-11-01\", geo_value %in% c(\"ak\", \"ca\", \"ny\")) r <- epi_recipe(jhu) %>% step_epi_lag(death_rate, lag = c(0, 7, 14)) %>% step_epi_ahead(death_rate, ahead = 7) %>% step_epi_naomit() wf <- epi_workflow(r, quantile_reg(tau = c(.25, .5, .75))) %>% fit(jhu) latest <- get_test_data(recipe = r, x = jhu) f1 <- frosting() %>% layer_predict() %>% layer_quantile_distn() %>% # puts the other quantiles in a different col layer_point_from_distn() %>% # mutate `.pred` to contain only a point prediction layer_naomit(.pred) wf1 <- wf %>% add_frosting(f1) p1 <- predict(wf1, latest) p1 #> An `epi_df` object, 3 x 4 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 3 × 4 #> geo_value time_value .pred .pred_distn #> * #> 1 ak 2021-12-31 0.167 [0.25, 0.75] #> 2 ca 2021-12-31 0.177 [0.25, 0.75] #> 3 ny 2021-12-31 0.272 [0.25, 0.75] f2 <- frosting() %>% layer_predict() %>% layer_point_from_distn() %>% # mutate `.pred` to contain only a point prediction layer_naomit(.pred) wf2 <- wf %>% add_frosting(f2) p2 <- predict(wf2, latest) p2 #> An `epi_df` object, 3 x 3 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 3 × 3 #> geo_value time_value .pred #> * #> 1 ak 2021-12-31 0.167 #> 2 ca 2021-12-31 0.177 #> 3 ny 2021-12-31 0.272"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_population_scaling.html","id":null,"dir":"Reference","previous_headings":"","what":"Convert per-capita predictions to raw scale — layer_population_scaling","title":"Convert per-capita predictions to raw scale — layer_population_scaling","text":"layer_population_scaling creates specification frosting layer \"undo\" per-capita scaling. Typical usage load dataset contains state-level population, use convert predictions made rate-scale model raw scale multiplying population. Although, worth noting nothing special \"population\". function can used scale variable. Population standard use case epidemiology forecasting scenario. value passed multiply selected variables rate_rescaling argument common divisor selected variables.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_population_scaling.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Convert per-capita predictions to raw scale — layer_population_scaling","text":"","code":"layer_population_scaling( frosting, ..., df, by = NULL, df_pop_col, rate_rescaling = 1, create_new = TRUE, suffix = \"_scaled\", id = rand_id(\"population_scaling\") )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_population_scaling.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Convert per-capita predictions to raw scale — layer_population_scaling","text":"frosting frosting postprocessor. layer added sequence operations frosting. ... One selector functions scale variables step. See recipes::selections() details. df data frame contains population data used inverting existing scaling. (possibly named) character vector variables join . NULL, default, function perform natural join, using variables common across epi_df produced predict() call user-provided dataset. columns epi_df df name (included ), .df added one user-provided data disambiguate. join different variables epi_df df, use named vector. example, = c(\"geo_value\" = \"states\") match epi_df$geo_value df$states. join multiple variables, use vector length > 1. example, = c(\"geo_value\" = \"states\", \"county\" = \"county\") match epi_df$geo_value df$states epi_df$county df$county. See dplyr::left_join() details. df_pop_col name column data frame df contains population data used scaling. rate_rescaling Sometimes rates \"per 100K\" \"per 1M\" rather \"per person\". Adjustments can made . example, original rate \"per 100K\", set rate_rescaling = 1e5 get counts back. create_new TRUE create new column keep original column epi_df. suffix character. suffix added column name create_new = TRUE. Default \"_scaled\". id random id string","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_population_scaling.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Convert per-capita predictions to raw scale — layer_population_scaling","text":"updated frosting postprocessor","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_population_scaling.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Convert per-capita predictions to raw scale — layer_population_scaling","text":"","code":"jhu <- epiprocess::jhu_csse_daily_subset %>% dplyr::filter(time_value > \"2021-11-01\", geo_value %in% c(\"ca\", \"ny\")) %>% dplyr::select(geo_value, time_value, cases) pop_data = data.frame(states = c(\"ca\", \"ny\"), value = c(20000, 30000)) r <- epi_recipe(jhu) %>% step_population_scaling(df = pop_data, df_pop_col = \"value\", by = c(\"geo_value\" = \"states\"), cases, suffix = \"_scaled\") %>% step_epi_lag(cases_scaled, lag = c(0, 7, 14)) %>% step_epi_ahead(cases_scaled, ahead = 7, role = \"outcome\") %>% step_epi_naomit() f <- frosting() %>% layer_predict() %>% layer_threshold(.pred) %>% layer_naomit(.pred) %>% layer_population_scaling(.pred, df = pop_data, by = c(\"geo_value\" = \"states\"), df_pop_col = \"value\") wf <- epi_workflow(r, parsnip::linear_reg()) %>% fit(jhu) %>% add_frosting(f) latest <- get_test_data( recipe = r, x = epiprocess::jhu_csse_daily_subset %>% dplyr::filter(time_value > \"2021-11-01\", geo_value %in% c(\"ca\", \"ny\")) %>% dplyr::select(geo_value, time_value, cases)) predict(wf, latest) #> An `epi_df` object, 2 x 4 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-23 20:17:07.044666 #> #> # A tibble: 2 × 4 #> geo_value time_value .pred .pred_scaled #> * #> 1 ca 2021-12-31 4.25 84967. #> 2 ny 2021-12-31 5.93 177783."},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_predict.html","id":null,"dir":"Reference","previous_headings":"","what":"Prediction layer for postprocessing — layer_predict","title":"Prediction layer for postprocessing — layer_predict","text":"Implements prediction fitted epi_workflow. One may want different types prediction, potentially apply amount postprocessing. typically first layer frosting postprocessor.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_predict.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Prediction layer for postprocessing — layer_predict","text":"","code":"layer_predict( frosting, type = NULL, opts = list(), ..., id = rand_id(\"predict_default\") )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_predict.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Prediction layer for postprocessing — layer_predict","text":"frosting frosting object type single character value NULL. Possible values \"numeric\", \"class\", \"prob\", \"conf_int\", \"pred_int\", \"quantile\", \"time\", \"hazard\", \"survival\", \"raw\". NULL, predict() choose appropriate value based model's mode. opts list optional arguments underlying predict function used type = \"raw\". list include options model object new data predicted. ... Additional parsnip-related options, depending value type. Arguments underlying model's prediction function passed (use opts argument instead). Possible arguments : interval: type equal \"survival\" \"quantile\", interval estimates added, available? Options \"none\" \"confidence\". level: type equal \"conf_int\", \"pred_int\", \"survival\", parameter tail area intervals (e.g. confidence level confidence intervals). Default value 0.95. std_error: type equal \"conf_int\" \"pred_int\", add standard error fit prediction (scale linear predictors). Default value FALSE. quantile: type equal quantile, quantiles distribution. Default (1:9)/10. eval_time: type equal \"survival\" \"hazard\", time points survival probability hazard estimated. id string identifying layer","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_predict.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Prediction layer for postprocessing — layer_predict","text":"updated frosting object","code":""},{"path":[]},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_predict.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Prediction layer for postprocessing — layer_predict","text":"","code":"jhu <- case_death_rate_subset %>% filter(time_value > \"2021-11-01\", geo_value %in% c(\"ak\", \"ca\", \"ny\")) r <- epi_recipe(jhu) %>% step_epi_lag(death_rate, lag = c(0, 7, 14)) %>% step_epi_ahead(death_rate, ahead = 7) %>% step_epi_naomit() wf <- epi_workflow(r, parsnip::linear_reg()) %>% fit(jhu) latest <- jhu %>% filter(time_value >= max(time_value) - 14) # Predict layer alone f <- frosting() %>% layer_predict() wf1 <- wf %>% add_frosting(f) p1 <- predict(wf1, latest) p1 #> An `epi_df` object, 3 x 3 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 3 × 3 #> geo_value time_value .pred #> * #> 1 ak 2021-12-31 0.245 #> 2 ca 2021-12-31 0.313 #> 3 ny 2021-12-31 0.295 # Prediction with interval f <- frosting() %>% layer_predict(type = \"pred_int\") wf2 <- wf %>% add_frosting(f) p2 <- predict(wf2, latest) p2 #> An `epi_df` object, 3 x 4 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 3 × 4 #> geo_value time_value .pred_lower .pred_upper #> * #> 1 ak 2021-12-31 -0.366 0.856 #> 2 ca 2021-12-31 -0.284 0.910 #> 3 ny 2021-12-31 -0.301 0.891"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_predictive_distn.html","id":null,"dir":"Reference","previous_headings":"","what":"Returns predictive distributions — layer_predictive_distn","title":"Returns predictive distributions — layer_predictive_distn","text":"function calculates approximation parametric predictive distribution. Predictive distributions linear models require x* (X'X)^{-1} x* along degrees freedom. function approximates . reasonably accurate models fit using lm new point x* far bulk data.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_predictive_distn.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Returns predictive distributions — layer_predictive_distn","text":"","code":"layer_predictive_distn( frosting, ..., dist_type = c(\"gaussian\", \"student_t\"), truncate = c(-Inf, Inf), name = \".pred_distn\", id = rand_id(\"predictive_distn\") )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_predictive_distn.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Returns predictive distributions — layer_predictive_distn","text":"frosting frosting postprocessor ... Unused, include consistency layers. dist_type Gaussian Student's t predictive intervals truncate truncate distribution interval name character. name output column. id random id string","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_predictive_distn.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Returns predictive distributions — layer_predictive_distn","text":"updated frosting postprocessor additional columns residual quantiles added prediction","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_predictive_distn.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Returns predictive distributions — layer_predictive_distn","text":"","code":"jhu <- case_death_rate_subset %>% dplyr::filter(time_value > \"2021-11-01\", geo_value %in% c(\"ak\", \"ca\", \"ny\")) r <- epi_recipe(jhu) %>% step_epi_lag(death_rate, lag = c(0, 7, 14)) %>% step_epi_ahead(death_rate, ahead = 7) %>% step_epi_naomit() wf <- epi_workflow(r, parsnip::linear_reg()) %>% fit(jhu) latest <- get_test_data(recipe = r, x = jhu) f <- frosting() %>% layer_predict() %>% layer_predictive_distn() %>% layer_naomit(.pred) wf1 <- wf %>% add_frosting(f) p <- predict(wf1, latest) p #> An `epi_df` object, 3 x 4 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 3 × 4 #> geo_value time_value .pred .pred_distn #> * #> 1 ak 2021-12-31 0.245 N(0.24, 0.093) #> 2 ca 2021-12-31 0.313 N(0.31, 0.093) #> 3 ny 2021-12-31 0.295 N(0.29, 0.093)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_quantile_distn.html","id":null,"dir":"Reference","previous_headings":"","what":"Returns predictive quantiles — layer_quantile_distn","title":"Returns predictive quantiles — layer_quantile_distn","text":"function calculates quantiles prediction distributional. Currently, distributional engine quantile_reg(). engine used, layer grab estimated (extrapolated) quantiles requested levels.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_quantile_distn.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Returns predictive quantiles — layer_quantile_distn","text":"","code":"layer_quantile_distn( frosting, ..., levels = c(0.25, 0.75), truncate = c(-Inf, Inf), name = \".pred_distn\", id = rand_id(\"quantile_distn\") )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_quantile_distn.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Returns predictive quantiles — layer_quantile_distn","text":"frosting frosting postprocessor ... Unused, include consistency layers. levels vector probabilities (quantiles) extract truncate truncate distribution interval name character. name output column. id random id string","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_quantile_distn.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Returns predictive quantiles — layer_quantile_distn","text":"updated frosting postprocessor. additional column predictive quantiles added predictions.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_quantile_distn.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Returns predictive quantiles — layer_quantile_distn","text":"","code":"jhu <- case_death_rate_subset %>% dplyr::filter(time_value > \"2021-11-01\", geo_value %in% c(\"ak\", \"ca\", \"ny\")) r <- epi_recipe(jhu) %>% step_epi_lag(death_rate, lag = c(0, 7, 14)) %>% step_epi_ahead(death_rate, ahead = 7) %>% step_epi_naomit() wf <- epi_workflow(r, quantile_reg(tau = c(.25, .5, .75))) %>% fit(jhu) latest <- get_test_data(recipe = r, x = jhu) f <- frosting() %>% layer_predict() %>% layer_quantile_distn() %>% layer_naomit(.pred) wf1 <- wf %>% add_frosting(f) p <- predict(wf1, latest) p #> An `epi_df` object, 3 x 4 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 3 × 4 #> geo_value time_value .pred .pred_distn #> * #> 1 ak 2021-12-31 [0.25, 0.75] [0.25, 0.75] #> 2 ca 2021-12-31 [0.25, 0.75] [0.25, 0.75] #> 3 ny 2021-12-31 [0.25, 0.75] [0.25, 0.75]"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_residual_quantiles.html","id":null,"dir":"Reference","previous_headings":"","what":"Creates predictions based on residual quantiles — layer_residual_quantiles","title":"Creates predictions based on residual quantiles — layer_residual_quantiles","text":"Creates predictions based residual quantiles","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_residual_quantiles.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Creates predictions based on residual quantiles — layer_residual_quantiles","text":"","code":"layer_residual_quantiles( frosting, ..., probs = c(0.05, 0.95), symmetrize = TRUE, by_key = character(0L), name = \".pred_distn\", id = rand_id(\"residual_quantiles\") )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_residual_quantiles.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Creates predictions based on residual quantiles — layer_residual_quantiles","text":"frosting frosting postprocessor ... Unused, include consistency layers. probs numeric vector probabilities values (0,1) referring desired quantile. symmetrize logical. TRUE interval symmetric. by_key character vector keys group residuals calculating quantiles. default, c() performs grouping. name character. name output column. id random id string","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_residual_quantiles.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Creates predictions based on residual quantiles — layer_residual_quantiles","text":"updated frosting postprocessor additional columns residual quantiles added prediction","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_residual_quantiles.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Creates predictions based on residual quantiles — layer_residual_quantiles","text":"","code":"jhu <- case_death_rate_subset %>% dplyr::filter(time_value > \"2021-11-01\", geo_value %in% c(\"ak\", \"ca\", \"ny\")) r <- epi_recipe(jhu) %>% step_epi_lag(death_rate, lag = c(0, 7, 14)) %>% step_epi_ahead(death_rate, ahead = 7) %>% step_epi_naomit() wf <- epi_workflow(r, parsnip::linear_reg()) %>% fit(jhu) latest <- get_test_data(recipe = r, x = jhu) f <- frosting() %>% layer_predict() %>% layer_residual_quantiles(probs = c(0.0275, 0.975), symmetrize = FALSE) %>% layer_naomit(.pred) wf1 <- wf %>% add_frosting(f) p <- predict(wf1, latest) f2 <- frosting() %>% layer_predict() %>% layer_residual_quantiles(probs = c(0.3, 0.7), by_key = \"geo_value\") %>% layer_naomit(.pred) wf2 <- wf %>% add_frosting(f2) p2 <- predict(wf2, latest) #> Warning: Some grouping keys are not in data.frame returned by the"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_threshold.html","id":null,"dir":"Reference","previous_headings":"","what":"Lower and upper thresholds for predicted values — layer_threshold","title":"Lower and upper thresholds for predicted values — layer_threshold","text":"postprocessing step used set prediction values smaller lower threshold higher upper threshold equal threshold values.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_threshold.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Lower and upper thresholds for predicted values — layer_threshold","text":"","code":"layer_threshold( frosting, ..., lower = 0, upper = Inf, id = rand_id(\"threshold\") )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_threshold.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Lower and upper thresholds for predicted values — layer_threshold","text":"frosting frosting postprocessor ... One unquoted expressions separated commas. Variable names can used positions data frame, expressions like x:y can used select range variables. Typical usage .pred threshold predictions range (say, nonnegative). lower Lower threshold prediction values. , predictions less lower bound set . Default value 0. upper Upper threshold prediction values. , predictions greater upper bound set . Default value Inf. id random id string","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_threshold.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Lower and upper thresholds for predicted values — layer_threshold","text":"updated frosting postprocessor","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_threshold.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Lower and upper thresholds for predicted values — layer_threshold","text":"","code":"jhu <- case_death_rate_subset %>% dplyr::filter(time_value < \"2021-03-08\", geo_value %in% c(\"ak\", \"ca\", \"ar\")) r <- epi_recipe(jhu) %>% step_epi_lag(death_rate, lag = c(0, 7, 14)) %>% step_epi_ahead(death_rate, ahead = 7) %>% step_epi_naomit() wf <- epi_workflow(r, parsnip::linear_reg()) %>% fit(jhu) latest <- get_test_data(r, jhu) f <- frosting() %>% layer_predict() %>% layer_threshold(.pred, lower = 0.180, upper = 0.310) wf <- wf %>% add_frosting(f) p <- predict(wf, latest) p #> An `epi_df` object, 3 x 3 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 3 × 3 #> geo_value time_value .pred #> * #> 1 ak 2021-03-07 0.18 #> 2 ar 2021-03-07 0.18 #> 3 ca 2021-03-07 0.31"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_unnest.html","id":null,"dir":"Reference","previous_headings":"","what":"Unnest prediction list-cols — layer_unnest","title":"Unnest prediction list-cols — layer_unnest","text":"Unnest prediction list-cols","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_unnest.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Unnest prediction list-cols — layer_unnest","text":"","code":"layer_unnest(frosting, ..., id = rand_id(\"unnest\"))"},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_unnest.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Unnest prediction list-cols — layer_unnest","text":"frosting frosting postprocessor ... One unquoted expressions separated commas. Variable names can used positions data frame, expressions like x:y can used select range variables. id random id string","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/layer_unnest.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Unnest prediction list-cols — layer_unnest","text":"updated frosting postprocessor","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/nested_quantiles.html","id":null,"dir":"Reference","previous_headings":"","what":"Turn a vector of quantile distributions into a list-col — nested_quantiles","title":"Turn a vector of quantile distributions into a list-col — nested_quantiles","text":"Turn vector quantile distributions list-col","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/nested_quantiles.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Turn a vector of quantile distributions into a list-col — nested_quantiles","text":"","code":"nested_quantiles(x)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/nested_quantiles.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Turn a vector of quantile distributions into a list-col — nested_quantiles","text":"x distribution containing dist_quantiles","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/nested_quantiles.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Turn a vector of quantile distributions into a list-col — nested_quantiles","text":"list-col","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/nested_quantiles.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Turn a vector of quantile distributions into a list-col — nested_quantiles","text":"","code":"edf <- case_death_rate_subset[1:3,] edf$q <- dist_quantiles(list(1:5, 2:4, 3:10), list(1:5/6, 2:4/5, 3:10/11)) edf_nested <- edf %>% dplyr::mutate(q = nested_quantiles(q)) edf_nested %>% tidyr::unnest(q) #> An `epi_df` object, 16 x 6 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 16 × 6 #> geo_value time_value case_rate death_rate q tau #> * #> 1 ak 2020-12-31 35.9 0.158 1 0.167 #> 2 ak 2020-12-31 35.9 0.158 2 0.333 #> 3 ak 2020-12-31 35.9 0.158 3 0.5 #> 4 ak 2020-12-31 35.9 0.158 4 0.667 #> 5 ak 2020-12-31 35.9 0.158 5 0.833 #> 6 al 2020-12-31 65.1 0.438 2 0.4 #> 7 al 2020-12-31 65.1 0.438 3 0.6 #> 8 al 2020-12-31 65.1 0.438 4 0.8 #> 9 ar 2020-12-31 66.0 1.27 3 0.273 #> 10 ar 2020-12-31 66.0 1.27 4 0.364 #> 11 ar 2020-12-31 66.0 1.27 5 0.455 #> 12 ar 2020-12-31 66.0 1.27 6 0.545 #> 13 ar 2020-12-31 66.0 1.27 7 0.636 #> 14 ar 2020-12-31 66.0 1.27 8 0.727 #> 15 ar 2020-12-31 66.0 1.27 9 0.818 #> 16 ar 2020-12-31 66.0 1.27 10 0.909"},{"path":"https://cmu-delphi.github.io/epipredict/reference/new_epi_recipe_blueprint.html","id":null,"dir":"Reference","previous_headings":"","what":"Recipe blueprint that accounts for epi_df panel data — new_epi_recipe_blueprint","title":"Recipe blueprint that accounts for epi_df panel data — new_epi_recipe_blueprint","text":"Used simplicity. See hardhat::new_recipe_blueprint() hardhat::default_recipe_blueprint() details.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/new_epi_recipe_blueprint.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Recipe blueprint that accounts for epi_df panel data — new_epi_recipe_blueprint","text":"","code":"new_epi_recipe_blueprint( intercept = FALSE, allow_novel_levels = FALSE, fresh = TRUE, composition = \"tibble\", ptypes = NULL, recipe = NULL, ..., subclass = character() ) epi_recipe_blueprint( intercept = FALSE, allow_novel_levels = FALSE, fresh = TRUE, composition = \"tibble\" ) default_epi_recipe_blueprint( intercept = FALSE, allow_novel_levels = FALSE, fresh = TRUE, composition = \"tibble\" ) new_default_epi_recipe_blueprint( intercept = FALSE, allow_novel_levels = FALSE, fresh = TRUE, composition = \"tibble\", ptypes = NULL, recipe = NULL, extra_role_ptypes = NULL, ..., subclass = character() )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/new_epi_recipe_blueprint.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Recipe blueprint that accounts for epi_df panel data — new_epi_recipe_blueprint","text":"intercept logical. intercept included processed data? information used process function mold forge function list. allow_novel_levels logical. novel factor levels allowed prediction time? information used clean function forge function list, passed scream(). fresh already trained operations re-trained prep() called? composition Either \"tibble\", \"matrix\", \"dgCMatrix\" format processed predictors. \"matrix\" \"dgCMatrix\" chosen, predictors must numeric preprocessing method applied; otherwise error thrown. ptypes Either NULL, named list 2 elements, predictors outcomes, 0-row tibbles. ptypes generated automatically mold() time used validate new_data prediction time. recipe Either NULL, unprepped recipe. argument set automatically mold() time. ... Name-value pairs additional elements blueprints subclass blueprint. subclass character vector. subclasses blueprint. extra_role_ptypes named list. names unique non-standard recipe roles (.e. everything except \"predictors\" \"outcomes\"). values prototypes original columns role. used validation forge().","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/new_epi_recipe_blueprint.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Recipe blueprint that accounts for epi_df panel data — new_epi_recipe_blueprint","text":"recipe blueprint.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/new_epi_recipe_blueprint.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Recipe blueprint that accounts for epi_df panel data — new_epi_recipe_blueprint","text":"bake_dependent_roles automatically set epi_df defaults.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/pipe.html","id":null,"dir":"Reference","previous_headings":"","what":"Pipe operator — %>%","title":"Pipe operator — %>%","text":"See magrittr::%>% details.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/pipe.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Pipe operator — %>%","text":"","code":"lhs %>% rhs"},{"path":"https://cmu-delphi.github.io/epipredict/reference/pipe.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Pipe operator — %>%","text":"lhs value magrittr placeholder. rhs function call using magrittr semantics.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/pipe.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Pipe operator — %>%","text":"result calling rhs(lhs).","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/pivot_quantiles.html","id":null,"dir":"Reference","previous_headings":"","what":"Pivot columns containing dist_quantile wider — pivot_quantiles","title":"Pivot columns containing dist_quantile wider — pivot_quantiles","text":"selected columns contain dist_quantiles \"widened\" \"taus\" (quantile) serving names values data frame. pivoting multiple columns, original column name used prefix.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/pivot_quantiles.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Pivot columns containing dist_quantile wider — pivot_quantiles","text":"","code":"pivot_quantiles(.data, ...)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/pivot_quantiles.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Pivot columns containing dist_quantile wider — pivot_quantiles","text":".data data frame, data frame extension tibble epi_df. ... One unquoted expressions separated commas. Variable names can used positions data frame, expressions like x:y can used select range variables. selected columns ","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/pivot_quantiles.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Pivot columns containing dist_quantile wider — pivot_quantiles","text":"object class .data","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/pivot_quantiles.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Pivot columns containing dist_quantile wider — pivot_quantiles","text":"","code":"d1 <- c(dist_quantiles(1:3, 1:3 / 4), dist_quantiles(2:4, 1:3 / 4)) d2 <- c(dist_quantiles(2:4, 2:4 / 5), dist_quantiles(3:5, 2:4 / 5)) tib <- tibble::tibble(g = c(\"a\", \"b\"), d1 = d1, d2 = d2) pivot_quantiles(tib, c(\"d1\", \"d2\")) #> # A tibble: 2 × 7 #> g d1_0.25 d1_0.5 d1_0.75 d2_0.4 d2_0.6 d2_0.8 #> #> 1 a 1 2 3 2 3 4 #> 2 b 2 3 4 3 4 5 pivot_quantiles(tib, tidyselect::starts_with(\"d\")) #> # A tibble: 2 × 7 #> g d1_0.25 d1_0.5 d1_0.75 d2_0.4 d2_0.6 d2_0.8 #> #> 1 a 1 2 3 2 3 4 #> 2 b 2 3 4 3 4 5 pivot_quantiles(tib, d2) #> # A tibble: 2 × 5 #> g d1 `0.4` `0.6` `0.8` #> #> 1 a [0.25, 0.75] 2 3 4 #> 2 b [0.25, 0.75] 3 4 5"},{"path":"https://cmu-delphi.github.io/epipredict/reference/predict-epi_workflow.html","id":null,"dir":"Reference","previous_headings":"","what":"Predict from an epi_workflow — predict-epi_workflow","title":"Predict from an epi_workflow — predict-epi_workflow","text":"predict() method fit epi_workflow object. nice thing predicting epi_workflow : Preprocess new_data using preprocessing method specified workflow created fit. accomplished using hardhat::forge(), apply formula preprocessing call recipes::bake() recipe supplied. Call parsnip::predict.model_fit() using underlying fit parsnip model. Ensure returned object epiprocess::epi_df possible. Specifically, output time_value geo_value columns well prediction.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/predict-epi_workflow.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Predict from an epi_workflow — predict-epi_workflow","text":"","code":"# S3 method for epi_workflow predict(object, new_data, ...)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/predict-epi_workflow.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Predict from an epi_workflow — predict-epi_workflow","text":"object epi_workflow fit workflows::fit.workflow() new_data data frame containing new predictors preprocess predict ... Additional parsnip-related options, depending value type. Arguments underlying model's prediction function passed (use opts argument instead). Possible arguments : interval: type equal \"survival\" \"quantile\", interval estimates added, available? Options \"none\" \"confidence\". level: type equal \"conf_int\", \"pred_int\", \"survival\", parameter tail area intervals (e.g. confidence level confidence intervals). Default value 0.95. std_error: type equal \"conf_int\" \"pred_int\", add standard error fit prediction (scale linear predictors). Default value FALSE. quantile: type equal quantile, quantiles distribution. Default (1:9)/10. eval_time: type equal \"survival\" \"hazard\", time points survival probability hazard estimated.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/predict-epi_workflow.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Predict from an epi_workflow — predict-epi_workflow","text":"data frame model predictions, many rows new_data . new_data epi_df data frame time_value geo_value columns, result well.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/predict-epi_workflow.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Predict from an epi_workflow — predict-epi_workflow","text":"","code":"jhu <- case_death_rate_subset r <- epi_recipe(jhu) %>% step_epi_lag(death_rate, lag = c(0, 7, 14)) %>% step_epi_ahead(death_rate, ahead = 7) %>% step_epi_lag(case_rate, lag = c(0, 7, 14)) %>% step_epi_naomit() wf <- epi_workflow(r, parsnip::linear_reg()) %>% fit(jhu) latest <- jhu %>% dplyr::filter(time_value >= max(time_value) - 14) preds <- predict(wf, latest) preds #> An `epi_df` object, 56 x 3 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 56 × 3 #> geo_value time_value .pred #> * #> 1 ak 2021-12-31 0.378 #> 2 al 2021-12-31 0.280 #> 3 ar 2021-12-31 0.452 #> 4 as 2021-12-31 -0.000475 #> 5 az 2021-12-31 0.657 #> 6 ca 2021-12-31 0.293 #> 7 co 2021-12-31 0.569 #> 8 ct 2021-12-31 0.641 #> 9 dc 2021-12-31 1.02 #> 10 de 2021-12-31 0.733 #> # ℹ 46 more rows"},{"path":"https://cmu-delphi.github.io/epipredict/reference/quantile_reg.html","id":null,"dir":"Reference","previous_headings":"","what":"Quantile regression — quantile_reg","title":"Quantile regression — quantile_reg","text":"quantile_reg() generates quantile regression model specification tidymodels framework. Currently, supported engine \"rq\" uses quantreg::rq().","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/quantile_reg.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Quantile regression — quantile_reg","text":"","code":"quantile_reg(mode = \"regression\", engine = \"rq\", tau = 0.5)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/quantile_reg.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Quantile regression — quantile_reg","text":"mode single character string type model. possible value model \"regression\". engine Character string naming fitting function. Currently, \"rq\" supported. tau scalar vector values (0, 1) determine quantiles estimate (default 0.5).","code":""},{"path":[]},{"path":"https://cmu-delphi.github.io/epipredict/reference/quantile_reg.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Quantile regression — quantile_reg","text":"","code":"tib <- data.frame(y = rnorm(100), x1 = rnorm(100), x2 = rnorm(100)) rq_spec <- quantile_reg(tau = c(.2, .8)) %>% set_engine(\"rq\") ff <- rq_spec %>% fit(y ~ ., data = tib) predict(ff, new_data = tib) #> # A tibble: 100 × 1 #> .pred #> #> 1 [0.2, 0.8] #> 2 [0.2, 0.8] #> 3 [0.2, 0.8] #> 4 [0.2, 0.8] #> 5 [0.2, 0.8] #> 6 [0.2, 0.8] #> 7 [0.2, 0.8] #> 8 [0.2, 0.8] #> 9 [0.2, 0.8] #> 10 [0.2, 0.8] #> # ℹ 90 more rows"},{"path":"https://cmu-delphi.github.io/epipredict/reference/reexports.html","id":null,"dir":"Reference","previous_headings":"","what":"Objects exported from other packages — reexports","title":"Objects exported from other packages — reexports","text":"objects imported packages. Follow links see documentation. generics fit recipes bake, prep","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/slather.html","id":null,"dir":"Reference","previous_headings":"","what":"Spread a layer of frosting on a fitted workflow — slather","title":"Spread a layer of frosting on a fitted workflow — slather","text":"Slathering frosting means implement postprocessing layer. creating new postprocessing layer, must implement S3 method function","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/slather.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Spread a layer of frosting on a fitted workflow — slather","text":"","code":"slather(object, components, workflow, new_data, ...)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/slather.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Spread a layer of frosting on a fitted workflow — slather","text":"object workflow frosting postprocessing steps components list components containing model information. updated returned layer. mold - output calling hardhat::mold() workflow. contains information preprocessing, including recipe. forged - output calling hardhat::forge() workflow. predictors outcomes new_data. three components predictors, outcomes (new_data), extras (usually rest data, including keys). keys - put keys (time_value, geo_value, others) ease. workflow object class workflow new_data data frame containing new predictors preprocess predict ... additional arguments used methods. Currently unused.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/slather.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Spread a layer of frosting on a fitted workflow — slather","text":"components list. format applying updates.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/smooth_quantile_reg.html","id":null,"dir":"Reference","previous_headings":"","what":"Smooth quantile regression — smooth_quantile_reg","title":"Smooth quantile regression — smooth_quantile_reg","text":"smooth_quantile_reg() generates quantile regression model specification tidymodels framework. Currently, supported engine smoothqr::smooth_qr().","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/smooth_quantile_reg.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Smooth quantile regression — smooth_quantile_reg","text":"","code":"smooth_quantile_reg( mode = \"regression\", engine = \"smoothqr\", outcome_locations = NULL, tau = 0.5, degree = 3L )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/smooth_quantile_reg.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Smooth quantile regression — smooth_quantile_reg","text":"mode single character string type model. possible value model \"regression\". engine Character string naming fitting function. Currently, \"smooth_qr\" supported. outcome_locations Defaults vector 1:ncol(y) responses observed different spacing (appear different order), information used . argument mapped ahead argument smoothqr::smooth_qr(). tau scalar vector values (0, 1) determine quantiles estimate (default 0.5). degree number polynomials used response smoothing. Must number responses.","code":""},{"path":[]},{"path":"https://cmu-delphi.github.io/epipredict/reference/smooth_quantile_reg.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Smooth quantile regression — smooth_quantile_reg","text":"","code":"tib <- data.frame( y1 = rnorm(100), y2 = rnorm(100), y3 = rnorm(100), y4 = rnorm(100), y5 = rnorm(100), y6 = rnorm(100), x1 = rnorm(100), x2 = rnorm(100)) qr_spec <- smooth_quantile_reg(tau = c(.2, .5, .8), outcome_locations = 1:6) ff <- qr_spec %>% fit(cbind(y1, y2 , y3 , y4 , y5 , y6) ~ ., data = tib) p <- predict(ff, new_data = tib) x <- -99:99 / 100 * 2 * pi y <- sin(x) + rnorm(length(x), sd = .1) fd <- x[length(x) - 20] XY <- smoothqr::lagmat(y[1:(length(y) - 20)], c(-20:20)) XY <- tibble::as_tibble(XY) qr_spec <- smooth_quantile_reg(tau = c(.2, .5, .8), outcome_locations = 20:1) tt <- qr_spec %>% fit_xy(x = XY[,21:41], y = XY[,1:20]) library(tidyr) library(dplyr) pl <- predict( object = tt, new_data = XY[max(which(complete.cases(XY[,21:41]))), 21:41] ) pl <- pl %>% unnest(.pred) %>% mutate(distn = nested_quantiles(distn)) %>% unnest(distn) %>% mutate(x = x[length(x) - 20] + ahead / 100 * 2 * pi, ahead = NULL) %>% pivot_wider(names_from = tau, values_from = q) plot(x, y, pch = 16, xlim = c(pi, 2 * pi), col = \"lightgrey\") curve(sin(x), add = TRUE) abline(v = fd, lty = 2) lines(pl$x, pl$`0.2`, col = \"blue\") lines(pl$x, pl$`0.8`, col = \"blue\") lines(pl$x, pl$`0.5`, col = \"red\") if (FALSE) { ggplot(data.frame(x = x, y = y), aes(x)) + geom_ribbon(data = pl, aes(ymin = `0.2`, ymax = `0.8`), fill = \"lightblue\") + geom_point(aes(y = y), colour = \"grey\") + # observed data geom_function(fun = sin, colour = \"black\") + # truth geom_vline(xintercept = fd, linetype = \"dashed\") + # end of training data geom_line(data = pl, aes(y = `0.5`), colour = \"red\") + # median prediction theme_bw() + coord_cartesian(xlim = c(0, NA)) + ylab(\"y\") }"},{"path":"https://cmu-delphi.github.io/epipredict/reference/state_census.html","id":null,"dir":"Reference","previous_headings":"","what":"State population data — state_census","title":"State population data — state_census","text":"Data set state populations, 2019 US Census.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/state_census.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"State population data — state_census","text":"","code":"state_census"},{"path":"https://cmu-delphi.github.io/epipredict/reference/state_census.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"State population data — state_census","text":"Data frame 57 rows (including one United States whole, plus District Columbia, Puerto Rico Commonwealth, American Samoa, Guam, U.S. Virgin Islands, Northern Mariana, Islands). fips FIPS code name Full name state territory pop Estimate location's resident population 2019. abbr Postal abbreviation location","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/state_census.html","id":"source","dir":"Reference","previous_headings":"","what":"Source","title":"State population data — state_census","text":"United States Census Bureau, https://www2.census.gov/programs-surveys/popest/datasets/2010-2019/counties/totals/co-est2019-alldata.pdf, https://www.census.gov/data/tables/time-series/demo/popest/2010s-total-puerto-rico-municipios.html, https://www.census.gov/data/tables/2010/dec/2010-island-areas.html","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_epi_naomit.html","id":null,"dir":"Reference","previous_headings":"","what":"Unified NA omission wrapper function for recipes — step_epi_naomit","title":"Unified NA omission wrapper function for recipes — step_epi_naomit","text":"Unified NA omission wrapper function recipes","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_epi_naomit.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Unified NA omission wrapper function for recipes — step_epi_naomit","text":"","code":"step_epi_naomit(recipe)"},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_epi_naomit.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Unified NA omission wrapper function for recipes — step_epi_naomit","text":"recipe Recipe used omission steps","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_epi_naomit.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Unified NA omission wrapper function for recipes — step_epi_naomit","text":"Omits NA's predictors outcomes training time fit model. Also omits associated predictors outcomes prediction time due lack response avoidance data loss.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_epi_naomit.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Unified NA omission wrapper function for recipes — step_epi_naomit","text":"","code":"case_death_rate_subset %>% epi_recipe() %>% step_epi_naomit() #> #> ── Recipe ────────────────────────────────────────────────────────────────────── #> #> ── Inputs #> Number of variables by role #> raw: 2 #> geo_value: 1 #> time_value: 1 #> #> ── Operations #> • Removing rows with NA values in: all_predictors() #> • Removing rows with NA values in: all_outcomes()"},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_epi_shift.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a shifted predictor — step_epi_lag","title":"Create a shifted predictor — step_epi_lag","text":"step_epi_lag step_epi_ahead create specification recipe step add new columns shifted data. former created lag column, latter create lead column. Shifted data default include NA values shift induced. can properly removed step_epi_naomit(), may specify alternative filler value default argument.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_epi_shift.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a shifted predictor — step_epi_lag","text":"","code":"step_epi_lag( recipe, ..., role = \"predictor\", trained = FALSE, lag, prefix = \"lag_\", default = NA, columns = NULL, skip = FALSE, id = rand_id(\"epi_lag\") ) step_epi_ahead( recipe, ..., role = \"outcome\", trained = FALSE, ahead, prefix = \"ahead_\", default = NA, columns = NULL, skip = FALSE, id = rand_id(\"epi_ahead\") )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_epi_shift.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a shifted predictor — step_epi_lag","text":"recipe recipe object. step added sequence operations recipe. ... One selector functions choose variables step. See recipes::selections() details. role model terms created step, analysis role assigned? lag default predictor ahead outcome. trained logical indicate quantities preprocessing estimated. lag, ahead vector integers. specified column lag lead value vector. Lag integers must nonnegative, ahead integers must positive. prefix prefix indicate type variable default Determines fills empty rows left leading/lagging (defaults NA). columns character string variable names populated (eventually) terms argument. skip logical. step skipped recipe baked bake()? operations baked prep() run, operations may able conducted new data (e.g. processing outcome variable(s)). Care taken using skip = TRUE may affect computations subsequent operations. id unique identifier step","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_epi_shift.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a shifted predictor — step_epi_lag","text":"updated version recipe new step added sequence existing operations.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_epi_shift.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Create a shifted predictor — step_epi_lag","text":"step assumes data already proper sequential order shifting. prefix id arguments unchangeable ensure code runs properly avoid inconsistency naming. step_epi_ahead, always set \"ahead_\" \"epi_ahead\" respectively, step_epi_lag, set \"lag_\" \"epi_lag, respectively.","code":""},{"path":[]},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_epi_shift.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create a shifted predictor — step_epi_lag","text":"","code":"r <- epi_recipe(case_death_rate_subset) %>% step_epi_ahead(death_rate, ahead = 7) %>% step_epi_lag(death_rate, lag = c(0,7,14)) r #> #> ── Recipe ────────────────────────────────────────────────────────────────────── #> #> ── Inputs #> Number of variables by role #> raw: 2 #> geo_value: 1 #> time_value: 1 #> #> ── Operations #> • Leading: death_rate by 7 #> • Lagging: death_rate by 0, 7, 14"},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_growth_rate.html","id":null,"dir":"Reference","previous_headings":"","what":"Calculate a growth rate — step_growth_rate","title":"Calculate a growth rate — step_growth_rate","text":"step_growth_rate() creates specification recipe step generate one new columns derived data.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_growth_rate.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Calculate a growth rate — step_growth_rate","text":"","code":"step_growth_rate( recipe, ..., role = \"predictor\", trained = FALSE, horizon = 7, method = c(\"rel_change\", \"linear_reg\", \"smooth_spline\", \"trend_filter\"), log_scale = FALSE, replace_Inf = NA, prefix = \"gr_\", columns = NULL, skip = FALSE, id = rand_id(\"growth_rate\"), additional_gr_args_list = list() )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_growth_rate.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Calculate a growth rate — step_growth_rate","text":"recipe recipe object. step added sequence operations recipe. ... One selector functions choose variables step. See recipes::selections() details. role model terms created step, analysis role assigned? lag default predictor ahead outcome. trained logical indicate quantities preprocessing estimated. horizon Bandwidth sliding window, method \"rel_change\" \"linear_reg\". See epiprocess::growth_rate() details. method Either \"rel_change\", \"linear_reg\", \"smooth_spline\", \"trend_filter\", indicating method use growth rate calculation. first two local methods: run sliding fashion sequence (order estimate derivatives hence growth rates); latter two global methods: run entire sequence. See epiprocess::growth_rate() details. log_scale growth rates estimated using parameterization log scale? See details explanation. Default FALSE. replace_Inf Sometimes, growth rate calculation can result infinite values (denominator zero, example). case, prediction methods fail. argument specifies potential replacement values. default (NA) likely result rows removed data. Alternatively, specify arbitrary large values, perhaps zero. Setting argument NULL result replacement. prefix prefix indicate type variable columns character string variable names populated (eventually) terms argument. skip logical. step skipped recipe baked bake()? operations baked prep() run, operations may able conducted new data (e.g. processing outcome variable(s)). Care taken using skip = TRUE may affect computations subsequent operations. id unique identifier step additional_gr_args_list list additional arguments used epiprocess::growth_rate(). ... arguments may passed along dup_rm na_rm.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_growth_rate.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Calculate a growth rate — step_growth_rate","text":"updated version recipe new step added sequence existing operations.","code":""},{"path":[]},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_growth_rate.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Calculate a growth rate — step_growth_rate","text":"","code":"r <- epi_recipe(case_death_rate_subset) %>% step_growth_rate(case_rate, death_rate) r #> #> ── Recipe ────────────────────────────────────────────────────────────────────── #> #> ── Inputs #> Number of variables by role #> raw: 2 #> geo_value: 1 #> time_value: 1 #> #> ── Operations #> • Calculating growth_rate for: case_rate, death_rate by rel_change r %>% recipes::prep() %>% recipes::bake(case_death_rate_subset) #> An `epi_df` object, 20,496 x 6 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 20,496 × 6 #> time_value geo_value case_rate death_rate gr_7_rel_change_case_rate #> * #> 1 2020-12-31 ak 35.9 0.158 NA #> 2 2020-12-31 al 65.1 0.438 NA #> 3 2020-12-31 ar 66.0 1.27 NA #> 4 2020-12-31 as 0 0 NA #> 5 2020-12-31 az 76.8 1.10 NA #> 6 2020-12-31 ca 96.0 0.751 NA #> 7 2020-12-31 co 35.8 0.649 NA #> 8 2020-12-31 ct 52.1 0.819 NA #> 9 2020-12-31 dc 31.0 0.601 NA #> 10 2020-12-31 de 65.2 0.807 NA #> # ℹ 20,486 more rows #> # ℹ 1 more variable: gr_7_rel_change_death_rate "},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_lag_difference.html","id":null,"dir":"Reference","previous_headings":"","what":"Calculate a lagged difference — step_lag_difference","title":"Calculate a lagged difference — step_lag_difference","text":"step_lag_difference() creates specification recipe step generate one new columns derived data.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_lag_difference.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Calculate a lagged difference — step_lag_difference","text":"","code":"step_lag_difference( recipe, ..., role = \"predictor\", trained = FALSE, horizon = 7, prefix = \"lag_diff_\", columns = NULL, skip = FALSE, id = rand_id(\"lag_diff\") )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_lag_difference.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Calculate a lagged difference — step_lag_difference","text":"recipe recipe object. step added sequence operations recipe. ... One selector functions choose variables step. See recipes::selections() details. role model terms created step, analysis role assigned? lag default predictor ahead outcome. trained logical indicate quantities preprocessing estimated. horizon Scalar vector. Time period(s) calculate differences. prefix prefix indicate type variable columns character string variable names populated (eventually) terms argument. skip logical. step skipped recipe baked bake()? operations baked prep() run, operations may able conducted new data (e.g. processing outcome variable(s)). Care taken using skip = TRUE may affect computations subsequent operations. id unique identifier step","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_lag_difference.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Calculate a lagged difference — step_lag_difference","text":"updated version recipe new step added sequence existing operations.","code":""},{"path":[]},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_lag_difference.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Calculate a lagged difference — step_lag_difference","text":"","code":"r <- epi_recipe(case_death_rate_subset) %>% step_lag_difference(case_rate, death_rate, horizon = c(7, 14)) r #> #> ── Recipe ────────────────────────────────────────────────────────────────────── #> #> ── Inputs #> Number of variables by role #> raw: 2 #> geo_value: 1 #> time_value: 1 #> #> ── Operations #> • Calculating lag_difference for: case_rate, death_rate by 7, 14 r %>% recipes::prep() %>% recipes::bake(case_death_rate_subset) #> An `epi_df` object, 20,496 x 8 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-31 19:08:25.791826 #> #> # A tibble: 20,496 × 8 #> time_value geo_value case_rate death_rate lag_diff_7_case_rate #> * #> 1 2020-12-31 ak 35.9 0.158 NA #> 2 2020-12-31 al 65.1 0.438 NA #> 3 2020-12-31 ar 66.0 1.27 NA #> 4 2020-12-31 as 0 0 NA #> 5 2020-12-31 az 76.8 1.10 NA #> 6 2020-12-31 ca 96.0 0.751 NA #> 7 2020-12-31 co 35.8 0.649 NA #> 8 2020-12-31 ct 52.1 0.819 NA #> 9 2020-12-31 dc 31.0 0.601 NA #> 10 2020-12-31 de 65.2 0.807 NA #> # ℹ 20,486 more rows #> # ℹ 3 more variables: lag_diff_14_case_rate , lag_diff_7_death_rate , #> # lag_diff_14_death_rate "},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_population_scaling.html","id":null,"dir":"Reference","previous_headings":"","what":"Convert raw scale predictions to per-capita — step_population_scaling","title":"Convert raw scale predictions to per-capita — step_population_scaling","text":"step_population_scaling creates specification recipe step perform per-capita scaling. Typical usage load dataset contains state-level population, use convert predictions made raw scale model rate-scale dividing population. Although, worth noting nothing special \"population\". function can used scale variable. Population standard use case epidemiology forecasting scenario. value passed divide selected variables rate_rescaling argument common multiplier selected variables.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_population_scaling.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Convert raw scale predictions to per-capita — step_population_scaling","text":"","code":"step_population_scaling( recipe, ..., role = \"raw\", trained = FALSE, df, by = NULL, df_pop_col, rate_rescaling = 1, create_new = TRUE, suffix = \"_scaled\", columns = NULL, skip = FALSE, id = rand_id(\"population_scaling\") )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_population_scaling.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Convert raw scale predictions to per-capita — step_population_scaling","text":"recipe recipe object. step added sequence operations recipe. recipe contain information epi_df column names. ... One selector functions scale variables step. See recipes::selections() details. role model terms created step, analysis role assigned? default, new columns created step original variables used predictors model. options can ard limited \"outcome\". trained logical indicate quantities preprocessing estimated. df data frame contains population data used inverting existing scaling. (possibly named) character vector variables join . NULL, default, function perform natural join, using variables common across epi_df produced predict() call user-provided dataset. columns epi_df df name (included ), .df added one user-provided data disambiguate. join different variables epi_df df, use named vector. example, = c(\"geo_value\" = \"states\") match epi_df$geo_value df$states. join multiple variables, use vector length > 1. example, = c(\"geo_value\" = \"states\", \"county\" = \"county\") match epi_df$geo_value df$states epi_df$county df$county. See dplyr::left_join() details. df_pop_col name column data frame df contains population data used scaling. one column. rate_rescaling Sometimes raw scales \"per 100K\" \"per 1M\". Adjustments can made . example, original scale \"per 100K\", set rate_rescaling = 1e5 get rates. create_new TRUE create new column keep original column epi_df suffix character. suffix added column name crete_new = TRUE. Default \"_scaled\". columns character string variable names populated (eventually) terms argument. skip logical. step skipped recipe baked bake()? operations baked prep() run, operations may able conducted new data (e.g. processing outcome variable(s)). Care taken using skip = TRUE may affect computations subsequent operations. id unique identifier step","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_population_scaling.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Convert raw scale predictions to per-capita — step_population_scaling","text":"Scales raw data population","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_population_scaling.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Convert raw scale predictions to per-capita — step_population_scaling","text":"","code":"library(epiprocess) library(epipredict) jhu <- epiprocess::jhu_csse_daily_subset %>% dplyr::filter(time_value > \"2021-11-01\", geo_value %in% c(\"ca\", \"ny\")) %>% dplyr::select(geo_value, time_value, cases) pop_data = data.frame(states = c(\"ca\", \"ny\"), value = c(20000, 30000)) r <- epi_recipe(jhu) %>% step_population_scaling(df = pop_data, df_pop_col = \"value\", by = c(\"geo_value\" = \"states\"), cases, suffix = \"_scaled\") %>% step_epi_lag(cases_scaled, lag = c(0, 7, 14)) %>% step_epi_ahead(cases_scaled, ahead = 7, role = \"outcome\") %>% step_epi_naomit() f <- frosting() %>% layer_predict() %>% layer_threshold(.pred) %>% layer_naomit(.pred) %>% layer_population_scaling(.pred, df = pop_data, by = c(\"geo_value\" = \"states\"), df_pop_col = \"value\") wf <- epi_workflow(r, parsnip::linear_reg()) %>% fit(jhu) %>% add_frosting(f) latest <- get_test_data( recipe = r, epiprocess::jhu_csse_daily_subset %>% dplyr::filter(time_value > \"2021-11-01\", geo_value %in% c(\"ca\", \"ny\")) %>% dplyr::select(geo_value, time_value, cases) ) predict(wf, latest) #> An `epi_df` object, 2 x 4 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2022-05-23 20:17:07.044666 #> #> # A tibble: 2 × 4 #> geo_value time_value .pred .pred_scaled #> * #> 1 ca 2021-12-31 4.25 84967. #> 2 ny 2021-12-31 5.93 177783."},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_training_window.html","id":null,"dir":"Reference","previous_headings":"","what":"Limits the size of the training window to the most recent observations — step_training_window","title":"Limits the size of the training window to the most recent observations — step_training_window","text":"step_training_window creates specification recipe step limits size training window n_recent recent observations time_value per group, groups formed based remaining epi_keys.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_training_window.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Limits the size of the training window to the most recent observations — step_training_window","text":"","code":"step_training_window( recipe, role = NA, trained = FALSE, n_recent = 50, epi_keys = NULL, id = rand_id(\"training_window\") )"},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_training_window.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Limits the size of the training window to the most recent observations — step_training_window","text":"recipe recipe object. step added sequence operations recipe. role used step since new variables created. trained logical indicate quantities preprocessing estimated. n_recent integer value represents number recent observations kept training window per key default value 50. epi_keys optional character vector specifying \"key\" variables group . default, NULL, ensures every key combination limited. id character string unique step identify .","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_training_window.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Limits the size of the training window to the most recent observations — step_training_window","text":"updated version recipe new step added sequence existing operations.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_training_window.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Limits the size of the training window to the most recent observations — step_training_window","text":"Note step_epi_lead() step_epi_lag() come filtering step.","code":""},{"path":"https://cmu-delphi.github.io/epipredict/reference/step_training_window.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Limits the size of the training window to the most recent observations — step_training_window","text":"","code":"tib <- tibble::tibble( x = 1:10, y = 1:10, time_value = rep(seq(as.Date(\"2020-01-01\"), by = 1, length.out = 5), times = 2), geo_value = rep(c(\"ca\", \"hi\"), each = 5)) %>% as_epi_df() epi_recipe(y ~ x, data = tib) %>% step_training_window(n_recent = 3) %>% prep(tib) %>% bake(new_data = NULL) #> An `epi_df` object, 6 x 4 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2023-10-04 21:22:11.340354 #> #> # A tibble: 6 × 4 #> time_value geo_value x y #> * #> 1 2020-01-03 ca 3 3 #> 2 2020-01-04 ca 4 4 #> 3 2020-01-05 ca 5 5 #> 4 2020-01-03 hi 8 8 #> 5 2020-01-04 hi 9 9 #> 6 2020-01-05 hi 10 10 epi_recipe(y ~ x, data = tib) %>% recipes::step_naomit() %>% step_training_window(n_recent = 3) %>% prep(tib) %>% bake(new_data = NULL) #> An `epi_df` object, 6 x 4 with metadata: #> * geo_type = state #> * time_type = day #> * as_of = 2023-10-04 21:22:11.340354 #> #> # A tibble: 6 × 4 #> time_value geo_value x y #> * #> 1 2020-01-03 ca 3 3 #> 2 2020-01-04 ca 4 4 #> 3 2020-01-05 ca 5 5 #> 4 2020-01-03 hi 8 8 #> 5 2020-01-04 hi 9 9 #> 6 2020-01-05 hi 10 10"},{"path":"https://cmu-delphi.github.io/epipredict/news/index.html","id":"epipredict-005","dir":"Changelog","previous_headings":"","what":"epipredict 0.0.5","title":"epipredict 0.0.5","text":"add smooth_quantile_reg() improved printing various methods / internals canned forecasters get class fixed quantile bug flatline_forecaster() add functionality output unfit workflow canned forecasters add pivot_quantiles() easier plotting","code":""},{"path":"https://cmu-delphi.github.io/epipredict/news/index.html","id":"epipredict-004","dir":"Changelog","previous_headings":"","what":"epipredict 0.0.4","title":"epipredict 0.0.4","text":"add quantile_reg() clean documentation bugs add smooth_quantile_reg() add classifier training window step debugged min_train_window argument removed canned forecasters","code":""},{"path":"https://cmu-delphi.github.io/epipredict/news/index.html","id":"epipredict-003","dir":"Changelog","previous_headings":"","what":"epipredict 0.0.3","title":"epipredict 0.0.3","text":"add forecasters implement postprocessing vignettes avaliable arx_forecaster pkgdown","code":""},{"path":"https://cmu-delphi.github.io/epipredict/news/index.html","id":"epipredict-0009000","dir":"Changelog","previous_headings":"","what":"epipredict 0.0.0.9000","title":"epipredict 0.0.0.9000","text":"Publish public easy navigation Two simple forecasters test beds Working vignette","code":""}]