| simulate_dynamic_multinomial | R Documentation |
Generates K - 1 independent latent additive-log-ratio (ALR) processes
(random walk or AR(1)), one per non-baseline category, and multinomial
choice counts with known totals. The ALR series
z_{t,k} = \log(p_{t,k} / p_{t,b}) share no parameters: sigma,
rho and mu may each be a single value (recycled) or a vector of length
K - 1 giving one value per non-baseline category.
simulate_dynamic_multinomial(
n,
sigma,
trials,
alr0 = c(0, 0),
baseline = length(alr0) + 1L,
rho = 1,
mu = 0,
offset = 0,
categories = NULL,
seed = NULL
)
n |
Number of observations. |
sigma |
Standard deviation(s) of the latent increments (Gaussian);
length 1 or |
trials |
Total count per period: a single number (recycled) or a
length- |
alr0 |
Numeric vector of length |
baseline |
The baseline category: a column index in |
rho |
AR(1) coefficient(s) of the latent processes
|
mu |
Drift (random walk) / intercept (AR(1)) of the latent processes;
length 1 or |
offset |
Known offset on the ALR scale: a scalar, a length
|
categories |
Optional character vector of length |
seed |
Optional random seed. The previous state of the global random number generator is restored afterwards. |
A list with components y (an n x K matrix of counts with the
baseline in column baseline), trials, alr (the n x (K - 1) latent
ALR paths z_{t,k}), prob (the n x K matrix of category
probabilities), offset, baseline (the column index) and categories.
sim <- simulate_dynamic_multinomial(n = 50, sigma = 0.15, trials = 200,
alr0 = c(-0.5, 0.5), seed = 1)
head(sim$y)
colSums(sim$y)
# fit on the simulated ALR scale by passing the simulated baseline
fit <- fit_dynamic_model(sim$y, family = "multinomial", baseline = sim$baseline,
nsave = 200, nburn = 100, seed = 1)
summary(fit)$params
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.