Mplus LPA Output Extractor
Extract key fit statistics and class distributions from Mplus Latent Profile Analysis (LPA) output files and generate a formatted Excel summary table.
When to Use
- User has multiple Mplus
.outfiles from LPA models (e.g., 2-class through 6-class) - User wants a side-by-side comparison table of AIC, BIC, SABIC, and Entropy
- User needs to extract class counts and proportions into a structured table
- Files follow a naming pattern like
T2_LPA2.out,T2_LPA3.out, etc.
Workflow
Step 1: Identify the input directory and file pattern
Ask the user or infer from context:
- Which directory contains the
.outfiles? - What is the file naming pattern? (e.g.,
T2_LPA*.out,LPA*.out) - Are there row label prefixes/suffixes to strip from filenames?
Step 2: Run the extraction script
Execute scripts/extract_lpa.py with appropriate arguments:
python scripts/extract_lpa.py DIRECTORY --pattern "GLOB_PATTERN" --output OUTPUT.xlsx [--row-prefix "PREFIX"] [--row-suffix "SUFFIX"]
Arguments:
directory(required): Path to the directory containing.outfiles--pattern(default*.out): Glob pattern to match files--output(defaultLPA_Results.xlsx): Output Excel filename--row-prefix(default empty): Prefix to remove from filenames for row labels. E.g., if files areT2_LPA2.outand you want row labelLPA2, use--row-prefix "T2_"--row-suffix(default.out): Suffix to remove from filenames for row labels
Step 3: Present the result
After the script completes, call present_files with the output Excel file path.
Also summarize the extracted values in a markdown table in the reply.
Extracted Values
The script extracts the following from each .out file:
| Column | Source in .out file | Extraction method |
|--------|-------------------|-------------------|
| Akaike (AIC) | Akaike (AIC) direct value (or Mean sub-line for bootstrap/MI) | Regex, float, 2 decimals |
| Bayesian (BIC) | Bayesian (BIC) direct value (or Mean sub-line) | Regex, float, 2 decimals |
| Sample-Size Adjusted BIC | Sample-Size Adjusted BIC direct value (or Mean sub-line) | Regex, float, 2 decimals |
| Entropy | Entropy line after CLASSIFICATION QUALITY | Regex, float, 2 decimals |
| Latent Classes1 | Class Counts and Proportions section (under "BASED ON THEIR MOST LIKELY LATENT CLASS MEMBERSHIP") → 2nd column (integer counts) | "/" separated |
| Latent Classes2 | Same section → 3rd column (proportions) | "/" separated, 2 decimal places |
| LMRL | LO-MENDELL-RUBIN ADJUSTED LRT TEST → P-Value | Regex, float, 2 decimals |
Notes
- The script requires
openpyxl. If not installed, install it first with pip. - All numeric values (AIC, BIC, SABIC, Entropy, LMRL) are rounded to 2 decimal places and formatted with
0.00number format in Excel. - Class proportions are automatically rounded to 2 decimal places.
- The "Class Counts and Proportions" section is the one under "BASED ON THEIR MOST LIKELY LATENT CLASS MEMBERSHIP" (integer counts), not the model-based or posterior-probability-based sections (which have decimal counts).
- AIC/BIC/SABIC extraction first tries direct value on the same line; falls back to
Meansub-line for bootstrap or multiple imputation outputs. - If any value is not found in a file, it is left empty in the table.
- The Excel output uses Times New Roman font, centered alignment, thin borders, and light blue header fill.
- Files with spaces in names (e.g.,
T3 LPA2.out) are supported.
微信扫一扫