Back to skills
extension
Category: Data & AnalyticsNo API key required

jjc_mplus_lpa_extract

This skill should be used when the user needs to extract AIC, BIC, Sample-Size Adjusted BIC, Entropy, and Class Counts/Proportions from Mplus LPA output files and generate a formatted Excel summary table. Trigger phrases include LPA结果提取, LPA汇总表生成, Mplus输出转Excel, LPA拟合指标表格, or any request to tabulate fit indices and class distributions from multiple LPA out files.

personAuthor: user_35e28d05hubcommunity

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 .out files 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 .out files?
  • 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 .out files
  • --pattern (default *.out): Glob pattern to match files
  • --output (default LPA_Results.xlsx): Output Excel filename
  • --row-prefix (default empty): Prefix to remove from filenames for row labels. E.g., if files are T2_LPA2.out and you want row label LPA2, 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 TESTP-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.00 number 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 Mean sub-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.