# NOT RUN {
# }
# NOT RUN {
# a) Set up 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 2 categories, 2 with 5
max_level <- max(level)
lags <- c(1, 3, 9) # include lagged effects of order 1, 3, 9
n_lags <- length(lags)
# Specify thresholds
thresholds[[1]] <- c(0, 0)
thresholds[[2]] <- c(0, 0)
thresholds[[3]] <- c(0, 0, 0, 0)
thresholds[[4]] <- c(0, 0, 0, 0)
thresholds[[5]] <- c(0)
thresholds[[6]] <- c(0)
# 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)
# b) Sample
set.seed(1)
dlist <- mvarsampler(coefarray = coefarray,
lags = lags,
thresholds = thresholds,
sds = sds,
type = type,
level = level,
N = 200,
pbar = TRUE)
# c) Recover
set.seed(1)
mvar_obj <- mvar(data = dlist$data,
type = type,
level = level,
lambdaSel = 'CV',
lags = c(1, 3, 9))
# Did we recover the true parameters?
mvar_obj$wadj[5, 6, 2] # yes
mvar_obj$wadj[1, 3, 1] # yes
mvar_obj$wadj[1, 5, 3] # yes
# }
# NOT RUN {
# }
Run the code above in your browser using DataCamp Workspace