herit: Calculate heritability from fitted model

Description Usage Arguments Details Examples

View source: R/herit.R

Description

Calculates the heritability (on an entry-mean basis) of a trait given a fitted model object

Usage

1
2
3
4
5
6
7
herit(object, exp, ...)

## S3 method for class 'lm'
herit(object, exp, ms.exp, ...)

## S3 method for class 'lmerMod'
herit(object, exp, ...)

Arguments

object

A model object. See Details for accepted classes.

exp

A quoted expression used to calculate the heritability. For instance, "geno / (geno + (Residual / r))". Variables in the expression should be variance components derived from restricted maximum likelihood (REML) or from the mean squares from an ANOVA table.

...

Other arguments to pass. This is generally a list of other objects that are in exp, but may not be found in object. For instance, if the argument exp = "geno / (geno + (Residual / r))" was passed, you would also pass the argument r = 2.

ms.exp

A named list of expressions used to calculate the variance components. The names of the list should be names of the variance components used in the heritability expression (exp). Note the expected residual variance is equal to the observed mean squares for the residuals. See Examples for examples.

Details

Accepted classes for object are:

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Use the gauch.soy dataset
data("gauch.soy")

# Filter
gauch_soy1 <- gauch.soy %>%
  group_by(env) %>%
  filter(n_distinct(gen, rep) == 28)

# Set the number of reps and number of environments
n_r <- 4
n_e <- 36

# Fit a linear model using lm
lm_mod <- lm(yield ~ gen + env + gen:env + rep:env, data = gauch_soy1)

# Variance components from a fixed effects model are derived from the ANOVA table.
# The function also required expressions to calculate the variance components
ms.exp <- list("gen:env" = "(gen:env - Residuals) / n_r",
               "gen" = "(gen - gen:env) / (n_r * n_e)")

exp = "gen / (gen + (gen:env / n_e) + (Residuals / n_r))"

herit(object = lm_mod, exp = exp, ms.exp = ms.exp, n_r = n_r, n_e = n_e)

# Fit a linear model using lmer
lmer_mod <- lmer(yield ~ (1|gen) + (1|env) + (1|gen:env) + (1|env:rep), data = gauch_soy1)
# Calculate heritability
herit(object = lmer_mod, exp = "gen / (gen + (gen:env / n_e) + (Residual / n_r))",
      n_r = n_r, n_e = n_e)

neyhartj/pbr documentation built on Jan. 7, 2020, 9:24 a.m.