# \donttest{
set.seed(1)
n = 4000
d = 2
X = cbind(rnorm(n), rnorm(n))
alphabet = 0:2 ### state space
y = sample(alphabet,2, replace = TRUE)
for (i in 3:n)
{
if (identical(as.numeric(y[(i-1):(i-2)]), c(0,0)))
value = c(exp(-0.5 + -1*X[i-1,1] + 2.5*X[i-1,2]),
exp(0.5 + -2*X[i-1,1] - 3.5*X[i-1,2]))
else if (identical(as.numeric(y[(i-1):(i-2)]), c(0,1)))
value = c(exp(-0.5), exp(0.5))
else
value = c(runif(1,0,3), runif(1,0,3))
prob = c(1,value)/(1 + sum(value)) ## compute probs with baseline state probability
y[i] = sample(alphabet,1,prob=prob)
}
tree = NULL
tree$context = "x" ## this is the root
tree$alpha = NULL
tree$beta = NULL
tree$child = list()
this_child = NULL
this_child$context = "0"
this_child$alpha = 0
this_child$child = list()
tree$child[[1]] = this_child
this_grandchild = NULL
this_grandchild$context = c(0, 0)
this_grandchild$alpha = 0
this_grandchild$beta = array(c(0,0,0,0),c(1, 2, 2)) ## steps, d, alphabet (state space)
this_grandchild$child = list()
tree$child[[1]]$child[[1]] = this_grandchild
this_other_grandchild = NULL
this_other_grandchild$context = c(0, 1)
this_other_grandchild$alpha = 0
this_other_grandchild$beta = NULL
this_other_grandchild$child = list()
tree$child[[1]]$child[[2]] = this_other_grandchild
estimate(tree, y, X)
fit = VLMCX(y, X, alpha.level = 0.0001, max.depth = 2, n.min = 15, trace = TRUE)
estimate(fit$tree, y, X)
# }
Run the code above in your browser using DataLab