The dependent variable Value of the data frame DF is predicted using the independent variables Mean, X, Y in the following way:
DF <- DF %>%
group_by(Country, Sex) %>%
do({
mod = lm(Value ~ Mean + X + Y, data = .)
A <- predict(mod, .)
data.frame(., A)
})
Data are grouped by Country and Sex. So, the fitting formula can be expressed as:
Value(Country, Sex) = a0(Country, Sex) + a1(Country, Sex) Mean + a2(Country, Sex) X + a3(Country, Sex) Y
However, I want to use this formula:
Value(Country, Sex) = a0(Country, Sex) + a1(Country, Sex) Mean + a2(Country) X + a3(Country) Y
Where a2 and a3 are independent of Sex. How can I do it?