1

I have measurements of a given trait (TRAIT1) in individuals from different genotypes that were reared at either temperature1 or temperature2. I want to test for the effect of genotype (random effect) and temperature (temperature is crossed with genotype) on my trait and the interaction between them. Then, I want to calculate the heritability of my TRAIT1 for which I need to extract the variance components (within and between genotype). This is the model I've run:

glm2<-lme(TRAI1 ~ temperature * genotype,random=~1|genotype, data=x)

But I don't know to extract the variance components from the output:

> summary(glm2)
Linear mixed-effects model fit by REML
 Data: x 
       AIC      BIC   logLik
  37778.39 37817.32 -18883.2

Random effects:
 Formula: ~1 | genotype
        (Intercept) Residual
StdDev:    7.201168 11.22449

Fixed effects: TRAI1 ~ temperature * genotype 
                         Value Std.Error   DF   t-value p-value
(Intercept)          137.39825 1.7585819 4655  78.13014  0.0000
temperature           -0.72913 0.0614889 4655 -11.85787  0.0000
genotype              -0.01086 0.0033006  198  -3.29095  0.0012
temperature:genotype   0.00021 0.0001156 4655   1.85912  0.0631
 Correlation: 
                     (Intr) tmprtr gentyp
temperature          -0.794              
genotype             -0.864  0.688       
temperature:genotype  0.687 -0.866 -0.795

Standardized Within-Group Residuals:
        Min          Q1         Med          Q3         Max 
-3.59940153 -0.64226045 -0.03134888  0.60768582  4.54919777 

Number of Observations: 4857
Number of Groups: 200 

Could anyone help me with this please?

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • Please consider formatting your code correctly. The above code is impossible to read! –  May 06 '16 at 15:20

1 Answers1

2

The nlme package does have a VarCorr() extractor function:

library(nlme)
fm2 <- lme(distance ~ age + Sex, data = Orthodont, random = ~ 1|Subject)
(v <- VarCorr(fm2))
## Subject = pdLogChol(1) 
##             Variance StdDev  
## (Intercept) 3.266784 1.807425
## Residual    2.049456 1.431592

However, trying str(v) or naively trying to extract the value will show that this is unfortunately a character matrix, so you have to do as.numeric() as well:

as.numeric(v[,"Variance"])
Ben Bolker
  • 211,554
  • 25
  • 370
  • 453