I am trying to compare the coefficients of two linear regressions with the same variables, but run for different subgroups. I want to check if the coefficients in my model 1 are equal to my coefficients in my model 2. I need to know for each coefficient.
My reproducible data :
Data <- data.frame(
gender = sample (c("men", "women"), 2000, replace = TRUE),
var1 = sample (c("value1", "value2"), 2000, replace = TRUE),
var2 = sample (c("valueA", "valueB"), 2000, replace = TRUE),
y = sample(0:10, 2000, replace = TRUE)
)
I run the two regressions :
men <- subset(Data, gender =="men")
women <- subset(Data, gender =="women")
lm.men <- lm(y~var1+var2, data = men)
summary(lm.men)
lm.women <- lm(y~var1+var2, data = women)
summary(lm.women)
Basically, I want to test if:
- coefficient
var1inlm.men= coefficientvar1inlm.women - coefficient
var2inlm.men= coefficientvar2inlm.women
I can't use the anova() function, because my two samples are different. I think I should apply an F-test but I can't find a function for this test.
Does anyone know how to solve my problem ?