| fit_mlvar_bayes | R Documentation |
Native, pure-R Bayesian estimator for a two-level VAR(1) that
statistically reproduces Mplus DSEM output (the estimator behind
mlVAR::mlVAR(estimator = "Mplus")) without needing Mplus installed. A
conjugate Gibbs sampler estimates a fixed temporal matrix, a within-person
residual (contemporaneous) network, and a between-person network, using
latent mean centring and Mplus's default priors. Point estimates are
posterior medians with posterior SDs and 95% credible intervals.
fit_mlvar_bayes(
data,
vars,
id,
day = NULL,
beep = NULL,
lags = 1L,
temporal = c("fixed", "default", "random"),
contemporaneous = c("fixed", "default"),
residual = c("fixed", "random"),
scale = TRUE,
scaleWithin = FALSE,
tinterval = NULL,
impute = FALSE,
n_iter = 4000L,
n_burnin = NULL,
n_chains = 2L,
thin = 1L,
seed = NULL,
min_obs = NULL,
subject = NULL,
verbose = FALSE
)
data |
A |
vars |
Character vector of variable column names to model (length >= 2). |
id |
Character string naming the person-ID column. |
day |
Character string naming the day/session column, or |
beep |
Character string naming the measurement-occasion column, or
|
lags |
Integer lag order; only |
temporal |
Character. |
contemporaneous |
Character. Only |
residual |
Character. |
scale |
Logical. Global grand-mean/SD standardization of each variable
before fitting (Mplus/ |
scaleWithin |
Logical. Additionally within-person scale each variable.
Default |
tinterval |
Numeric or |
impute |
Logical. If |
n_iter |
Integer. Total MCMC iterations per chain. Default |
n_burnin |
Integer. Burn-in iterations discarded per chain. Default
|
n_chains |
Integer. Number of independent chains. Default |
thin |
Integer. Keep every |
seed |
Integer or |
min_obs |
Integer or |
subject |
Optional vector naming the exact subject(s) to analyse. |
verbose |
Logical. Emit progress messages. Default |
The sampler alternates five conjugate full-conditional draws per
iteration: the latent person means mu_i (Gaussian), the fixed temporal
matrix B (matrix-normal), the within residual covariance Sigma_W
(inverse-Wishart), the grand mean alpha (Gaussian), and the between
covariance Sigma_B (inverse-Wishart). The lagged predictor is recentred
on the current mu_i draw every iteration (latent mean centring). Data
are globally standardized first (matching mlVAR's scale = TRUE); the
first observation of each block is used only as a lag (condition-on-first).
Validated to statistical (Monte-Carlo-error) equivalence against real
Mplus 9 DSEM output on standardized synthetic panels: posterior medians of
B, Sigma_W, Sigma_B agree with Mplus to well within a posterior SD.
A net_mlvar_bayes object (also inheriting net_mlvar), a named
list of three netobjects (temporal, contemporaneous, between) with
posterior-summary attributes. coefs() returns a tidy table with
estimate (posterior median), posterior_sd, ci_lower, ci_upper,
p (one-tailed), and significant (95% CI excludes 0). Posterior draws
and the max Gelman-Rubin PSR are kept in attributes.
fit_mlvar() (frequentist lmer path), fit_mlvar_mplus()
(true-Mplus wrapper).
set.seed(1)
n_id <- 10; n_t <- 40; vars <- c("A", "B")
rows <- lapply(seq_len(n_id), function(i) {
y <- matrix(0, n_t, 2)
for (t in 2:n_t) y[t, ] <- c(0.3, 0.15) * y[t - 1, ] + rnorm(2)
data.frame(id = i, beep = seq_len(n_t), A = y[, 1], B = y[, 2])
})
d <- do.call(rbind, rows)
fit <- fit_mlvar_bayes(d, vars = vars, id = "id", beep = "beep",
n_iter = 500, seed = 1)
print(fit)
coefs(fit)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.