Unlimited learning, half price | 50% off

Last chance! 50% off unlimited learning

Sale ends in


mlVAR (version 0.1.0)

mlVAR: Multilevel VAR Estimation for Multiple Time Series

Description

The function mlVAR computes estimates of the multivariate vector autoregression model as introduced by Bringmann et al. (2013) which can be extended through treatment effects, covariates and pre- and post assessment effects.

Usage

mlVAR(data, vars, idvar, dayvar, beepvar, periodvar, lags = 1, treatmentvar, covariates, 
        control = list(optimizer = "bobyqa"))

Arguments

data
Data frame
vars
Vectors of variables to include in the analysis
idvar
String indicating the subject ID
dayvar
String indicating assessment day (if missing, every assessment is set to one day)
beepvar
String indicating assessment beep per day (if missing, is added)
periodvar
String indicating the period (baseline, treatment period, etc.) of assessment (if missing, every assessment is set to one period)
lags
Vector indicating the lags to include
treatmentvar
Character vector indicating treatment
covariates
Character indicating covariates independent of assessment.
control
A list of arguments sent to lmerControl

Value

  • mlVAR returns a 'mlVAR' object containing
  • fixedEffectsA matrix that contains all fixed effects coefficients with dependent variables as rows and the lagged independent variables as columns.
  • se.fixedEffectsA matrix that contains all standard errors of the fixed effects.
  • randomEffectsA list of matrices that contain the random effects coefficients.
  • randomEffectsVarianceA matrix containing the estimated variances between the random-effects terms
  • pvalsA matrix that contains p-values for all fixed effects.
  • pseudologlikThe pseudo log-likelihood.
  • BICBayesian Information Criterion, i.e. the sum of all univariate models' BICs
  • inputList containing the names of variables used in the analysis

Details

mlVAR has been built to extract individual network dynamics by estimating a multilevel vector autoregression model that models the time dynamics of selected variables both within an individual and on group level. For example, in a lag-1-model each variable at time point t is regressed to a lagged version of itself at time point t-1 and all other variables at time point t-1. In psychological research, for example, this analysis can be used to relate the dynamics of symptoms on one day (as assessed by experience sampling methods) to the dynamics of these symptoms on the consecutive day.

References

Bringmann, L. F., Vissers, N., Wichers, M., Geschwind, N., Kuppens, P., Peeters, F., Borsboom, D. and Tuerlinckx, F. (2013). A network approach to psychopathology: New insights into clinical longitudinal data. PloS one, 8(4): e60188.

See Also

fixedEffects, fixedEffects

Examples

Run this code
# True L1 structure:
L1 <- matrix(c(
  0.5,0.25,0,
  0,0.5,0.25,
  0,0,0.5),3,3,byrow=TRUE)

# True L2 structure:
L2 <- matrix(c(
  0.1,0,-0.2,
  0,0.1,0,
  0,0,0.1),3,3,byrow=TRUE)

# Error variance:
error <- 0.1

# Number of subjects:
Np <- 10

# Number of measurements per subject:
Nt <- 30

# Generate random effects:
L1_RF <- lapply(1:Np, function(x) L1 + rnorm(prod(dim(L1)),0,error))
L2_RF <- lapply(1:Np, function(x) L2 + rnorm(prod(dim(L1)),0,error))

# Generate data:
Data <- do.call(rbind,lapply(1:Np, function(p) {
  subjectData <- simulateVAR(list(L1_RF[[p]], L2_RF[[p]]), 1:2, 100)
  names(subjectData) <- paste0("x",1:3)
  subjectData$ID <- p
  subjectData
  }))

# Run analysis:
Res <- mlVAR(Data, paste0('x',1:3), "ID", lags = c(1, 2))

  library("qgraph")
  
  # Plot true fixed VAR network vs estimated fixed VAR network:
  # Lag-1
  layout(t(1:2))
  qgraph(t(L1), labels = paste0('x',1:3), layout = "circle", title = "True Lag-1", diag = TRUE,
         mar = c(8,8,8,8))
  plot(Res, "fixed", lag=1, labels = paste0('x',1:3), layout = "circle", title = "Estimated Lag-1",
       mar = c(8,8,8,8))
  
  # Lag-2
  layout(t(1:2))
  qgraph(t(L2), labels = paste0('x',1:3), layout = "circle", title = "True Lag-2", diag = TRUE,
         mar = c(8,8,8,8))
  plot(Res, "fixed", lag=2, labels = paste0('x',1:3), layout = "circle", title = "Estimated Lag-2",
       mar = c(8,8,8,8))

Run the code above in your browser using DataLab