Sampling from a mixed VAR model
Function to sample from a mixed VAR (mVAR) model
mvarsampler(coefarray, lags, thresholds, sds, type, level, N, pbar)
coefarray |
A p x p x max(level) x max(level) x n_lags array, where p are the number of variables, level is the input argument |
lags |
A vector indicating the lags in the mVAR model. E.g. |
thresholds |
A list with p entries, each consisting of a vector indicating a threshold for each category of the given variable. For continuous variable, the vector has length 1. |
sds |
A vector of length p indicating the standard deviations of the included Gaussian nodes. If non-Gaussian variables are included in the mVAR model, the corresponding entries are ignored. |
type |
p vector indicating the type of variable for each column in |
level |
p vector indicating the number of categories of each variable. For continuous variables set to 1. |
N |
The number of samples to be drawn from the specified mVAR model. |
pbar |
If |
We sample from the mVAR model by separately sampling from its corresponding p conditional distributions.
A list with two entries:
call |
The function call |
data |
The sampled n x p data matrix |
Jonas Haslbeck <jonashaslbeck@gmail.com>
Haslbeck, J. M. B., & Waldorp, L. J. (2020). mgm: Estimating time-varying Mixed Graphical Models in high-dimensional Data. Journal of Statistical Software, 93(8), pp. 1-46. DOI: 10.18637/jss.v093.i08
## Not run: ## Generate data from mixed VAR model using mvarsampler() and recover model using mvar() # 1) Define mVAR model p <- 6 # Six variables type <- c("c", "c", "c", "c", "g", "g") # 4 categorical, 2 gaussians level <- c(2, 2, 4, 4, 1, 1) # 2 categoricals with m=2, 2 categoricals with m=4, two continuous max_level <- max(level) lags <- c(1, 3, 9) # include lagged effects of order 1, 3, 9 n_lags <- length(lags) # Specify thresholds thresholds <- list() thresholds[[1]] <- rep(0, level[1]) thresholds[[2]] <- rep(0, level[2]) thresholds[[3]] <- rep(0, level[3]) thresholds[[4]] <- rep(0, level[4]) thresholds[[5]] <- rep(0, level[5]) thresholds[[6]] <- rep(0, level[6]) # Specify standard deviations for the Gaussians sds <- rep(NULL, p) sds[5:6] <- 1 # Create coefficient array coefarray <- array(0, dim=c(p, p, max_level, max_level, n_lags)) # a.1) interaction between continuous 5<-6, lag=3 coefarray[5, 6, 1, 1, 2] <- .4 # a.2) interaction between 1<-3, lag=1 m1 <- matrix(0, nrow=level[2], ncol=level[4]) m1[1,1:2] <- 1 m1[2,3:4] <- 1 coefarray[1, 3, 1:level[2], 1:level[4], 1] <- m1 # a.3) interaction between 1<-5, lag=9 coefarray[1, 5, 1:level[1], 1:level[5], 3] <- c(0, 1) # 2) Sample set.seed(1) dlist <- mvarsampler(coefarray = coefarray, lags = lags, thresholds = thresholds, sds = sds, type = type, level = level, N = 200, pbar = TRUE) # 3) Recover set.seed(1) mvar_obj <- mvar(data = dlist$data, type = type, level = level, lambdaSel = "CV", lags = c(1, 3, 9), signInfo = FALSE, overparameterize = F) # Did we recover the true parameters? mvar_obj$wadj[5, 6, 2] # cross-lagged effect of 6 on 5 over lag lags[2] mvar_obj$wadj[1, 3, 1] # cross-lagged effect of 3 on 1 over lag lags[1] mvar_obj$wadj[1, 5, 3] # cross-lagged effect of 1 on 5 over lag lags[3] # For more examples see https://github.com/jmbh/mgmDocumentation ## End(Not run)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.