## Not run:
#
#
#
# data(handy)
#
# exp <- loglin(handy, as.list(1:2), fit = TRUE)$fit
# e <- unname(tab2vec(exp))
# h <- t(t(unname(tab2vec(handy))))
# chisq <- algstat:::computeChisqsCpp(h, e)
#
# out <- hierarchical(~ Gender + Handedness, data = handy)
# chisqs <- algstat:::computeChisqsCpp(out$steps, e)
#
# mean(chisqs >= chisq)
# fisher.test(handy)$p.value
#
#
#
#
#
# A <- hmat(c(2,2), as.list(1:2))
# moves <- markov(A)
# outC <- metropolis(tab2vec(handy), moves, 1e4, engine = "Cpp")
# str(outC)
# outR <- metropolis(tab2vec(handy), moves, 1e4, engine = "R", thin = 20)
# str(outR)
#
# # showSteps(out$steps)
#
#
# library(microbenchmark)
# microbenchmark(
# metropolis(tab2vec(handy), moves, engine = "Cpp"),
# metropolis(tab2vec(handy), moves, engine = "R")
# )
#
# # cpp ~ 20-25x faster
#
#
#
#
#
#
#
#
#
#
#
#
#
# showSteps <- function(steps){
# apply(steps, 2, function(x){
# x <- format(x)
# tab <- vec2tab(x, dim(handy))
# message(
# paste(
# apply(tab, 1, paste, collapse = " "),
# collapse = " "
# )
# )
# message("
# ", appendLF = F)
# })
# invisible()
# }
# # showSteps(out$steps)
#
#
#
#
#
#
#
#
# ## End(Not run)
Run the code above in your browser using DataLab