data(DT_cpdata, package="enhancer")
DT <- DT_cpdata
# response matrix
y <- cbind(imputev(DT$Yield), imputev(DT$Firmness))
# fixed effect incidence matrix
X <- model.matrix(~Rowf, data=DT)
# random effect incidence matrix
Z <- Matrix::sparse.model.matrix(~id - 1, data=DT)
colnames(Z) <- gsub("id","",colnames(Z))
# covariance for random effect
GT <- GT_cpdata
A <- A.mat(GT) # additive relationship matrix
A <- A[colnames(Z),colnames(Z)] # make sure of the order
A <- A + diag(1e-4,nrow(A), nrow(A))
# residual effect incidence matrix (dimensions equal nrow(y))
R1 <- Matrix::Diagonal(n=nrow(y))
# weights matrix (dimensions equal nrow(y))
W <- diag(nrow(y))
# some other parameters
maxIter=3
stepWeight <- rep(0.9, maxIter)
stepWeight[1:2] <- c(0.5, 0.7)
emWeights <- rep(0,maxIter)
# model fit
res <- MNR( Y=y, # multi-trait response
X=list(X), Gx=list(diag(2)), # fixed effects
Z=list(Z), K=list(A), # random effects
R=list(R1), # residual effects
Ge=list( (diag(2)*.3)+.15 , diag(2)*0.75 ), # inital vc
GeI=list(unsm2(2),diag(2)), # vc constraints
W=W, isInvW=TRUE, # weights for records
iters=maxIter,
tolpar=1e-4, tolparinv=1e-6, # tolerance
ai=FALSE, pev=FALSE, # algorithm specifics
verbose=TRUE,
retscaled=FALSE,
stepweight=stepWeight, # second derivatives weights
emweight=emWeights # em update weights
)
res$sigma
res$Beta
res$U[[1]]
Run the code above in your browser using DataLab