Skip to content

support lavaan.mi models#1188

Merged
strengejacke merged 6 commits intomainfrom
strengejacke/issue1187
Feb 5, 2026
Merged

support lavaan.mi models#1188
strengejacke merged 6 commits intomainfrom
strengejacke/issue1187

Conversation

@strengejacke
Copy link
Copy Markdown
Member

Fixes #1187

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @strengejacke, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the parameters package by introducing native support for lavaan.mi models. This integration provides a streamlined and consistent way to extract, format, and present model parameters, including standardized coefficients and confidence intervals, from structural equation models fitted with multiply imputed data. The changes ensure broader compatibility and utility for researchers working with complex statistical models.

Highlights

  • New Model Support: Added support for lavaan.mi models, allowing the model_parameters function to process objects from the lavaan.mi package, which handles structural equation models with multiply imputed data.
  • S3 Method Implementation: Implemented a new S3 method model_parameters.lavaan.mi to specifically extract and format parameters from lavaan.mi objects, ensuring consistent output with other supported model types.
  • Package Metadata Updates: Updated the package version to 0.28.3.1 and added lavaan.mi to the list of suggested dependencies in the DESCRIPTION file.
  • Standardization and CI Handling: Included comprehensive logic within the new method for handling various standardization options (e.g., std.all, std.lv, std.nox) and confidence interval calculations for lavaan.mi outputs.
  • Unit Tests: Added dedicated unit tests to verify the correct functionality and output of model_parameters when applied to lavaan.mi objects, using a simulated example with mice for imputation.
Changelog
  • DESCRIPTION
    • Incremented package version to 0.28.3.1.
    • Added lavaan.mi to the list of suggested packages.
  • NAMESPACE
    • Exported the new S3 method model_parameters.lavaan.mi.
  • R/methods_lavaan.mi.R
    • New file introduced, containing the implementation for model_parameters.lavaan.mi and its internal helper function .extract_parameters_lavaan.mi.
    • The implementation includes logic for extracting parameter estimates, standard errors, confidence intervals, and handling various standardization options from lavaan.mi objects.
    • Includes checks for lavaan.mi installation and verbose alerts for invalid standardize or ci arguments.
    • Maps lavaan.mi output to a consistent parameters package data frame structure, including component types (Loading, Regression, Correlation, etc.).
  • tests/testthat/test-lavaan.mi.R
    • New test file added to validate the model_parameters.lavaan.mi function.
    • Includes a test case demonstrating parameter extraction from a sem.mi model using mice for imputation.
Activity
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for lavaan.mi model objects to the parameters package. The changes include adding a new model_parameters.lavaan.mi S3 method, updating the DESCRIPTION and NAMESPACE files, and adding a new test file. The implementation for lavaan.mi models is well-structured and follows the existing pattern for lavaan models. I've found one area for improvement in how function arguments are validated, which I've detailed in a specific comment. Overall, this is a great addition to the package.

Comment thread R/methods_lavaan.mi.R Outdated
@strengejacke
Copy link
Copy Markdown
Member Author

@gemini-code-assist review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for lavaan.mi models, which is a valuable enhancement. The implementation is well-structured, including a new S3 method, documentation, and tests. I've identified a critical bug and another potential issue in the new R/methods_lavaan.mi.R file that should be addressed.

Comment thread R/methods_lavaan.mi.R Outdated
Comment thread R/methods_lavaan.mi.R
params$Component[as.character(params$From) == as.character(params$To)] <- "Variance"

if ("p" %in% colnames(params)) {
params$p[is.na(params$p)] <- 0
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Replacing NA p-values with 0 can be misleading. P-values might be NA for valid reasons, such as for fixed parameters where a p-value is not applicable. Setting them to 0 incorrectly implies perfect statistical significance. It would be better to remove this line and let them remain NA.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattansb I would agree, the code was copied from the .lavaan method, which was first implemented by @DominiqueMakowski (b34d66d). Any ideas why we set p to 0 for missing p-values?

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds support for lavaan.mi models to the parameters package, enabling model_parameters() to work with multiple imputation SEM models from the lavaan.mi package. This addresses issue #1187.

Changes:

  • Added new model_parameters.lavaan.mi() method to handle lavaan.mi models
  • Added .extract_parameters_lavaan_mi() helper function based on the existing lavaan implementation
  • Modified NAMESPACE to export predict methods as regular functions instead of S3 methods
  • Added lavaan.mi to package Suggests
  • Added test coverage for the new functionality

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
R/methods_lavaan.mi.R New file implementing model_parameters method for lavaan.mi objects
tests/testthat/test-lavaan.mi.R New test file verifying lavaan.mi support works correctly
R/methods_lavaan.R Reformatted function signatures for consistency (no functional changes)
R/methods_psych.R Reformatted function signatures and updated documentation to include "defined" component
NAMESPACE Added lavaan.mi method export and changed predict methods from S3method to export
DESCRIPTION Version bump and added lavaan.mi to Suggests
man/*.Rd Documentation updates reflecting code changes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread man/principal_components.Rd Outdated
Comment thread man/predict.parameters_clusters.Rd Outdated
Comment thread R/methods_lavaan.mi.R
Comment thread R/methods_lavaan.mi.R
Comment thread R/methods_lavaan.mi.R Outdated
Comment thread NAMESPACE Outdated
@mattansb
Copy link
Copy Markdown
Member

mattansb commented Feb 5, 2026

Something weird is happening with the namespace and Rd files - see copilots comments.

@strengejacke
Copy link
Copy Markdown
Member Author

Something weird is happening with the namespace and Rd files - see copilots comments.

Yeah, saw it (and fixed it). Not sure why roxygen did this change? Or was it Gemini when it worked on the PR?

@strengejacke
Copy link
Copy Markdown
Member Author

btw, ignore the lavaan-methods file, that is just styling.

@strengejacke strengejacke merged commit 092f6e0 into main Feb 5, 2026
12 of 22 checks passed
@strengejacke strengejacke deleted the strengejacke/issue1187 branch February 5, 2026 09:58
@mattansb
Copy link
Copy Markdown
Member

mattansb commented Feb 5, 2026

Thanks @strengejacke !

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

Successfully merging this pull request may close these issues.

support lavaan.mi models

3 participants