Repeated measures animal model

How to fit and interpret permanent environment effects.
library(brms)
library(nadiv)
repeatedphenotypicdata <- read.csv("data/gryphonRepeatedMeas.csv")
pedigreedata <- read.csv("data/gryphonped.csv")
Amat <- nadiv::makeA(pedigree = pedigreedata)

The key to repeated measurement animal models is having a duplicate of the individual identity in the dataset. This allows to estimate a breeding value for each individual, that is connected to the relatedness matrix, and a permanent environment value that is not. Let’s keep id as the additive genetic random effect and call the duplicate pe (for permanent environment).

repeatedphenotypicdata$pe <- repeatedphenotypicdata$id

We will fit a random effect for id, one for pe and one for cohort:

brms_r1 <- 
  brm(lay_date ~ 1 + age +  (1 | gr(id, cov = Amat)) + (1|pe) + (1|cohort), 
      data = repeatedphenotypicdata,
      data2 = list(Amat = Amat), 
      family = gaussian(),
      chains = 4, cores = 4, iter = 2000)
## Warning: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.
## Running the chains for more iterations may help. See
## https://mc-stan.org/misc/warnings.html#bulk-ess

There is a bit of negative correlation between id and pe in the MCMC sampling, which is usual with that kind of models, because it is difficult to disentangle both of the individual effects:

pairs(brms_r1, variable = "^(sd|sigma)", regex = TRUE)

Assuming we are happy with the model fit, we can compute heritability as:

heritability1 <- 
  hypothesis(brms_r1, "sd_id__Intercept^2 / (sd_id__Intercept^2 + sd_pe__Intercept^2 + sd_cohort__Intercept^2 + sigma^2) = 0", class = NULL)
heritability1
## Hypothesis Tests for class :
##                 Hypothesis Estimate Est.Error CI.Lower CI.Upper Evid.Ratio Post.Prob Star
## 1 (sd_id__Intercept... = 0     0.17      0.05     0.07     0.28         NA        NA    *
## ---
## 'CI': 90%-CI for one-sided and 95%-CI for two-sided hypotheses.
## '*': For one-sided hypotheses, the posterior probability exceeds 95%;
## for two-sided hypotheses, the value tested against lies outside the 95%-CI.
## Posterior probabilities of point hypotheses assume equal prior probabilities.

and repeatability as:

repeatability1 <- 
  hypothesis(brms_r1, "(sd_id__Intercept^2 +  sd_pe__Intercept^2) / (sd_id__Intercept^2 + sd_pe__Intercept^2 + sd_cohort__Intercept^2 + sigma^2) = 0", class = NULL)
repeatability1
## Hypothesis Tests for class :
##                 Hypothesis Estimate Est.Error CI.Lower CI.Upper Evid.Ratio Post.Prob Star
## 1 ((sd_id__Intercep... = 0     0.34      0.03     0.28      0.4         NA        NA    *
## ---
## 'CI': 90%-CI for one-sided and 95%-CI for two-sided hypotheses.
## '*': For one-sided hypotheses, the posterior probability exceeds 95%;
## for two-sided hypotheses, the value tested against lies outside the 95%-CI.
## Posterior probabilities of point hypotheses assume equal prior probabilities.

If we want to take into account the variation due to age, the calculations become:

vars <- as_draws_matrix(brms_r1, variable = "^(sd_|sigma)", regex = TRUE)^2
predictions <- standata(brms_r1)$X %*% t(fixef(brms_r1, summary = FALSE))
fixef_variance <- apply(predictions, MARGIN = 2, var)

heritability2 <- vars[ , "sd_id__Intercept"] / (fixef_variance + rowSums(vars))
summary(heritability2)
## # A tibble: 1 × 10
##   variable          mean median     sd    mad     q5   q95  rhat ess_bulk ess_tail
##   <chr>            <dbl>  <dbl>  <dbl>  <dbl>  <dbl> <dbl> <dbl>    <dbl>    <dbl>
## 1 sd_id__Intercept 0.161  0.159 0.0509 0.0521 0.0803 0.248  1.02     334.     730.

and

repeatability2 <- (vars[ , "sd_id__Intercept"] + vars[ , "sd_pe__Intercept"] ) / (fixef_variance + rowSums(vars))
summary(repeatability2)
## # A tibble: 1 × 10
##   variable          mean median     sd    mad    q5   q95  rhat ess_bulk ess_tail
##   <chr>            <dbl>  <dbl>  <dbl>  <dbl> <dbl> <dbl> <dbl>    <dbl>    <dbl>
## 1 sd_id__Intercept 0.319  0.319 0.0289 0.0288 0.271 0.367  1.00    1146.    2061.

Reading to go further

  • Kruuk & Hadfield, 2007. How to separate genetic and environmental causes of similarity between relatives. Journal of Evolutionary Biology https://doi.org/10.1111/j.1420-9101.2007.01377.x
  • Ponzi & al, 2018. Heritability, selection, and the response to selection in the presence of phenotypic measurement error: Effects, cures, and the role of repeated measurements. Evolution https://doi.org/10.1111/evo.13573