Basically, I am running nlme::lme
with a missing value. The model fits fine with na.action=na.omit
, but how come the name of the fitted/residuals/coef all seem to be shifted by a row?
## Generate data ---------------------
X1=gl(2,4)
X2=gl(2,2,8)
Y=rnorm(8)
dat=data.frame(Y=Y,X1=X1,X2=X2)
dat
## missing value -------------
mis.dat=dat
mis.dat[3,"Y"]=NA
mis.dat
> mis.dat
Y X1 X2
1 -0.06845332 1 1
2 0.89169085 1 1
3 NA 1 2
4 1.88997449 1 2
5 0.95912879 2 1
6 -0.64049400 2 1
7 -0.23354948 2 2
8 -0.66869350 2 2
## Fit model -----------------------
model=nlme::lme(Y~1,random=~1|X1/X2,data=mis.dat,na.action=na.omit)
summary(model)
## Notie the names -------------------
fitted(model)
> fitted(model)
1/1 1/1 2/1 2/1 2/2 2/2 <NA>
0.67179438 0.67179438 0.67179439 0.02855517 0.02855517 0.02855517 0.02855517
attr(,"label")
[1] "Fitted values"
#model$coef$random
#resid(model)
Notice how the names of the fitted value? Shouldn't there be a 1/2 in the 3rd position, and the names after that shift one position to the right, thus eliminating the NA?