forecast | R Documentation |
Forecast using branching processes at a target date
forecast(
obs,
forecast_date = max(obs$date),
seq_date = forecast_date,
case_date = forecast_date,
data_list = forecast.vocs::fv_as_data_list,
inits = forecast.vocs::fv_inits,
fit = forecast.vocs::fv_sample,
posterior = forecast.vocs::fv_tidy_posterior,
extract_forecast = forecast.vocs::fv_extract_forecast,
horizon = 4,
r_init = c(0, 0.25),
r_step = 1,
r_forecast = TRUE,
beta = c(0, 0.1),
lkj = 0.5,
period = NULL,
special_periods = c(),
voc_scale = c(0, 0.2),
voc_label = "VOC",
strains = 2,
variant_relationship = "correlated",
overdispersion = TRUE,
models = NULL,
likelihood = TRUE,
output_loglik = FALSE,
debug = FALSE,
keep_fit = TRUE,
scale_r = 1,
digits = 3,
timespan = 7,
probs = c(0.05, 0.2, 0.8, 0.95),
id = 0,
...
)
obs |
A |
forecast_date |
Date at which to forecast. Defaults to the
maximum date in |
seq_date |
Date from which to use available sequence data. Defaults to
the |
case_date |
Date from which to use available case data. Defaults to
the |
data_list |
A function that returns a list of data as ingested by the
|
inits |
A function that returns a function to samples initial
conditions with the same arguments as |
fit |
A function that fits the supplied model with the same arguments
and return values as |
posterior |
A function that summarises the output from the supplied
fitting function with the same arguments and return values (depending on
the requirement for downstream package functionality to function) as
|
extract_forecast |
A function that extracts the forecast from
the summarised |
horizon |
Integer forecast horizon. Defaults to 4. |
r_init |
Numeric vector of length 2. Mean and standard deviation for the normal prior on the initial log growth rate. |
r_step |
Integer, defaults to 1. The number of observations between each change in the growth rate. |
r_forecast |
Logical, defaults |
beta |
Numeric vector, defaults to c(0, 0.5). Represents the mean and standard deviation of the normal prior (truncated at 1 and -1) on the weighting in the differenced AR process of the previous difference. Placing a tight prior around zero effectively reduces the AR process to a random walk on the growth rate. |
lkj |
Numeric defaults to 0.5. The assumed prior covariance between variants growth rates when using the "correlated" model. This sets the shape parameter for the Lewandowski-Kurowicka-Joe (LKJ) prior distribution. If set to 1 assigns a uniform prior for all correlations, values less than 1 indicate increased belief in strong correlations and values greater than 1 indicate increased belief weaker correlations. Our default setting places increased weight on some correlation between strains. |
period |
Logical defaults to |
special_periods |
A vector of dates to pass to the |
voc_scale |
Numeric vector of length 2. Prior mean and standard deviation for the initial growth rate modifier due to the variant of concern. |
voc_label |
A character string, default to "VOC". Defines the label to assign to variant of concern specific parameters. Example usage is to rename parameters to use variant specific terminology. |
strains |
Integer number of strains to use. Defaults to 2. Current maximum is 2. A numeric vector can be passed if forecasts from multiple strain models are desired. |
variant_relationship |
Character string, defaulting to "correlated". Controls the relationship of strains with options being "correlated" (strains growth rates are correlated over time), "scaled" (a fixed scaling between strains), and "independent" (fully independent strains after initial scaling). |
overdispersion |
Logical, defaults to |
models |
A model as supplied by |
likelihood |
Logical, defaults to |
output_loglik |
Logical, defaults to |
debug |
Logical, defaults to |
keep_fit |
Logical, defaults to |
scale_r |
Numeric, defaults to 1. Rescale the timespan over which the growth rate and reproduction number is calculated. An example use case is rescaling the growth rate from weekly to be scaled by the mean of the generation time (for COVID-19 for example this would be 5.5 / 7. |
digits |
Numeric, defaults to 3. Number of digits to round summary statistics to. |
timespan |
Integer, defaults to 7. Indicates the number of days between each observation. Defaults to a week. |
probs |
A vector of numeric probabilities to produce
quantile summaries for. By default these are the 5%, 20%, 80%,
and 95% quantiles which are also the minimum set required for
plotting functions to work (such as |
id |
ID to assign to this forecast. Defaults to 0. |
... |
Additional parameters passed to |
A data.frame
containing the output of fv_sample()
in each row as
well as the summarised posterior, forecast and information about the
parameters specified.
Functions used for forecasting across models, dates, and scenarios
forecast_across_dates()
,
forecast_across_scenarios()
,
forecast_n_strain()
,
plot.fv_forecast()
,
summary.fv_forecast()
,
unnest_posterior()
options(mc.cores = 4)
forecasts <- forecast(
germany_covid19_delta_obs,
forecast_date = as.Date("2021-06-12"),
horizon = 4,
strains = c(1, 2),
adapt_delta = 0.99,
max_treedepth = 15,
variant_relationship = "scaled"
)
# inspect forecasts
forecasts
# extract the model summary
summary(forecasts, type = "model")
# plot case posterior predictions
plot(forecasts, log = TRUE)
# plot voc posterior predictions
plot(forecasts, type = "voc_frac")
# extract the case forecast
summary(forecasts, type = "cases", forecast = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.