Create, Run, and Forecast Multi-model Inference TSGLM Model Runs
Source:R/models_tsglm.R
tsglm-models.RdUsing the tscount (Liboschik et al. 2017) package to forecast time series of counts. meta_tsglm: Combines the model running with the covariate preparation functions for a multi-model tsglm (from the tscount (Liboschik et al. 2017) package) model. forecast.tsglm: A wrapper around the predict function for tsglm objects that produces a "forecast"-class object.
Usage
meta_tsglm(
ts,
model,
distr,
link,
lag,
submodels,
covariates,
metadata,
quiet = FALSE
)
# S3 method for class 'tsglm'
forecast(object, h, level, ...)Arguments
- ts
Non-negative
integer-conformable vector of rodent abundances to use in forecasting. Seeprepare_abundance.- model
A named
listof model linear predictors. Seetsglm.- distr
characterof the response distribution. Seetsglm.- link
characterof the link function. Seetsglm.- lag
integer-conformable value of the number of timesteps used in a bulk lagging for all covariates in all submodels.- submodels
listofcharactervectors defining the covariates to include in each of the submodels.- covariates
data.frameof covariates used in modeling. Seeprepare_covariates.- metadata
listof model control elements. Seeprepare_metadata.- quiet
logicalindicator controlling if messages are printed.- object
A
tsglm-class object.- h
integer-conformable number of steps forward to forecast. Passed intopredictasn.ahead.- level
numericof the confidence level to use in summarizing the predictions.- ...
Additional parameters passed into
predict.
Value
meta_tsglm: An object of class "tsglm" with additional elements defining the submodel and lag. forecast.tsglm: list with "forecast"-class with named elements including "mean", "lower", "upper", and "newxreg" (if provided for prediction) as well as the other elements returned by predict.
References
Liboschik T., K. Fokianos, and R. Fried. 2017. tscount: An R Package for Analysis of Count Time Series Following Generalized Linear Models. Journal of Statistical Software, 82:1-51. URL.
See also
Helper functions for prefab models:
prefabricated models,
runjags models
Examples
if (FALSE) { # \dontrun{
main1 <- file.path(tempdir(), "metatsglm")
setup_dir(main = main1)
dataset <- "all"
species <- "DM"
model <- "pevGARCH"
abundance <- prepare_abundance(main = main1,
dataset = dataset,
species = species,
model = model)
model_controls <- models_controls(main = main1,
models = model)[[model]]
metadata <- read_metadata(main = main1)
newmoons <- read_newmoons(main = main1)
covariates <- read_covariates(main = main1)
model <- list(past_obs = 1, past_mean = 13)
distr <- "poisson"
link <- "log"
lag <- 6
submodels <- list(c("mintemp", "ndvi"),
c("maxtemp"),
c("meantemp"),
c("precipitation"),
c(NULL))
fit_tsglm <- meta_tsglm(ts = abundance,
model = model,
distr = distr,
link = link,
lag = lag,
submodels = submodels,
covariates = covariates,
metadata = metadata,
quiet = FALSE)
newmoons_in <- match(metadata$time$forecast_newmoonnumbers - lag, covariates$newmoonnumber)
newxreg <- covariates[newmoons_in, unlist(fit_tsglm$submodel)]
forecast(object = fit_tsglm,
h = metadata$time$lead_time_newmoons,
level = metadata$confidence_level,
newxreg = newxreg)
unlink(main1, recursive = TRUE)
} # }