####=========================================####
#### For CRAN time limitations most lines in the
#### examples are silenced with one '#' mark,
#### remove them and run the examples
####=========================================####
data("DT_example")
DT <- DT_example
K <- A_example
#### look at the data and fit the model
head(DT)
zz <- with(DT, vsr(dsr(Env),Name))
Z <- c(list(model.matrix(~Name-1, data=DT)),zz$Z)
Zind <- c(1,2,2,2)
A <- list(diag(41), diag(41))#rep(list(diag(41)),4)
Ai <- lapply(A, function(x){solve(x)})
theta <- list(
matrix(10,1,1),
diag(10,3,3),
diag(10,3,3)
);theta
thetaC <- list(
matrix(1,1,1),
diag(1,3,3),
diag(1,3,3)
);thetaC
X <- model.matrix(~Env, data=DT)
y <- as.matrix(DT$Yield)
DTx <- DT; DTx$units <- as.factor(1:nrow(DTx))
ss <- with(DTx, vsr(dsr(Env),units) )
S <- ss$Z
H <- diag(length(y))
addScaleParam <- 0
nn <- unlist(lapply(thetaC, function(x){length(which(x > 0))}))
nn2 <- sum(nn[1:max(Zind)])
ff <- diag(nn2)
thetaF <- cbind(ff,matrix(0,nn2,1))
## apply the function
weightInfMat=rep(1,40); # weights for the information matrix
weightInfEMv=c(seq(.9,.1,-.1),rep(0,36)); # weights for the EM information matrix
# expr = res3<-AI(X=X,Z=Z, Zind=Zind,
# Ai=Ai,y=y,
# S=S,
# H=H,
# nIters=20, tolParConvLL=1e-5,
# tolParConvNorm=0.05,
# tolParInv=1e-6,theta=theta,
# thetaC=thetaC,thetaF=thetaF,
# addScaleParam=addScaleParam, weightInfEMv = weightInfEMv,
# weightInfMat = weightInfMat
#
# )
# # compare results
# res3$monitor
Run the code above in your browser using DataLab