[R] Variance and Covariance Matrix D and R in nlme or lme4 part II [Please]

Douglas Bates bates at stat.wisc.edu
Sat Nov 13 21:33:39 CET 2004


Alexandre Galvão Patriota wrote:
> Hi Douglas, I need to find the matrix V=ZDZ'+R, for
> example:
> 
> require(nlme)
> data(Orthodont)
> attach(Orthodont)
> fm1 <- lme(distance ~ age + Sex, data =
> Orthodont,random=~age)
> X<-model.matrix(distance ~ age + Sex)
> Z<-model.matrix(distance ~ age + Subject -1)
> D<-diag(ncol(Z))
> cova<-VarCorr(fm1,rdig=7)
> D[,1]<-D[1,]<-as.numeric(cova[2,3])*as.numeric(cova[1,2])*as.numeric(cova[2,2])
> diag(D)<-c(as.numeric(cova[1,1]),rep(as.numeric(cova[2,1]),
> 27))
> se2<-summary(fm1)$sigma^2
> V<-Z%*%D%*%t(Z) + se2*diag(108)
> 
> Is It right?? I compared a function vcov(fm1) with
> solve(t(X)%*%solve(V)%*%X). Could you give me a hint
> on why the two functions are giving incompatible
> results?

I don't know.

I wouldn't calculate the variance-covariance matrix for the parameter 
estimates that way.




More information about the R-help mailing list