Skip to content
Prev 15867 / 20628 Next

https://stats.stackexchange.com/questions/301763/using-random-effect-predictions-in-other-models?noredirect=1#comment573574_301763

Hi Josh,

It sounds like one of your responses is repeat measure and the other 
not. With a bivariate model this means you want to model the covariance 
between the ID random effect for the repeat-measure trait and the 
residual for the single-measure trait (an ID term and  a residual would 
be non-identifiable for the latter). In MCMCglmm you can do this using 
the covu argument in the prior. An example is below.

Cheers,

Jarrod

   N<-500
    # 500 individuals

   V<-matrix(c(1,0.5, 0.5, 1),2,2)
    # 2x2 random/residual-effect covariance matrix

   Vr<-matrix(1,1,1)
    # residual variance for repeat measure trait

   u<-MASS::mvrnorm(N, rep(0, 2), V)
     # random effect for repeat measure trait followed by
     # residuals for the single measured trait.

   e<-rnorm(2*N,0,sqrt(Vr))
    # residuals for the repeat trait

   ysingle<-1+u[,2]
     # single measure traits has intercept of 1

   individual<-as.factor(rep(1:N, 3))
     # individuals are ordered within each trait/time combination

   type<-as.factor(c(rep("s", N), rep("r",2*N)))
     # designate which observations are single measures (s)
     # or repeat measures (r)

   yrep<--1+u[rep(1:N, 2),1]+e
     # the repeat measure trait has an intercept of -1

   dat1<-data.frame(y=c(ysingle,yrep), type=type,
   individual=individual)

   prior1<-list(R=list(R1=list(V=V, nu=0, covu=TRUE),
      R2=list(V=Vr, nu=0)))
     # use flat priors, but use covu=TRUE to mdoel covariances
     # between R1 effects and the random effects
     # (G is not needed because random effect prior is
     #  specified in R1)


   m.test1<-MCMCglmm(y~type-1,
     random=~us(at.level(type,"r")):individual,
     rcov=~us(at.level(type, "s")):individual+us(at.level(type, "r")):units,
     data=dat1,
     prior=prior1,
     verbose=FALSE)
     # Have to fit repeat measure residuals in the
     # second residual term.
On 04/10/2017 23:12, Joshua Rosenberg wrote: