Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with mixtureSummaryTable and readModels #206

Open
linem7 opened this issue May 3, 2024 · 2 comments
Open

Issue with mixtureSummaryTable and readModels #206

linem7 opened this issue May 3, 2024 · 2 comments

Comments

@linem7
Copy link

linem7 commented May 3, 2024

Hi,

I'm currently using the mixtureSummaryTable function in the MplusAutomation package to summarize several mixture models, particularly for comparing model fits. I've encountered an issue where the objects returned by readModels("nameofMplusoutfile.out", what="summaries")$summaries don't seem to function as effectively as extractModelSummaries, which is now deprecated.

Could you please provide any guidance or workaround to address this issue? Any help would be greatly appreciated!

Thanks!

@linem7
Copy link
Author

linem7 commented May 3, 2024

I'd like to add some more details regarding the issue I mentioned. While the summaryTable can read and display the object returned by the readModels, certain indices such as min_N and max_N for mixture models are still not available. This makes it challenging as I still require a suitable object format, like what was returned by the now-deprecated extractModelSummaries, which could be processed by mixtureSummaryTable.

@linem7
Copy link
Author

linem7 commented May 15, 2024

Hi everyone,

I would like to share my solution addressing this issue,

# Read information from output file
res <- readModels("./LCA") # Total 5 models are imported

# Function to enhance the SummaryTable with class proportions
summary_with_proportions <- function(res, keepCols) {
  # Retrieve the initial summary table
  summary_data <- SummaryTable(res_post, keepCols = keepCols) %>%
    select({{ keepCols }})

  # Extract and format the class proportions for each model
  proportions_data <- map(res, ~ {
    proportions <- .x[["class_counts"]][["mostLikely"]][["proportion"]]
    proportions <- sort(proportions, decreasing = TRUE)
    proportion_string <- paste(formatC(proportions * 100, format = "f", digits = 1), collapse = "/")
    return(proportion_string)
  })

  # Combine the proportion data with the summary table
  summary_data$"Proportion (%)" <- unlist(proportions_data)

  return(summary_data)
}

# Assuming 'res' is your list of models
summary_with_proportions (res, c("Title", "AIC", "BIC", "aBIC", "Entropy", "T11_LMR_PValue", "BLRT_PValue"))

and the corresponding result looks like below, where the proportion for each class will be sorted in descending order and separated by a slash. This may help you consider whether there is enough proportion in each class.

       Title      AIC      BIC     aBIC Entropy T11_LMR_PValue BLRT_PValue         Proportion (%)
1  1 classes 5957.652 5998.196 5966.462      NA             NA          NA                  100.0
2  2 classes 5730.675 5803.655 5746.534   0.953         0.0000           0              76.3/23.7
3  3 classes 5595.470 5700.886 5618.378   0.932         0.3342           0          69.5/21.8/8.7
4  4 classes 5090.423 5228.274 5120.379   1.000         0.3240           0      60.3/24.4/9.4/5.9
5  5 classes 4867.573 5037.859 4904.578   0.980         0.0377           0 56.8/18.8/16.0/4.9/3.5

I hope this function will be of some help to your work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant