[R] Test For Difference of Betas By Group in car

David Winsemius dw|n@em|u@ @end|ng |rom comc@@t@net
Sun Jan 19 07:54:27 CET 2025


I don’t understand why you don’t include the full text of the error. 

— 
David
Sent from my iPhone

> On Jan 19, 2025, at 10:00 AM, Sparks, John via R-help <r-help using r-project.org> wrote:
> 
> Hello R-Helpers,
> 
> I was looking into how to test whether the beta coefficient from a regression would be the same for two different groups contained in the dataset for the regression.
> 
> When I put that question into google, AI returned a very nice looking answer (and a couple of variations on it).
> 
> library(car)
> data <- data.frame(income = c(30, 45, 50, 25, 60, 55),
>                   education = c(12, 16, 14, 10, 18, 16),
>                   gender = c("Male", "Female", "Male", "Female", "Male", "Female"))
> model <- lm(income ~ education * gender, data = data)
> # Test if the beta for "education" is significantly different between genders
> test <- linearHypothesis(model, "genderMale - genderFemale = 0")
> print(test)
> 
> This, however, produces an error that I can't find a way to resolve.
> 
> Can this test actually be done in this manner, or is this a case of AI run amok.
> 
> Guidance would be appreciated.
> --John Sparks
> 
> 
> 
>    [[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide https://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list