View source: R/mplus.lca.summa.R
| mplus.lca.summa | R Documentation |
This function reads all Mplus output files from latent class analysis in
subfolders to create result tables with model summaries (e.g., AIC, CAIC, BIC,
SABIC, AWE and cmP), approximate Bayes factors, classification diagnostics
(e.g., relative Entropy, AvePP, and OCC), class-specific means and variances
or class-specific item response probabilities of
the indicator variables, and Cohen's ds to quantify class separation
between latent class j and latent class k. By default, the
function reads output files in all subfolders of the current working directory
or output files in the current working directory and prints a table with model
summaries on the console. Bar charts including confidence intervals for each
latent class solution can be requested by setting the argument plot to
TRUE. Note that result tables with Bayes factors, classification diagnostics,
class-specific means and variances, class-specific item response probabilities,
and Cohen's ds will not be printed on the console, but are only available
in the exported Excel file when specifying the write argument (e.g.,
write = "Results_LCA.xlsx").
mplus.lca.summa(folder = getwd(), exclude = NULL, sort.n = TRUE, sort.p = FALSE,
digits = 0, p.digits = 3, bf.trunc = TRUE, conf.level = 0.95,
plot = FALSE, group.ind = TRUE, ci = TRUE,
axis.title = 9, axis.text = 9, levels = NULL, labels = NULL,
ylim = NULL, ylab = c("Mean Value", "Item Response Probability"),
breaks = ggplot2::waiver(), errorbar.width = 0.1,
legend.title = 9, legend.text = 9, legend.key.size = 0.5,
gray = FALSE, start = 0.15, end = 0.85, dpi = 600,
width.ind = NULL, width.nclass = NULL, height.categ = NULL,
height = NA, write = NULL, append = TRUE, check = TRUE,
output = TRUE)
folder |
a character string indicating the path of the folder
containing subfolders with the Mplus output files. By
default Mplus outputs in the subfolders of the current
working directory are read. Note that if there are no
subfolders available, Mplus outputs from the folder
specified in the argument |
exclude |
a character vector indicating the name of the subfolders excluded from the result tables. |
sort.n |
logical: if |
sort.p |
logical: if |
digits |
an integer value indicating the number of decimal places to be used for displaying LL, AIC, CAIC, BIC, SABIC, AWE, OCC, and approximate Bayes factors (aBF). |
p.digits |
an integer value indicating the number of decimal places
to be used for displaying cmP, p-values, relative entropy
values, class proportions, and confidence intervals. Note that the scaling
correction factor is displayed with |
bf.trunc |
logical: if |
conf.level |
a numeric value between 0 and 1 indicating the confidence
level of the intervals in the result table with means
and variances for each latent class separately. Note
that only |
plot |
logical: if |
group.ind |
logical: if |
ci |
logical: if |
axis.title |
a numeric value specifying the size of the axis title. |
axis.text |
a numeric value specifying the size of the axis text |
levels |
a character string specifying the order of the indicator variables shown on the x-axis. |
labels |
a character string specifying the labels of the indicator variables shown on the x-axis. |
ylim |
a numeric vector of length two specifying limits of the y-axis. |
ylab |
a character string specifying the label of the y-axis. |
breaks |
a numeric vector specifying the points at which tick-marks are drawn at the y-axis. |
errorbar.width |
a numeric vector specifying the width of the error bars. By default, the width of the error bars is 0.1 plus number of classes divided by 30. |
legend.title |
a numeric value specifying the size of the legend title. |
legend.text |
a numeric value specifying the size of the legend text. |
legend.key.size |
a numeric value specifying the size of the legend keys. |
gray |
logical: if |
start |
a numeric value between 0 and 1 specifying the gray value at the low end of the palette. |
end |
a numeric value between 0 and 1 specifying the gray value at the high end of the palette. |
dpi |
a numeric value specifying the plot resolution when saving the bar chart. |
width.ind |
a numeric value specifying the width of the plot as a factor depending on the number of indicator variables. By default, the factor is 1.5. |
width.nclass |
a numeric value specifying the width of the plot as a factor depending on the number of classes. By default, the factor is 0.5 when saving plots of an LCA based on continuous or count indicator variables, while the factor is 1.5 when saving plots of an LCA based on ordered or unordered categorical indicator variables. |
height.categ |
a numeric value specifying the height of the plot as a factor depending on the number of response categories. By default, the factor is 0.6. Note that this argument is used only when saving plots of an LCA based on ordered or unordered categorical indicator variables. |
height |
a numeric value specifying the height of the plot when saving the bar chart. Note that this argument is used only when saving plots of an LCA based on continuous or count indicator variables. |
write |
a character string naming a file for writing the output into
either a text file with file extension |
append |
logical: if |
check |
logical: if |
output |
logical: if |
The Excel file exported by the function for reading Mplus output files from
latent class analysis with continuous or count indicator variables by
specifying the write argument (e.g., write = "Results_LCA.xlsx")
contains five sheets.
(1) Summary: Model Summaries
"Folder": Subfolder from which the group of Mplus outputs files
were summarized
"#Class": Number of latent classes, i.e., CLASSES ARE c(#Class)
"Conv": Model converged, TRUE or FALSE, i.e.,
THE MODEL ESTIMATION TERMINATED NORMALLY
"#Param": Number of estimated parameters, i.e., Number of Free Parameters
"logLik": Log-likelihood of the estimated model, i.e., H0 Value
"Scale": Scaling correction factor, i.e., H0 Scaling Correction Factor for,
available only when ESTIMATOR IS MLR
"LLRep": Best log-likelihood replicated, TRUE or FALSE,
i.e., THE BEST LOGLIKELIHOOD VALUE HAS BEEN REPLICATED
"AIC": Akaike information criterion, i.e., Akaike (AIC)
"CAIC": Consistent AIC, not reported in the Mplus output, but
simply BIC + #Param
"BIC": Bayesian information criterion, i.e., Bayesian (BIC)
"SABIC": Sample-size adjusted BIC, i.e., Sample-Size Adjusted BIC
"AWE": Approximate weight of evidence criterion (Banfield & Raftery, 1993)
"cmP": Approximate correct model probability (Schwarz, 1978)
across estimated models in all Mplus output files in
the subfolders to create result tables
"Chi-Pear": Pearson chi-square test of model fit, i.e., Pearson Chi-Square,
available only when indicators are count or ordered categorical
"Chi-LRT": Likelihood ratio chi-square test of model fit, i.e., Likelihood Ratio Chi-Square,
available only when indicators are count or ordered categorical
"LMR-LRT": Significance value (p-value) of the Vuong-Lo-Mendell-Rubin test,
i.e., VUONG-LO-MENDELL-RUBIN LIKELIHOOD RATIO TEST,
available only when OUTPUT: TECH11
"A-LRT": Significance value (p-value) of the Adjusted Lo-Mendell-Rubin Test,
i.e., LO-MENDELL-RUBIN ADJUSTED LRT TEST,
available only when OUTPUT: TECH11
"BLRT": Significance value (p-value) of the bootstrapped
likelihood ratio test, available only when OUTPUT: TECH14
"Entropy": Summary of the class probabilities across classes
and individuals in the sample, i.e., Entropy
"aPPMin": Minimum average posterior class probability (AvePP)
for the latent classes
"OCCMin": Minimum odds of correct classification ratio (OCC)
"nMin": Minimum class count for the latent classes based on
the estimated model
"pMin": Minimum class proportion for the latent classes based
on the estimated model
(2) aBF: Approximate Bayes Factors
"A-Folder": Subfolder from which the group of Mplus outputs files
for Model A were summarized
"A-#Class": Number of latent classes for Model A, i.e., CLASSES ARE c(#Class)
"A-BIC": Bayesian information criterion for Model A, i.e., Bayesian (BIC)
"B-Folder": Subfolder from which the group of Mplus outputs files
for Model B were summarized
"B-#Class": Number of latent classes for Model B, i.e., CLASSES ARE c(#Class)
"B-BIC": Bayesian information criterion for Model B, i.e., Bayesian (BIC)
"aBF": Approximate Bayes Factor for pairwise comparison of relative fit
between Model A and Model B, i.e., ratio of the probability of
Model A being correct model to Model B being the correct model
(3) Classif: Classification Diagnostics
"Folder": Subfolder from which the group of Mplus outputs files
were summarized
"#Class": Number of latent classes, i.e., CLASSES ARE c(#Class).
"Conv": Model converged, TRUE or FALSE, i.e.,
THE MODEL ESTIMATION TERMINATED NORMALLY.
"#Param": Number of estimated parameters, i.e.,
Number of Free Parameters
"LLRep": Best log-likelihood replicated, TRUE or FALSE,
i.e., THE BEST LOGLIKELIHOOD VALUE HAS BEEN REPLICATED
"n1": Class count for the first latent class based on the estimated model,
i.e., FINAL CLASS COUNTS AND PROPORTIONS
"n2": Class count for the second latent class based on the estimated model,
i.e., FINAL CLASS COUNTS AND PROPORTIONS
"p1": Class proportion of the first class based on the estimated
posterior probabilities, i.e., FINAL CLASS COUNTS AND PROPORTIONS
"p2": Class proportion of the second class based on the estimated
posterior probabilities, i.e., FINAL CLASS COUNTS AND PROPORTIONS
"Entropy": Summary of the class probabilities across classes
and individuals in the sample, i.e., Entropy
"aPP1": Average posterior class probability (AvePP) of the
first latent class for the latent classes
"aPP2": Average posterior class probability (AvePP) of the
second latent class for the latent classes
"OCC1": Odds of correct classification ratio (OCC) of the
first latent class
"OCC2": Odds of correct classification ratio (OCC) of the
second latent class
(4) Mean_Var: Means and Variances for each Latent Class Separately
"Folder": Subfolder from which the group of Mplus outputs files
were summarized
"#Class": Number of latent classes, i.e., CLASSES ARE c(#Class)
"n": Class counts based on the estimated model,
i.e., FINAL CLASS COUNTS AND PROPORTIONS
"Param": Parameter, i.e., mean or variance
"Ind": Latent class indicator variable
"Est.": Parameter estimate.
"SE": Standard error
"z": Test statistic
"pval": Significance value
"Low": Lower bound of the confidence interval
"Upp": Upper bound of the confidence interval
(5) d: Cohen's d
"Folder": Subfolder from which the group of Mplus outputs files
were summarized
"#Class": Number of latent classes, i.e., CLASSES ARE c(#Class)
"Ind": Latent class indicator variable
"Class.j": Number of classes for model j
"Class.k": Number of classes for model k
"n.j": Latent classes j
"M.j": Class-specific mean of the indicator for the latent class j
"SD.j": Class-specific standard deviation of the indicator for the latent class j
"n.k": Latent classes k
"M.k": Class-specific mean of the indicator for the latent class k
"SD.k": Class-specific standard deviation of the indicator for the latent class k
"d": Cohen's d, Standardized mean difference
For more info on fit indices, classification diagnostics, and evaluating class separation see Masyn (2013) and Sorgente et al. (2025).
Returns an object of class misty.object, which is a list with following
entries:
call |
function call |
type |
type of analysis |
output |
list with all Mplus outputs |
args |
specification of function arguments |
result |
list with result tables, i.e., |
Takuya Yanagida takuya.yanagida@univie.ac.at
Banfield, J. D., & Raftery, A E. (1993). Model-based Gaussian and non-Gaussian clustering. Biometrics, 49, 803-821.
Masyn, K. E. (2013). Latent class analysis and finite mixture modeling. In T. D. Little (Ed.), The Oxford handbook of quantitative methods: Statistical analysis (pp. 551–611). Oxford University Press.
Muthen, L. K., & Muthen, B. O. (1998-2017). Mplus User's Guide (8th ed.). Muthen & Muthen.
Schwartz, G. (1978). Estimating the dimension of a model. The Annals of Statistics, 6, 461-464.
Sorgente, A., Caliciuri, R., Robba, M., Lanz, M., & Zumbo, B. D. (2025) A systematic review of latent class analysis in psychology: Examining the gap between guidelines and research practice. Behavior Research Methods, 57(11), 301. https://doi.org/10.3758/s13428-025-02812-1
mplus.lca, mplus.run, read.mplus,
write.mplus
## Not run:
# Load data set "HolzingerSwineford1939" in the lavaan package
data("HolzingerSwineford1939", package = "lavaan")
# Run LCA with k = 1 to k = 6 classes
mplus.lca(HolzingerSwineford1939, ind = c("x1", "x2", "x3", "x4"),
mplus.run = TRUE)
# Example 1a: Read Mplus output files, create result table, write table, and save plots
mplus.lca.summa(write = "Results_LCA.xlsx", plot = TRUE)
# Example 1b: Write results into a text file
mplus.lca.summa(write = "Results_LCA.txt")
#-------------------------------------------------------------------------------
# Example 2: Draw bar chart manually
library(ggplot2)
# Collect LCA results
lca.result <- mplus.lca.summa()
# Result table with means
means <- lca.result$result$mean
# Extract results from variance-covariance structure A with 4 latent classes
plotdat <- means[means$folder == "A_Invariant-Theta_Diagonal-Sigma" & means$nclass == 4, ]
# Draw bar chart
ggplot(plotdat, aes(ind, est, group = class, fill = class)) +
geom_bar(stat = "identity", position = "dodge", color = "black",
linewidth = 0.1) +
geom_errorbar(aes(ymin = low, ymax = upp), width = 0.23,
linewidth = 0.2, position = position_dodge(0.9)) +
scale_x_discrete("") +
scale_y_continuous("Mean Value", limits = c(0, 9),
breaks = seq(0, 9, by = 1)) +
labs(fill = "Latent Class") +
guides(fill = guide_legend(nrow = 1L)) +
theme(axis.title = element_text(size = 11),
axis.text = element_text(size = 11),
legend.position = "bottom",
legend.key.size = unit(0.5 , 'cm'),
legend.title = element_text(size = 11),
legend.text = element_text(size = 11),
legend.box.spacing = unit(-9L, "pt"))
# Save bar chart
ggsave("LCA_4-Class.png", dpi = 600, width = 6, height = 4)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.