Function to fit Gaussian mixed model with multiple mixed effects with known covariances.
Function to fit Gaussian mixed model with multiple mixed effects with known covariances.
This function is a wrapper for the emmreml to fit Gaussian mixed model with multiple mixed effects with known covariances. The model fitted is y=Xβ+Z1u1+Z2u2+...Zkuk+e where y is the n vector of response variable, X is a nxq known design matrix of fixed effects, Zj is a nxlj known design matrix of random effects for j=1,2,...,k, β is nx1 vector of fixed effects coefficients and U=(u1t,u2t,...,ukt)t and e are independent variables with NL(0,blockdiag(σu12K1,σu22K2,...,σuk2Kk)) and Nn(0,σe2In) correspondingly. The function produces the BLUPs for the L=l1+l2+...+lk dimensional random effect U. The variance parameters for random effects are estimated as (w^1,w^2,...,w^k)∗σu2^ where w=(w1,w2,...,wk) are the kernel weights. The function also provides some useful statistics like large sample estimates of variances and PEV.
Zlist: list of random effects design matrices of dimensions nxl1,...,nxlk
Klist: list of known relationship matrices of dimensions l1xl1,...,lkxlk
varbetahat: TRUE or FALSE
varuhat: TRUE or FALSE
PEVuhat: TRUE or FALSE
test: TRUE or FALSE
Returns
Vu: Estimate of σu2
Ve: Estimate of σe2
betahat: BLUEs for β
uhat: BLUPs for u
weights: Estimates of kernel weights
Xsqtestbeta: A χ2 test statistic based for testing whether the fixed effect coefficients are equal to zero.
pvalbeta: pvalues obtained from large sample theory for the fixed effects. We report the pvalues adjusted by the "padjust" function for all fixed effect coefficients.
Xsqtestu: A χ2 test statistic based for testing whether the BLUPs are equal to zero.
pvalu: pvalues obtained from large sample theory for the BLUPs. We report the pvalues adjusted by the "padjust" function.
varuhat: Large sample variance for the BLUPs.
varbetahat: Large sample variance for the β's.
PEVuhat: Prediction error variance estimates for the BLUPs.
loglik: loglikelihood for the model.
Examples
####example#Data from Gaussian process with three #(total four, including residuals) independent #sources of variation n=80M1<-matrix(rnorm(n*10), nrow=n)M2<-matrix(rnorm(n*20), nrow=n)M3<-matrix(rnorm(n*5), nrow=n)#Relationship matricesK1<-cov(t(M1))K2<-cov(t(M2))K3<-cov(t(M3))K1=K1/mean(diag(K1))K2=K2/mean(diag(K2))K3=K3/mean(diag(K3))#Generate datacovY<-2*(.2*K1+.7*K2+.1*K3)+diag(n)Y<-10+crossprod(chol(covY),rnorm(n))#training setTrainsamp<-sample(1:80,60)funout<-emmremlMultiKernel(y=Y[Trainsamp], X=matrix(rep(1, n)[Trainsamp], ncol=1),Zlist=list(diag(n)[Trainsamp,], diag(n)[Trainsamp,], diag(n)[Trainsamp,]),Klist=list(K1,K2, K3),varbetahat=FALSE,varuhat=FALSE, PEVuhat=FALSE, test=FALSE)#weightsfunout$weights
#Correlation of predictions with true values in test setuhatmat<-matrix(funout$uhat, ncol=3)uhatvec<-rowSums(uhatmat)cor(Y[-Trainsamp], uhatvec[-Trainsamp])