[R-sig-ME] Replicating analysis in asreml in lme4

Kevin Wright kw.stat at gmail.com
Thu Sep 22 22:34:07 CEST 2016


This is very late, but I'm posting it for completeness.

Thanks to Aravind for the question and to Ben for the tip.  Here's how you
would use lme4/lsmeans:

   require(lme4)

  cov2sed <- function(x){
  # Convert var-cov matrix to SED matrix
  # sed[i,j] = sqrt( x[i,i] + x[j,j]- 2*x[i,j] )
  n <- nrow(x)
  vars <- diag(x)
  sed <- sqrt( matrix(vars, n, n, byrow=TRUE) +
                 matrix(vars, n, n, byrow=FALSE) - 2*x )
  diag(sed) <- 0
  return(sed)
  }

  # Same as asreml model m4
  m5 <- lmer(yield ~ 0 + gen + rep + (1|rep:block), dat)

  require(lsmeans)
  ls5 <- lsmeans(m5, "gen")
  con <- ls5 at linfct # contrast matrix
  sed5 <- cov2sed(con %*% vcov(m5) %*% t(con)) # SED between genotypes
  # Average variance of difference between genotypes
  mean(sed5[upper.tri(sed5)]^2) # .07010875 matches 'vblue' from asreml



On Sun, Jul 31, 2016 at 8:50 PM, Ben Bolker <bbolker at gmail.com> wrote:

>
>  Try the lsmeans package ...
>
> On 16-07-30 01:41 AM, Aravind J. wrote:
> > Dear members,
> >
> > I am trying to reproduce analyse an alpha lattice design (an unbalanced
> > design) in  `lme4`.
> >
> > https://cran.r-project.org/web/packages/agridat/agridat.pdf#page.184
> >
> > library(agridat)
> > library(lme4)
> >
> > The model can be fitted in lme4
> >
> > # genotypes - fixed
> > model <- lmer(yield ~ 0 + gen + rep + (1|rep:block), dat)
> > # genotypes - random
> > model <- lmer(yield ~ 0 + (1|gen) + rep + (1|rep:block), dat)
> >
> > However further calculations seem to required `asreml`.
> >
> > library(asreml)
> >
> > m3 <- asreml(yield ~ 1 + rep, data=dat, random=~ gen + rep:block)
> > sg2 <- summary(m3)$varcomp[1,'component']
> > vblup <- predict(m3, classify="gen")$pred$avsed ^ 2
> >
> > m3 <- asreml(yield ~ 1 + gen + rep, data=dat, random = ~ rep:block)
> > vblue <- predict(m3, classify="gen")$pred$avsed ^ 2
> > sg2 / (sg2 + vblue/2)
> > 1-(vblup / 2 / sg2)
> >
> > Here `avsed` is the "mean variance of difference of adjusted means" (BLUP
> > or BLUE). Is it possible to replicate the last part also in `lme4`?
> >
> > `avsed` can be computed from the "variance-covariance matrix of adjusted
> > means" for genotypes. (
> > https://static-content.springer.com/esm/art%3A10.
> 1186%2F1471-2164-14-860/MediaObjects/12864_2013_5591_MOESM1_ESM.doc).
> > How to get that matrix from lme4?
> >
> >
> > Warm Regards,
> >
>
> _______________________________________________
> R-sig-mixed-models at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>



-- 
Kevin Wright

	[[alternative HTML version deleted]]



More information about the R-sig-mixed-models mailing list