# Is the “within-person” effect estimated by fixed effects regression equivalent to that of a random effects model with mean-centered predictors?

I suspect the answer is yes. I explored this with a simulation. The coefficient and standard error are identical in the first model (the fixed effects regression) and the second model (the model with mean centered predictor and random effects). The goal is to estimate the within-"person" effect of x.

library(lme4)
K <- 50; N <- 5 #50 people, 5 measurements per person.
ID = rep(1:K,each=N)
x=NULL
for(k in 1:K) x <- c(x, runif(N)+0.1*k)
y=NULL
for(k in 1:K) y <- c(y, runif(N)+0.1*k)
mod2 = lm(y ~ -1 + factor(ID) + x)
xc = NULL
for(k in 1:K)
{
ix = c(1:5) + (k-1)*5
xc = c(xc, x[ix]-mean(x[ix]))
}
summary(mod2)
summary(lmer(y~xc+(1|ID)))


If these two models are equivalent for estimating the within-person effect, I don't understand why. And, I don't understand why this doesn't seem to be mentioned by statisticians that have researched the "fixed effects model" in depth, such as Paul Allison. I've always been taught that the random effects model is not sufficient for estimating the within-person effect like this.

Any thoughts on this are appreciated.

• Is it deliberate that x is confounded with k? Usually, one wants (but can't always obtain in a nonexperimental setting) treatment to be independent of subject. – Kodiologist Aug 23 '17 at 0:05
• @Kodiologist, Yes. This was intended as an example of there being no within-person effect, but a large overall effect (i.e. a situation where fixed effects regression is good at identifying that there is no within-person effect). I was taught that fixed effects, but not random effects, are good at handling this situation. But, it appears the models are equivalent when you center the predictor--my question is whether or not that's true. – within_person Aug 23 '17 at 0:24
• If I answered your question to your satisfaction, you can accept my answer by clicking on the check mark under the voting arrows. – Kodiologist Aug 25 '17 at 19:06

The models aren't equivalent. The coefficient for x equals the coefficient for xc, but these are different predictors because of the mean-centering; moreover, the coefficient of each group is estimated differently for the two models, which leads to different predictions of y for the same x and group, even when the models are asked to predict y in their own training data.
So why do x and cx end up with the same coefficient? First notice that tail(coef(mod2), 1) and coef(lm(y ~ -1 + xc)) are equal. That is, if you remove group from the OLS model but center x within groups, the coefficient ends up the same. This makes sense considering that the effect of group (according to the first model) is just to add a constant value to the dependent variable for each group. In fact, once you center x within groups, adding groups back into the model, whether as random or fixed effects, won't change the coefficient of xc, because (I believe) xc is uncorrelated with group.
• @within_person If by "estimating the 'within group' effect" you mean "getting a coefficient", then yes, it's the same coefficient. $p$-values, confidence intervals, and other inferences may difer. – Kodiologist Aug 23 '17 at 1:22