Learn R Programming

misty (version 0.6.7)

result.lca: Summary Result Table and Grouped Bar Charts for Latent Class Analysis Estimated in Mplus

Description

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.

Usage

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)

Value

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

Arguments

folder

a character vector indicating the name of the subfolders to be excluded from the summary result table.

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.

sort.p

logical: if TRUE (default), class proportions are sorted decreasing.

plot

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.

group.ind

logical: if TRUE (default), latent class indicators are represented by separate bars, if FALSE latent classes are represented by separate bars.

ci

logical: if TRUE (default), confidence intervals are added to the bar charts.

conf.level

a numeric value between 0 and 1 indicating the confidence level of the interval.

adjust

logical: if TRUE (default), difference-adjustment for the confidence intervals is applied.

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.

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

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.

height

a numeric value specifying the height of the plot when saving the bar chart.

digits

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.

p.digits

an integer value indicating the number of decimal places to be used for displaying p-values, entropy value, and class proportions.

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.

Author

Takuya Yanagida takuya.yanagida@univie.ac.at

Details

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

References

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.

See Also

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

Examples

Run this code
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