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

Sparks, John j@p@rk4 @end|ng |rom u|c@edu
Sun Jan 19 03:59:44 CET 2025


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]]



More information about the R-help mailing list