evaluateLags {multilevelTools} | R Documentation |
Create lag variables and evaluate models with different number of lags
Description
This function creates the desired number of lags and tests consecutive models from a model with no lags (lag 0), lag 0 + lag1, etc. and reports model performance. This helps evaluate how many lags are needed.
Usage
evaluateLags(formula, lagvar, nlags = 0L, idvar, data, ...)
Arguments
formula |
A |
lagvar |
A |
nlags |
An |
idvar |
A |
data |
A |
... |
Additional arguments passed to |
Details
Currently only linear mixed effects models are allowed.
Examples
## these examples are slow to run
data(aces_daily, package = "JWileymisc")
evaluateLags(
"NegAff ~ Female + Age + BornAUS + (1 | UserID)",
"STRESS",
4L,
"UserID",
aces_daily)
## not run, more complex example with random slope, fails to converge
evaluateLags(
"NegAff ~ Female + Age + BornAUS + (1 + STRESS | UserID)",
"STRESS",
5L,
"UserID",
aces_daily)
## use different control to fit model and now converges
strictControl <- lme4::lmerControl(optCtrl = list(
algorithm = "NLOPT_LN_NELDERMEAD",
xtol_abs = 1e-10,
ftol_abs = 1e-10))
evaluateLags(
"NegAff ~ Female + Age + BornAUS + (1 + STRESS | UserID)",
"STRESS",
5L,
"UserID",
aces_daily,
control = strictControl)