Applies nullcat() or quantize() to a community matrix, recording
a summary statistic at each iteration to help assess mixing on a given dataset.
Usage
trace_cat(
x,
fun = c("nullcat", "quantize"),
n_iter = 1000L,
thin = NULL,
n_chains = 5L,
n_cores = 1L,
stat = NULL,
seed = NULL,
plot = FALSE,
...
)Arguments
- x
Matrix of categorical data (integers) or quantitative values.
- fun
Which function to trace:
"nullcat"or"quantize".- n_iter
Total number of update iterations to simulate. Default is 1000.
- thin
Thinning interval (updates per recorded point). Default ~
n_iter/100. Smaller values increase resolution but increase run time.- n_chains
Number of independent chains to run, to assess consistency (default
5).- n_cores
Parallel chains (default
1).- stat
Function that compares
xto a permutedx_randto quantify their similarity. Either a functionf(x, x_rand)returning a scalar, orNULL. IfNULL(the default), traces use Cohen's kappa fornullcat()or Pearson's correlation forquantize().- seed
Optional integer seed for reproducible traces.
- plot
If TRUE, plot the traces.
- ...
Arguments to the chosen
fun(nullcat()orquantize()), such asmethod,n_strata,fixed, etc. Ifrow_groupsand/orcol_groupsare supplied (as vectors, or as matrices with one column per replicate), the traced chains run the grouped randomization exactly as it is used: every block is advanced by the same number of iterations, and the statistic is computed on the whole matrix, so the trace (andsuggest_n_iter()) gives the number of iterations to run per block. With a matrix of groups (e.g. tilings), the first column is used. Because every cell counts equally in the statistic, a few small blocks that mix more slowly than the rest have little influence on it. Each traced chain costs as much as one grouped randomization run forn_iteriterations (that is,n_iteriterations in every block), so with many blocks it pays not to setn_iterfar above the number expected to be needed.
Value
An object of class "cat_trace" with elements:
traces: matrix of size (n_steps+1) x n_chains, including iteration 0steps: integer vector of iteration numbers (starting at 0)fun,n_iter,thin,n_chains,n_cores,stat_name,callfun_args: list of the...used (for reproducibility)n_blocks: when groups were supplied, the number of blocks in the traced grouping; otherwiseNULL
Plotting is available via plot(cat_trace).
Examples
# nullcat trace
set.seed(123)
x <- matrix(sample(1:5, 2500, replace = TRUE), 50)
tr <- trace_cat(x, n_iter = 1000, n_chains = 5, fun = "nullcat",
method = "curvecat")
plot(tr)
# quantize trace
x <- matrix(runif(2500), 50)
tr <- trace_cat(x, n_iter = 1000, n_chains = 5, fun = "quantize",
method = "curvecat", n_strata = 3, fixed = "cell")
plot(tr)
