rsquaredacademy / olsrr

Tools for developing OLS regression models
https://olsrr.rsquaredacademy.com/
Other
102 stars 22 forks source link

Discrepancy between ols_test_breusch_pagan and breusch_pagan (skedastic), bptest (lmtest) #183

Closed davidreilly007 closed 3 years ago

davidreilly007 commented 3 years ago

I noticed a discrepancy between the BP test in olsrr versus those in skedastic and lmtest.

I'm not sure if this is a bug or a feature.

library(olsrr) library(lmtest) library(skedastic) model <- lm(mpg ~ disp + hp + wt + drat, data = mtcars)

ols_test_breusch_pagan(model, rhs = TRUE, multiple = TRUE)

ols_test_breusch_pagan(model, rhs = TRUE, multiple = FALSE)

breusch_pagan(model, koenker = TRUE, statonly = FALSE) bptest(model)

Breusch Pagan Test for Heteroskedasticity

Ho: the variance is constant
Ha: the variance is not constant

       Data            

Response : mpg Variables: disp hp wt drat

    Test Summary (Unadjusted p values)       

Variable chi2 df p

disp 1.2355345 1 0.2663334 hp 0.9209878 1 0.3372157 wt 1.2529988 1 0.2629805 drat 1.1668486 1 0.2800497

simultaneous 1.5138083 4 0.8241927

A tibble: 1 x 5

statistic p.value parameter method alternative

1 1.44 0.837 4 Koenker (studentised) greater studentized Breusch-Pagan test data: model BP = 1.4406, df = 4, p-value = 0.8371
aravindhebbali commented 3 years ago

Hi @davidreilly007,

Thank you for bringing this to our attention. We will look into this and get back to you.

davidreilly007 commented 3 years ago

Thank you! I’m guessing a methodology difference.

davidreilly007 commented 3 years ago

I think I resolved it. Proc cook_weisberg in skedastic matches your result.

davidreilly007 commented 3 years ago

Dear Aravind,

Do you have a reference for how you do the individual chi-square tests in the loop function? I haven’t seen that done before on the individual predictors.

Thanks and Best Regards David Reilly

On Wednesday, August 4, 2021, Aravind Hebbali @.***> wrote:

Hi @davidreilly007 https://github.com/davidreilly007,

Thank you for bringing this to our attention. We will look into this and get back to you.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/rsquaredacademy/olsrr/issues/183#issuecomment-892778752, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHDFJBP5Y3AICUFWBDX6TX3T3FPZVANCNFSM5BRAZ7ZQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

davidreilly007 commented 3 years ago

Sorry one more question, is there a Wald version of the multiple test that would accommodate categorical predictors with more than 2 levels?

On Wednesday, August 4, 2021, David Reilly @.***> wrote:

Dear Aravind,

Do you have a reference for how you do the individual chi-square tests in the loop function? I haven’t seen that done before on the individual predictors.

Thanks and Best Regards David Reilly

On Wednesday, August 4, 2021, Aravind Hebbali @.***> wrote:

Hi @davidreilly007 https://github.com/davidreilly007,

Thank you for bringing this to our attention. We will look into this and get back to you.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/rsquaredacademy/olsrr/issues/183#issuecomment-892778752, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHDFJBP5Y3AICUFWBDX6TX3T3FPZVANCNFSM5BRAZ7ZQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

aravindhebbali commented 3 years ago

Dear Aravind, Do you have a reference for how you do the individual chi-square tests in the loop function? I haven’t seen that done before on the individual predictors. Thanks and Best Regards David Reilly

Hi David,

Unfortunately, I have not documented the internal functions (my apologies) but I have mostly relied on hettest of stata while implementing this test. Let me see if I have jotted down any references or notes that I can share with you.

davidreilly007 commented 3 years ago

Thank you - that would be greatly appreciated. I don’t have access to stata but I have seen the documentation.

On Wednesday, August 4, 2021, Aravind Hebbali @.***> wrote:

Dear Aravind, Do you have a reference for how you do the individual chi-square tests in the loop function? I haven’t seen that done before on the individual predictors. Thanks and Best Regards David Reilly

Hi David,

Unfortunately, I have not documented the internal functions (my apologies) but I have mostly relied on hettest https://www.stata.com/manuals13/rregresspostestimation.pdf of stata while implementing this test. Let me see if I have jotted down any references or notes that I can share with you.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/rsquaredacademy/olsrr/issues/183#issuecomment-893137821, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHDFJBPMAYYEBNOJCM4RVU3T3IBSPANCNFSM5BRAZ7ZQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

davidreilly007 commented 3 years ago

Dear Aravind

I was able to successfully replicate the stata example (auto) using mtest(bonferonni), so I am good to go.

Thank you very much for your help. It is greatly appreciated!

David

On Wednesday, August 4, 2021, David Reilly @.***> wrote:

Thank you - that would be greatly appreciated. I don’t have access to stata but I have seen the documentation.

On Wednesday, August 4, 2021, Aravind Hebbali @.***> wrote:

Dear Aravind, Do you have a reference for how you do the individual chi-square tests in the loop function? I haven’t seen that done before on the individual predictors. Thanks and Best Regards David Reilly

Hi David,

Unfortunately, I have not documented the internal functions (my apologies) but I have mostly relied on hettest https://www.stata.com/manuals13/rregresspostestimation.pdf of stata while implementing this test. Let me see if I have jotted down any references or notes that I can share with you.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/rsquaredacademy/olsrr/issues/183#issuecomment-893137821, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHDFJBPMAYYEBNOJCM4RVU3T3IBSPANCNFSM5BRAZ7ZQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .