## Not run: ------------------------------------
#
# # we set up a VAR model of 4 variables and 2 smoothly changing parameters:
# # the autocorrelation 1-> smootly increases from 0 to .8
# # the cross-correlation 2-> smootly decreases from .8 to 0
#
# #set up graph
# p <- 4 # 4 nodes
# n <- 600 # number of time steps
# graph <- matrix(0, p, p)
# k <- 15 # steepness of sigmoid function
# theta <- .8
# sigm_in <- theta * 1/ (1+ exp(-k*(seq(0,1,length=n)-.5))) # sigmoid curve
# sigm_de <- theta * 1/ (1+ exp(k*(seq(0,1,length=n)-.5)))
# graphs <- array(dim=c(p, p, n))
# graphs[,,1:n] <- graph
# graphs[1,1,] <- sigm_in # autocorrelation 1->1
# graphs[2,3,] <- sigm_de # cross correlation 2->3
#
# InnoVar <- array(data=NA, dim=c(p,1,n)) #innocation variance
# for(i in 1:n) InnoVar[,,i] <- colSums(graphs[,,i]) + 1
#
# # generate data from VAR model
# set.seed(23)
# data <- matrix(NA, n, p)
# data[1, ] <- rnorm(p, 0, InnoVar)
# for(i in 2:n) {
# for(v in 1:p) {
# data[i, v] <- sum(data[i-1,] * graphs[,v,i]) + rnorm(1,0,InnoVar[v,,i])
# }
# }
#
# head(data) # first 6 time steps
#
# # estimate
#
# type <- c('g', 'g', 'g', 'g') # four Gaussians
# lev <- c(1, 1, 1, 1)
# tsteps <- 50
#
# tv_var.obj <- tv_var.mgm(data = data,
# type = type,
# lev = lev,
# tsteps = tsteps,
# bandwidth = .8/n^(1/3),
# gam = 0,
# d = 1)
#
#
# # visual check
# plot(tv_var.obj$wadj[1,1,], xlab = 'Estimated time points', ylab = 'Edge weight',
# type = 'l', col = 'red', ylim=c(0,1), lwd=2, yaxt='n')
# lines(tv_var.obj$wadj[2,3,], col='blue', lwd=2)
# axis(side = 2, at = round(seq(0,1,length=5), 2), las=2)
# # true parameters
# tsteps <- 50
# lines( theta* 1/ (1+ exp(-k*(seq(0,1,length=tsteps)-.5))) , col='red', lty=2)
# lines( theta* 1/ (1+ exp(k*(seq(0,1,length=tsteps)-.5))), col='blue', lty=2)
#
# legend(38,.55, c('1->1 true', '1->1 estimated', '2->3 true', '2->3 estimated'), lty=c(2,1,2,1),
# col = c('red', 'red', 'blue', 'blue'), lwd=c(2,2, 2, 2))
#
#
#
#
## ---------------------------------------------
Run the code above in your browser using DataLab