Estimating variance attributed a fixed effect

79 views Asked by At

Disregarding how "important" it is, I am interested in trying to estimate how much of the variance is attributed to a single fixed effect (it being a main effect, or interaction term).

As a quick thought I imagined that constructing a linear model for the predicted values of mixed model (without the random effect), and assessing the ANOVA-table would provide a estimate (yes, the residual variance will then be zero, but we know(?) this from the mixed model). However, from playing around apparently not.

Where is the flaw in my reasoning? Or did I do something wrong along the way? Is there an alternative method?

Disclaimer: I know some people have suggested looking at the change in residual variance when removing/adding fixed effects, but as this does not take into account the correlation between fixed and random effects I am not interested .

data(Orthodont,package="nlme")
Orthodont = na.omit(Orthodont)
#Fitting a linear mixed model
library(lme4)
mod = lmer(distance ~ age*Sex + (1|Subject) , data=Orthodont)
# Predicting across all observed values, 
pred.frame = expand.grid(age = seq(min(Orthodont$age, na.rm = T),max(Orthodont$age, na.rm=T)), 
            Sex = unique(Orthodont$Sex))
# But not including random effects
pred.frame$fit = predict(mod, newdata = pred.frame, re.form=NA)
anova(lm(fit~age*Sex, data = pred.frame))
library(data.table)
Orthodont = data.table(Orthodont)
# to test the validity of the approach
# by estimating a linear model using a random observation 
# per individual and look at the means
tmp = sapply(1:500, function(x){
     print(x)
     as.matrix(anova(lm(distance~age*Sex, data =Orthodont[,.SD[sample(1:.N,1)],"Subject"])))[,2]
}
)
# These are clearly not similar
    prop.table(as.table(rowMeans(tmp)[-4]))
       age        Sex    age:Sex 
0.60895615 0.31874622 0.07229763 
> prop.table(as.table(anova(lm(fit~age*Sex, data = pred.frame))[1:3,2]))
         A          B          C 
0.52597575 0.44342996 0.03059429 
0

There are 0 answers