mplus.lca.summa: Summary Result Tables and Grouped Bar Charts for Latent Class...

View source: R/mplus.lca.summa.R

mplus.lca.summaR Documentation

Summary Result Tables and Grouped Bar Charts for Latent Class Analysis in Mplus

Description

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").

Usage

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)

Arguments

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 folder are extracted.

exclude

a character vector indicating the name of the subfolders excluded from the result tables.

sort.n

logical: if TRUE (default), result table is sorted according to the number of classes within each folder in increasing order.

sort.p

logical: if TRUE, model-estimated class counts, proportions, average posterior class probabilities, and odds of correct classification ratio in the classification diagnostics are sorted in increasing order.

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 p.digits minus 1 decimal places.

bf.trunc

logical: if TRUE (default), approximate Bayes factors (aBF) greater than 1000 are truncated.

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 0.9, 0.95, or 0.95 are allowed when extracting confidence intervals from Mplus outputs.

plot

logical: if TRUE, bar charts with error bars for confidence intervals for LCA with continuous, count variables are saved in the folder _Plots within subfolders.

group.ind

logical: if TRUE (default), latent class indicators are represented by separate bars when saving plots of an LCA based on continuous or count indicator variables, while latent class indicators are represented on the x-axis when saving plots of an LCA based on ordered or unordered categorical indicator, if FALSE latent classes are represented by separate bars when saving plots of an LCA based on continuous or count indicator variables, while latent classes are represented on the x-axis when saving plots of an LCA based on ordered or unordered categorical indicator.

ci

logical: if TRUE (default), confidence intervals are added to the bar charts for LCA with continuous or count indicator variables.

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 TRUE, bar charts are drawn in gray scale.

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 ".txt" (e.g., "Output.txt") or Excel file with file extension ".xlsx" (e.g., "Output.xlsx"). If the file name does not contain any file extension, an Excel file will be written.

append

logical: if TRUE (default), output will be appended to an existing text file with extension .txt specified in write, if FALSE existing text file will be overwritten.

check

logical: if TRUE (default), argument specification is checked.

output

logical: if TRUE (default), output is shown.

Details

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).

Value

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., summary for the model summaries, bf for approximate Bayes factors, classif classification diagnostics, mean_var for class-specific means and variances of the indicator variables, prob for class-specific item response probabilities of the indicator variables and d for Cohen's d standardized mean difference between latent class j and latent class k

Author(s)

Takuya Yanagida takuya.yanagida@univie.ac.at

References

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

See Also

mplus.lca, mplus.run, read.mplus, write.mplus

Examples

## 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)

misty documentation built on March 6, 2026, 9:08 a.m.

Related to mplus.lca.summa in misty...