View source: R/mixture-regression-enumerate.R
| enumerate_regressions | R Documentation |
Fits mixture_regression() for every requested number of classes (and of group
classes, for the two-level model) and returns their fit statistics in one
table. Optionally adds a parametric bootstrap likelihood-ratio test of
k - 1 against k classes (McLachlan 1987; Nylund, Asparouhov and Muthen
2007): outcomes are simulated from the k - 1 class fit, both models are
refitted to every replicate, and the p-value is the share of replicate
statistics at least as large as the observed one, (1 + b) / (1 + B).
enumerate_regressions(
formula,
data,
n_classes = 1:4,
n_group_classes = 1L,
bootstrap = 0L,
bootstrap_starts = 3L,
seed = NULL,
...
)
## S3 method for class 'latents_regression_enumeration'
as.data.frame(x, row.names = NULL, optional = FALSE, ...)
## S3 method for class 'latents_regression_enumeration'
get_results(
x,
what = c("fit", "model"),
n_classes = NULL,
n_group_classes = 1L,
...
)
## S3 method for class 'latents_regression_enumeration'
print(x, digits = 4L, ...)
formula |
A model formula |
data |
A data frame. |
n_classes |
Integer vector of class counts to fit. |
n_group_classes |
Integer vector of group-class counts (two-level
model; needs |
bootstrap |
Number of bootstrap replicates for the likelihood-ratio
test; |
bootstrap_starts |
Random starts for each bootstrap refit. |
seed |
|
... |
Further arguments to |
x |
A |
row.names, optional |
Unused; part of the generic. |
what |
|
digits |
Significant digits. |
An object of class latents_regression_enumeration. Its table (from
as.data.frame() or get_results(x, "fit")) has one row per model:
n_classes, n_group_classes, log_likelihood, n_parameters,
aic, bic, bic_rows, sabic, icl, entropy, smallest_share,
converged, n_best_replicated, best_bic (the minimum-BIC row), and,
with bootstrap > 0, blrt_statistic, blrt_p_value and
blrt_replicates (the successful replicates) and blrt_flagged (the
failed, unconverged, separated or reversed-likelihood replicates). The
p-value is NA if any requested replicate fails validation. get_results(x, "model", n_classes = , n_group_classes = ) returns one fitted model.
latents_bad_argument for an empty or invalid grid. A model that cannot
be fitted at some count (for example every start degenerates) gets a row
of NA with its condition message in note, rather than stopping the
comparison.
McLachlan, G. J. (1987). On bootstrapping the likelihood ratio test statistic for the number of components in a normal mixture. Applied Statistics, 36, 318–324.
Nylund, K. L., Asparouhov, T., & Muthen, B. O. (2007). Deciding on the number of classes in latent class analysis and growth mixture modeling: A Monte Carlo simulation study. Structural Equation Modeling, 14, 535–569.
classes <- enumerate_regressions(score ~ hours, data = study_hours,
n_classes = 1:3, n_starts = 3, seed = 1)
classes
with_test <- enumerate_regressions(score ~ hours, data = study_hours,
n_classes = 1:2, n_starts = 3, seed = 1,
bootstrap = 19)
as.data.frame(with_test)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.