Skip to content

Add -2LL as the Criterion column#895

Open
jmgirard wants to merge 5 commits intoeasystats:mainfrom
jmgirard:main
Open

Add -2LL as the Criterion column#895
jmgirard wants to merge 5 commits intoeasystats:mainfrom
jmgirard:main

Conversation

@jmgirard
Copy link
Copy Markdown
Contributor

Revival of #806

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 test_likelihoodratio function by integrating and explicitly displaying the -2 * log-likelihood (-2LL) value as a 'Criterion' column in the output. This change provides users with direct access to the underlying statistic used for likelihood ratio tests, improving transparency and interpretability of model comparisons. The accompanying documentation has been updated to explain this new output, and robust unit tests ensure the accuracy of the added functionality across various statistical models.

Highlights

  • New 'Criterion' Column: A new 'Criterion' column has been added to the output of the test_likelihoodratio function, which displays the -2 * log-likelihood (-2LL) value for each model.
  • Updated Chi2 Calculation: The calculation of the Chi2 statistic in test_likelihoodratio has been updated to directly use the difference in the new 'Criterion' values.
  • Enhanced Documentation: The documentation for test_likelihoodratio has been revised to clearly explain the meaning and calculation of the new 'Criterion' column and its relationship to the Chi2 statistic.
  • Comprehensive Unit Tests: New unit tests have been introduced to thoroughly validate the accuracy and presence of the 'Criterion' column across different model types, including lm, lme4, and lavaan.
  • Snapshot Test Updates: Existing snapshot tests were updated to reflect changes in output values, and an outdated snapshot test file was removed.
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.

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.

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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 a -2LL column named Criterion to the output of test_likelihoodratio, which is a valuable addition for model comparison. The implementation is sound, and new tests have been added to verify the functionality. I have a couple of suggestions to enhance consistency and test coverage for lavaan models.

@jmgirard
Copy link
Copy Markdown
Contributor Author

While adding the Criterion column and testing the output, I also caught and fixed a bug in test_likelihoodratio_ListLavaan. The function was previously extracting the absolute model fit (Chisq) from the lavTestLRT output instead of the actual LRT test statistic (Chisq diff). I updated the column mapping to extract Chisq diff, so the reported Chi2 value now correctly matches the difference in -2LL and aligns with the reported p-value.

@jmgirard
Copy link
Copy Markdown
Contributor Author

/gemini 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 a -2LL column named Criterion to the output of test_likelihoodratio(), which is a useful addition for model comparison. The implementation is correct, and the new functionality is well-documented and thoroughly tested. I've added a couple of suggestions to improve the robustness of the newly added tests.

@jmgirard
Copy link
Copy Markdown
Contributor Author

/gemini summary

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

This pull request enhances the test_likelihoodratio function by explicitly including the -2 * log-likelihood (-2LL) value as a new 'Criterion' column in its output. This change improves the transparency and interpretability of likelihood ratio tests by directly exposing the underlying statistic used for model comparison. The update also refines the Chi2 calculation to align with this new criterion, includes a bug fix for lavaan models, and updates documentation and tests to reflect these improvements.

Highlights

  • New 'Criterion' Column: A new 'Criterion' column has been added to the output of the test_likelihoodratio function, displaying the -2 * log-likelihood (-2LL) value for each model.
  • Updated Chi2 Calculation: The calculation of the Chi2 statistic in test_likelihoodratio has been updated to directly use the difference in the new 'Criterion' values.
  • Enhanced Documentation: The documentation for test_likelihoodratio has been revised to clearly explain the meaning and calculation of the new 'Criterion' column and its relationship to the Chi2 statistic.
  • Comprehensive Unit Tests: New unit tests have been introduced to thoroughly validate the accuracy and presence of the 'Criterion' column across different model types, including lm, lme4, and lavaan.
  • Bug Fix in Lavaan Models: A bug was corrected in test_likelihoodratio_ListLavaan where the Chisq column was incorrectly extracted instead of the Chisq diff from lavTestLRT output.
  • Snapshot Test Updates: Existing snapshot tests were updated to reflect changes in output values, and an outdated snapshot test file was removed.
Changelog
  • R/test_likelihoodratio.R
    • Added a 'Criterion' column to the output data frame for ListNestedRegressions to display the -2 * log-likelihood.
    • Modified the chi2 calculation to use the difference in the newly introduced criterion values.
    • Introduced a 'Criterion' column for ListLavaan models, calculating it as -2 times the log-likelihood from lavaan::fitMeasures.
    • Corrected the column renaming for Chisq to Chisq diff for lavaan models to ensure proper extraction of the LRT test statistic.
    • Reordered the output columns for lavaan models to include 'Criterion' and ensured the output is sorted by degrees of freedom (df).
  • R/test_performance.R
    • Updated the documentation for test_likelihoodratio to explain the new 'Criterion' column and its role in the Chi2 calculation.
    • Removed previous documentation regarding log-likelihood correction for transformed response variables.
  • man/test_performance.Rd
    • Updated the R documentation to describe the 'Criterion' column and its relation to Chi2.
    • Removed the section explaining log-likelihood correction for transformed response variables.
  • tests/testthat/_snaps/model_performance.psych.md
    • Updated snapshot values for RMSR, RMSR_corrected, R2, and Correlation in several test cases.
  • tests/testthat/_snaps/nestedLogit.md
    • Removed the snapshot test file.
  • tests/testthat/test-test_likelihoodratio.R
    • Added new test_that blocks to verify the presence and accuracy of 'Criterion' values for lm, lme4, and lavaan models.
    • Ensured the 'Criterion' column exists and its values match manual calculations.
    • Verified that the Chi2 statistic correctly reflects the absolute difference in 'Criterion' values for lm, lme4, and lavaan models.
Activity
  • The gemini-code-assist[bot] provided an initial summary of the pull request.
  • The author jmgirard commented on fixing a bug in test_likelihoodratio_ListLavaan related to incorrect Chisq extraction.
  • The gemini-code-assist[bot] suggested explicitly sorting the output by df in test_likelihoodratio_ListLavaan for consistency, which jmgirard addressed in commit 65e19e4.
  • The gemini-code-assist[bot] recommended adding a check for Chi2 calculation from Criterion values in the lavaan test, which jmgirard addressed in commit 65e19e4.
  • The gemini-code-assist[bot] advised using abs(diff(...)) for Chi2 calculation checks in lm and lme4 tests for improved robustness and consistency, which jmgirard addressed in commit 839f3b2.

@jmgirard
Copy link
Copy Markdown
Contributor Author

I think this is good to go. The failed checks seem unrelated to my changes.

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.

1 participant