Skip to content

Fix for non-converged lavaan#848

Merged
strengejacke merged 8 commits intomainfrom
lavaan_converged
Aug 11, 2025
Merged

Fix for non-converged lavaan#848
strengejacke merged 8 commits intomainfrom
lavaan_converged

Conversation

@DominiqueMakowski
Copy link
Member

fix #847

Copy link
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.

Summary of Changes

Hello @DominiqueMakowski, 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!

I've implemented a fix to improve the robustness of the model_performance.lavaan function. This change specifically addresses scenarios where the lavaan model provided as input has not converged. The primary goal is to prevent errors and provide clearer feedback to the user in such situations, although there appears to be a logical inversion in the final step of setting the output values.

Highlights

  • Convergence Check: I've introduced a check within the model_performance.lavaan function to detect if an input lavaan model has failed to converge. This is done by checking if model@vcov$vcov is NULL.
  • Warning and Mock Model Creation: When a non-converged model is detected, a warning message is now displayed to inform the user that performance indices cannot be computed. To prevent subsequent errors, a temporary 'mock' lavaan model is created and used for internal calculations.
  • Output Handling Discrepancy: The logic attempts to set the output performance metrics to NA based on the original model's convergence status. However, as currently implemented, the NA values are assigned when the original model did converge, which seems to contradict the PR's stated goal of handling non-converged cases.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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 or fill out our survey to provide feedback.

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
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 aims to handle non-converged lavaan models by returning NA values. While the intention is good, the current implementation contains a critical logical error that causes it to nullify results for correctly converged models instead. My review provides a fix for this issue, along with a minor correction to a user-facing warning message to improve clarity.

@DominiqueMakowski
Copy link
Member Author

Not the most elegant solution but 🤷

@DominiqueMakowski
Copy link
Member Author

@gemini-code-assist review

Copy link
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 addresses an issue with non-converged lavaan models by adding a check and returning NA values for performance metrics. The overall approach is sound, but the implementation can be improved for robustness and clarity. I've suggested refactoring the convergence check to use the recommended lavaan::lavInspect() function and to handle non-converged models more directly by returning early, which simplifies the code. I also noted a minor discrepancy between a comment and the code.

@strengejacke strengejacke requested a review from Copilot August 11, 2025 10:21
@strengejacke
Copy link
Member

@gemini-code-assist review

Copy link
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 PR addresses issue #847 by adding proper handling for non-converged lavaan models in the model performance function. The change prevents errors when trying to compute performance metrics on models that failed to converge.

  • Added convergence check using insight::is_converged() before computing metrics
  • Returns NA values with appropriate warning when model hasn't converged
  • Added drop = FALSE parameter to maintain data frame structure during subsetting

@strengejacke
Copy link
Member

@DominiqueMakowski I applied the suggestion from Gemini code assist, directly returning the data frame. And I implemented a .lavaan method for insight::is_converged(), which is in the current release branch of insight (which will be submitted after the summer break)

Copy link
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 addresses an issue with non-converged lavaan models by adding a check and returning NA for performance metrics. The changes are sensible and correctly handle the non-converged case. My feedback focuses on refactoring the new logic to improve maintainability by reducing code duplication. The core idea is to separate the creation of the results data frame (with either computed values or NAs) from the logic that subsets the metrics, making the function more robust and easier to maintain.

@strengejacke strengejacke merged commit 3fb3b5c into main Aug 11, 2025
18 of 20 checks passed
@strengejacke strengejacke deleted the lavaan_converged branch August 11, 2025 12:31
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.

model_performance() of non-converging Lavaan model should return warning + NA instead of error

3 participants