MARSScv | R Documentation |
MARSScv is a wrapper for MARSS that re-fits the model with cross validated data.
MARSScv(
y,
model = NULL,
inits = NULL,
method = "kem",
form = "marxss",
silent = FALSE,
control = NULL,
fun.kf = c("MARSSkfas", "MARSSkfss"),
fold_ids = NULL,
future_cv = FALSE,
n_future_cv = floor(ncol(y)/3),
interval = "confidence",
...
)
y |
A n x T matrix of n time series over T time steps. Only y is required for the function. A ts object (univariate or multivariate) can be used and this will be converted to a matrix with time in the columns. |
model |
Model specification using a list of parameter matrix text shortcuts or matrices.
See Details and |
inits |
A list with the same form as the list output by |
method |
Estimation method. MARSS provides an EM algorithm ( |
form |
The equation form used in the |
silent |
Setting to TRUE(1) suppresses printing of full error messages, warnings, progress bars and convergence information. Setting to FALSE(0) produces error output. Setting silent=2 will produce more verbose error messages and progress information. |
control |
Estimation options for the maximization algorithm. The typically used
control options for method="kem" are below but see marssMLE for the full
list of control options. Note many of these are not allowed if method="BFGS";
see |
fun.kf |
What Kalman filter function to use. MARSS has two:
|
fold_ids |
A n x T matrix of integers, with values assigned by the user to folds. If not included, data are randomly assigned to one of 10 folds |
future_cv |
Whether or not to use future cross validation (defaults to FALSE), where data up to
time T-1 are used to predict data at time T. Data are held out by time slices, and
the |
n_future_cv |
Number of time slices to hold out for future cross validation. Defaults to floor(n_future_cv/3). Predictions are made for the last n_future_cv time steps |
interval |
uncertainty interval for prediction. Can be one of "confidence" or "prediction", and defaults to "confidence" |
... |
not used |
A list object, containing cv_pred
(a matrix of predictions), cv_se
(a matrix of SEs),
fold_ids
(a matrix of fold ids used as data), and df
(a dataframe containing
the original data, predictions, SEs, and folds)
dat <- t(harborSealWA)
dat <- dat[2:4, ] # remove the year row
# fit a model with 1 hidden state and 3 observation time series
# cross validation here is random, 10 folds
fit <- MARSScv(dat, model = list(
Z = matrix(1, 3, 1),
R = "diagonal and equal"
))
# second, demonstrate passing in pre-specified folds
fold_ids <- matrix(
sample(1:5, size = nrow(dat) * ncol(dat), replace = TRUE),
nrow(dat), ncol(dat)
)
fit <- MARSScv(dat, model = list(
Z = matrix(1, 3, 1),
R = "diagonal and equal"
), fold_ids = fold_ids)
# third, illustrate future cross validation
fit <- MARSScv(dat, model = list(
Z = matrix(1, 3, 1),
R = "diagonal and equal"
), future_cv = TRUE, n_future_cv = 5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.