p <- 8 # number of nodes
# "truK" is the precision matrix of true graph
truK <- diag(p)
for (i in 1:(p-1)) truK[i,i+1] <- truK[i+1,i] <- 0.5
truK[1,p] <- truK[p,1] <- 0.4
truK # precision matrix of the true graph
# generate the data (200 observations) from multivariate normal
# distribution with mean zero and percision matrix "truK"
data <- mvrnorm(200, c(rep(0,p)), solve(truK))
# selecting the best graph according to bdmcmc algorithm
output <- bdmcmc(data, meanzero = T, iter = 5000)
bdmcmc.g <- select.g(output)
# selecting the best graph according to glasso by using huge package
huge.g <- huge(data, method = "glasso")
huge.g <- huge.select(huge.g, criterion = "stars")
true.g <- ceiling (truK)
true.g # matrix A shows circle graph with 8 links and 8 nodes which is the true graphical model
# comparing the result by using "compare" function
compare.true <- compare(est.g = true.g, true.g = true.g)
compare.bdmcmc <- compare(est.g = bdmcmc.g, true.g = true.g)
compare.huge <- compare(est.g = huge.g$refit, true.g = true.g)
compare.all <- cbind(compare.true, compare.bdmcmc, compare.huge)
colnames(compare.all) <- c("True graph", "BDgraph", "huge")
compare.all
Run the code above in your browser using DataLab