rmove | R Documentation |
Generate random moves on a fiber
rmove(
n,
A,
b,
x,
method = c("sis", "walk", "hybrid"),
dist = c("uniform", "hypergeometric"),
parallel = FALSE,
format = c("mat", "vec", "tab"),
dim,
...
)
n |
the number of observations |
A |
the configuration matrix of the model defining the fiber |
b |
integer vector; the vector of sufficient statistics |
x |
integer vector; a vector in the fiber to be used as an initialization point for the "walk" method |
method |
"sis", "walk", or "hybrid" |
dist |
"uniform" or "hypergeometric" |
parallel |
parallelize the sampling? |
format |
format of the returned moves, "mat", "vec", or "tab" |
dim |
the dimensions of the table if "tab" is used, see |
... |
arguments to pass to |
a named numeric vector
David Kahle david@kahle.io, Ruriko Yoshida ruriko.yoshida@uky.edu
rfiber()
data(politics); politics
(x <- tab2vec(politics))
(A <- hmat(c(2,2), 1:2)) # independence model on 2x2 table
(b <- A %*% x) # vector of sufficient statistics
rmove(10, A = A, b = b)
## Not run: # requires 4ti2
rmove(10, A = A, x = x, method = "walk")
moves <- rmove(10000, A = A, x = x, method = "walk")
unique(t(moves))
## simple example
(A <- hmat(c(2,2), 1:2))
(x <- c(1, 3, 3, 1))
(b <- rep.int(4, 4))
rfiber(10, A = A, b = b)
(tabs <- rfiber(10, A = A, b = b, format = "vec"))
unique(tabs)
lapply(unique(tabs), vec2tab, dim = c(2, 2))
library(microbenchmark)
microbenchmark(
rmove(100, A = A, b = b),
rmove(100, A = A, x = x, method = "walk")
)
markov(A)
markov(A, "vec")
markov(A, "tab", c(2,2))
rmove(5, A, b)
rmove(5, A, b, format = "vec")
rmove(5, A, b, format = "tab", dim = c(2,2))
## politics example
data(politics); politics
tab2vec(politics)
(b <- A %*% tab2vec(politics))
(tabs <- rfiber(1000, A = A, b = b, format = "vec"))
lapply(unique(tabs), vec2tab, dim = c(2, 2))
rmove(5, A, b)
rmove(5, A, b, format = "tab", dim = c(2,2))
## parallelizing
system.time(rmove(1e4, A, b)) # ~35s
system.time(rmove(1e4, A, b, parallel = TRUE)) # ~ 8s, 8 cores
## drugs example
data(drugs)
(A <- hmat(c(2,2,2), 1:3))
(b <- A %*% tab2vec(drugs))
markovMoves <- markov(A)
rmove(5, A, b)
rmove(5, A, b, format = "tab", dim = c(2,2,2))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.