# Animal Model toy example y<-matrix(c(310,270,350),nrow=3) X<-matrix(c(1,1,0,0,0,1),nrow=3) Z<-matrix(c(1,0,0,0,0,0,0,1,0,0,0,0,0,1,0),nrow=3, byrow = TRUE) A<-matrix(c(1,0,0.5,0.5,0.25, 0,1,0,0.5,0, 0.5,0,1,0.25,0.5, 0.5,0.5,0.25,1,0.125, 0.25,0,0.5,0.125,1),nrow=5) h2<-1/3 # heritability a=(1-h2)/h2 # crossproducts XX<-crossprod(X,X) XZ<-t(X) %*% Z ZX<-t(Z) %*% X ZZ<-crossprod(Z,Z)+a*solve(A) # mixed model equations # coefficient matrix and right hand side C<-rbind(cbind(XX,XZ),cbind(ZX,ZZ)) rhs<-rbind(t(X) %*% y,t(Z) %*% y) #solution theta.hat <- solve(C) %*% rhs theta.hat