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

Multinomial logistic regression pull request #17

Merged
merged 22 commits into from
Jul 8, 2024

Conversation

svteichman
Copy link
Collaborator

This is an edited version of PR #10. I couldn't figure out how to push directly to that PR, so I'm creating a new one here that takes the code from PR #10 from @shirmath and updates based on @adw96's comments on PR #10. This implements robust score tests for multinomial logistic regression, without a Firth penalty.

@adw96
Copy link
Contributor

adw96 commented Jun 26, 2024

This is looking great, @svteichman !

Can you tell me why the following doesn't give me a p-value?

multinom_test(X = structure(c(0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1), dim = c(6L, 2L)), 
              Y = structure(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
                              0, 1, 1, 2, 1, 1, 2), dim = c(6L, 4L)), 
              strong=TRUE)

Thanks so much!

(Update: I just added this as an test that currently fails -- thought it'd be more helpful)

@adw96
Copy link
Contributor

adw96 commented Jun 26, 2024

This eg may shed some light...

set.seed(1) ## runs
multinom_test(X = structure(c(0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1), dim = c(6L, 2L)), 
              Y = rpois(24, 1) + structure(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
                              0, 1, 1, 2, 1, 1, 2), dim = c(6L, 4L)), 
              strong=TRUE)
set.seed(11) # fails
multinom_test(X = structure(c(0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1), dim = c(6L, 2L)), 
              Y = rpois(24, 1) + structure(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
                                             0, 1, 1, 2, 1, 1, 2), dim = c(6L, 4L)), 
              strong=TRUE)

And when it runs, why is the test stat always 6...?

@svteichman
Copy link
Collaborator Author

The p-value is NA when the inverse of the matrix used in the generalized score test stat is computationally singular, so it looks like it's hitting a try-catch block, muting the error from solve(), and returning an NA test stat and p-value. I'll look into the case where it works and is equal to 6.

@adw96
Copy link
Contributor

adw96 commented Jun 26, 2024

Hmmmmm... do you think it should return a warning? Silently failing isn't good... Are we sure that matrix is truly singular in this case? (intuitively this wouldn't be too surprising since it is noiseless...)

Do you think Firth regularization fix singularity issues? It's not good to have a test that just sometimes can't be computed, unless we can really clearly characterize why...

@svteichman
Copy link
Collaborator Author

Yes, I'll have it report the matrix inverse error as a warning. I'll look into whether the Firth penalty will fix singularity issues.

@svteichman
Copy link
Collaborator Author

svteichman commented Jun 26, 2024

I checked your example and the matrix H2 %*% solve(I2) %*% D2 %*% solve(I2) %*% t(H2), which is the inner part of the robust score test, is indeed singular.

Copy link

codecov bot commented Jul 3, 2024

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

Copy link
Contributor

Choose a reason for hiding this comment

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

should multinomial be included in the function title? Could be good as we plan to expand the package

Copy link
Contributor

Choose a reason for hiding this comment

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

(this may apply to other functions as well)

@adw96 adw96 merged commit 93b5f01 into statdivlab:main Jul 8, 2024
3 checks passed
@adw96 adw96 mentioned this pull request Jul 8, 2024
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.

3 participants