Description Usage Arguments Value Functions References Examples
View source: R/ITSModelingCode.R
Given a fit linear model 'fit0', generate R prediction series starting at t0. This takes model uncertainty into account by pulling from the pseudo-posterior of the model parameters (from Gelman and Hill arm package).
1 2 3 | make_many_predictions(fit0, dat, R, outcomename, t0)
make_many_predictions_plug(fit0, dat, R, outcomename, t0)
|
fit0 |
The fit linear model to simulate from. |
dat |
A dataframe with the covariates needed by the model fit0 for both pre and post-policy months. |
R |
Number of series to generate. |
outcomename |
The name of the column in dat which is our outcome. |
t0 |
Last month of pre-policy. Will start predicting at t0+1. |
A data.frame with the collection of predicted series, one row per month per replicate (so will have R*nrow(dat) rows).
make_many_predictions_plug
: This version makes multiple predictions
using estimated parameters without additional uncertainty. This takes point
estimates from the fit model as fixed parameters. WARNING: This method will
not capture true uncertainty as it is not taking parameter uncertainty into
account.
The 'arm' package, see https://cran.r-project.org/package=arm
Also see Gelman, A., & Hill, J. (2007). Data analysis using regression and multilevelhierarchical models (Vol. 1). New York, NY, USA: Cambridge University Press.
1 2 3 4 5 6 | data("mecklenberg" )
mecklenberg = add_lagged_covariates( mecklenberg, "pbail" )
mecklenberg.pre = dplyr::filter( mecklenberg, month <= 0 )
M0 = fit_model_default( mecklenberg.pre, "pbail" )
res = make_many_predictions( M0, dat=mecklenberg, outcome="pbail", t0=0, R=2 )
tail( res )
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.