In a linear model that predicts birth rate (TFR) per country from per capita GDP, the country is encoded in "treatment coding", and there are several measurements (different years) per country. I would thus have thought that the first level represents the "reference intercept" and the predictions for only this first level should change when the intercept is removed from the model.
However, the predictions do not change for any country, if I remove the intercept:
> fit1 <- lm(TFR ~ logGDPpc + logGDPpc2 +
country, data=x)
> fit2 <- lm(TFR ~ logGDPpc + logGDPpc2 +
country - 1, data=x)
> max(abs(fit1$fitted.values -
fit2$fitted.values))
[1] 1.847411e-13
This also applies to the relative error of the differences:
> max(abs((fit1$fitted.values -
fit2$fitted.values)/fit2$fitted.values))
[1] 7.482906e-14
Is this the expected behavior? Why?
model.matrixfunction. These two models have the same design matrix. – dipetkov Mar 29 '22 at 13:38model.matrix, and this is indeed the explanation. Would you mind elaborating your comment into an answer whcih I then can accept, so that teh question is marked as answered? – cdalitz Mar 29 '22 at 13:42