Last chance! 50% off unlimited learning
Sale ends in
This function reads all Mplus output files from latent class analysis in
subfolders to create a summary result table and bar charts for each latent
class solution separately. By default, the function reads output files in all
subfolders of the current working directory. Optionally, bar charts for each
latent class solution can be requested by setting the argument plot
to TRUE
. Note that subfolders with only one Mplus output file are
excluded.
result.lca(folder = getwd(), exclude = NULL, sort.n = TRUE, sort.p = TRUE,
plot = FALSE, group.ind = TRUE, ci = TRUE, conf.level = 0.95, adjust = TRUE,
axis.title = 7, axis.text = 7, levels = NULL, labels = NULL,
ylim = NULL, ylab = "Mean Value", breaks = ggplot2::waiver(),
error.width = 0.1, legend.title = 7, legend.text = 7, legend.key.size = 0.4,
gray = FALSE, start = 0.15, end = 0.85, dpi = 600,
width = "n.ind", height = 4, digits = 1, p.digits = 3,
write = NULL, append = TRUE, check = TRUE, output = TRUE)
Returns an 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
summary result table, mean_var
for the result
table with means and variances for each latent class
separately, mean
for the result table with means
for each latent class separately, and var
for the
result table with variances for each latent class separately
a character vector indicating the name of the subfolders to be excluded from the summary result table.
a character vector indicating the name of the subfolders excluded from the result tables.
logical: if TRUE
(default), result table is sorted
according to the number of classes within each folder.
logical: if TRUE
(default), class proportions are
sorted decreasing.
logical: if TRUE
, bar charts with
error bars for confidence intervals are saved
in the folder _Plots
within subfolders. Note
that plots are only available for LCA with continuous
or count indicator variables.
logical: if TRUE
(default), latent class indicators
are represented by separate bars, if FALSE
latent classes
are represented by separate bars.
logical: if TRUE
(default), confidence intervals
are added to the bar charts.
a numeric value between 0 and 1 indicating the confidence level of the interval.
logical: if TRUE
(default), difference-adjustment
for the confidence intervals is applied.
a numeric value specifying the size of the axis title.
a numeric value specifying the size of the axis text
a character string specifying the order of the indicator variables shown on the x-axis.
a character string specifying the labels of the indicator variables shown on the x-axis.
a numeric vector of length two specifying limits of the y-axis.
a character string specifying the label of the y-axis.
a numeric vector specifying the points at which tick-marks are drawn at the y-axis.
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.
a numeric value specifying the size of the legend title.
a numeric value specifying the size of the legend text.
a numeric value specifying the size of the legend keys.
logical: if TRUE
, bar charts are drawn in gray
scale.
a numeric value between 0 and 1 specifying the gray value at the low end of the palette.
a numeric value between 0 and 1 specifying the gray value at the high end of the palette.
a numeric value specifying the plot resolution when saving the bar chart.
a numeric value specifying the width of the plot when saving the bar chart. By default, the width is number of indicators plus number of classes divided by 2.
a numeric value specifying the height of the plot when saving the bar chart.
an integer value indicating the number of decimal places
to be used for displaying results. Note that the scaling
correction factor is displayed with digits
plus 1
decimal places.
an integer value indicating the number of decimal places to be used for displaying p-values, entropy value, and class proportions.
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.
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.
logical: if TRUE
(default), argument specification is checked.
logical: if TRUE
(default), output is shown.
Takuya Yanagida takuya.yanagida@univie.ac.at
The result summary table comprises following entries:
"Folder"
: Subfolder from which the group of Mplus outputs files
were summarized.
"#Class"
: Number of 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
). Provided
only when ESTIMATOR IS MLR
.
"LL Rep"
: 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)
).
"Chi-Pear"
: Pearson chi-square test of model fit (i.e., Pearson Chi-Square
),
only available when indicators are count or ordered categorical.
"Chi-LRT"
: Likelihood ratio chi-square test of model fit (i.e., Likelihood Ratio Chi-Square
),
only available when indicators are count or ordered categorical.
"SABIC"
: Sample-size adjusted BIC (i.e., Sample-Size Adjusted BIC
).
"LMR-LRT"
: Significance value (p-value) of the Vuong-Lo-Mendell-Rubin test
(i.e., VUONG-LO-MENDELL-RUBIN LIKELIHOOD RATIO TEST
).
Provided 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
).
Provided only when OUTPUT: TECH11
.
"BLRT"
: Significance value (p-value) of the bootstrapped
likelihood ratio test. Provided only when OUTPUT: TECH14
.
"Entropy"
: Sample-size adjusted BIC (i.e., Entropy
).
"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
).
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.
mplus.lca
, mplus.run
, read.mplus
,
write.mplus
if (FALSE) {
# 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"),
run.mplus = TRUE)
# Example 1a: Read Mplus output files, create result table, write table, and save plots
result.lca(write = "LCA.xlsx", plot = TRUE)
# Example 1b: Write results into a text file
result.lca(write = "LCA.txt")
#-------------------------------------------------------------------------------
# Example 2: Draw bar chart manually
library(ggplot2)
# Collect LCA results
lca.result <- result.lca()
# 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)
}
Run the code above in your browser using DataLab