| fit_bayesian | R Documentation |
Fits the low-rank Bayesian factor model to Q-sort data. Samples the
posterior with Stan (via cmdstanr or rstan), resolves
rotational ambiguity with MatchAlign, and returns a classed
bayesqm_fit object carrying posterior-mean loadings and factor
scores, credible intervals, raw draws, LOO, PPC, and diagnostics.
fit_bayesian(
Y,
K,
stan_dir = NULL,
robust = TRUE,
nu = "estimate",
chains = 4,
iter = 2000,
warmup = 1000,
seed = NULL,
adapt_delta = 0.9,
max_draws = 2000,
prior_loading_scale = 1,
prior_sigma_scale = 1,
prior_nu_alpha = 2,
prior_nu_beta = 0.1,
use_half_cauchy = FALSE,
prob = 0.95,
delta = NULL
)
Y |
Either a |
K |
Integer number of factors to extract. |
stan_dir |
Directory containing |
robust |
Logical; |
nu |
Either |
chains, iter, warmup |
NUTS sampler settings. |
seed |
Optional integer seed for reproducibility. |
adapt_delta |
NUTS adapt_delta target (default 0.90). |
max_draws |
Thin post-warmup draws to at most this many before MatchAlign (default 2000). |
prior_loading_scale, prior_sigma_scale, prior_nu_alpha, prior_nu_beta, use_half_cauchy |
Prior hyperparameters (see the Stan model for parameterization). |
prob |
Credible-interval probability stored on the fit (default 0.95). |
delta |
Substantive viewpoint separation for the
distinguishing/consensus probabilities. If |
A bayesqm_fit object. See bayesqm-fit-methods for print()
and summary(), and coef.bayesqm_fit() for the standard R
accessors.
Poworoznek et al. (2025). Efficiently Resolving Rotational Ambiguity in Bayesian Matrix Sampling with Matching. Bayesian Analysis.
# Needs a working Stan backend; skipped when cmdstanr/CmdStan is absent.
has_stan <- requireNamespace("cmdstanr", quietly = TRUE) &&
!inherits(try(cmdstanr::cmdstan_path(), silent = TRUE), "try-error")
if (has_stan) {
sim <- generate_data(N = 8, J = 12, K = 2, seed = 1)
fit <- fit_bayesian(sim$Y, K = 2, chains = 1, iter = 600, warmup = 300)
summary(fit)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.