rn_vtot: Compute the total phenotypic variance V_{\text{Tot}}

View source: R/rn_tot.R

rn_vtotR Documentation

Compute the total phenotypic variance V_{\text{Tot}}

Description

This function calculates the total phenotypic variance V_{\text{Tot}} arising along and beyond the reaction norm, i.e. including the residual variance.

Usage

rn_vtot(theta, V_theta, var_res, env = NULL, shape = NULL, X = NULL, S = NULL,
        fixed = NULL, wt_env = NULL, correction = FALSE, width = 10)

Arguments

theta

Average parameters of the shape function. It must be a named vector, with the names corresponding to the parameters in the shape expression. (numeric)

V_theta

Full variance-covariance matrix of the parameters. It can be of lesser dimensions than theta, see fixed parameter. (numerical matrix)

var_res

Residual variance beyond the reaction norm. It could be a scalar if this residual variance is assumed homogeneous or a vector the same length as env (or number of rows of X), if the residual variance is allowed to vary across the environment. (numeric scalar or vector)

env

Vector of environmental values (numeric).

shape

Expression providing the shape of the reaction where x is the environment. For example: expression(a + b * x + c * x^2).

X

If the model used was linear in the parameters, the design matrix X of the model (numeric, incompatible with the arguments env and shape).

S

The error variance-covariance matrix of the estimated fixed effects theta. Used only if the X argument is used. (numeric, incompatible with the arguments env and shape).

fixed

If some parameters of shape, included in theta are not included in the G_theta matrix, then those dimensions are considered as genetically "fixed". Hence, fixed should contain a vector of the index of those parameters. Otherwise (if all parameters vary genetically), and by default, fixed should be set as NA. (integer)

wt_env

Weights to apply to the env vector values, providing an information regarding their relative probability in the biological context. The weights must non-negative, and at least one must non-zero. The vector wt_env must be the same length as env. By default, no weighting is applied. (numeric)

correction

Should Bessel's correction (dividing the sum-of-squares by N-1 rather than N) be used (TRUE) or not (FALSE, default). The default is FALSE, because it is likely that other components such as the total phenotypic variance is computed over the number of individuals (generally large number) rather than the number of environments (generally small number). The best is to manually use Bessel's correction over the proper number of data points. (boolean)

width

Parameter for the integral computation. The integral is evaluated from mu - width * sqrt(var) to mu + width * sqrt(var). The default value is 10, which should be sensible for most models. (numeric)

Details

The variance V_{\text{Tot}} is the total phenotypic variance of the trait along and beyond the reaction norm. In the simplest case, it is equal to the sum V_{\text{Plas}} + V_{\text{Gen}} + V_{\text{Res}}, in which case this function is rather useless. But in cases where the parameters \theta in the reaction norm curve is fitted with more than the (additive) genetic effect, then computing V_{\text{Tot}} becomes non-trivial. This function allows to do it, e.g. by providing (i) a way to specify the full variation assumed in \theta, using the V_theta full variance-covariance argument, and (ii) a way to specify a varying residual variance by environment.

Value

This function yields the total phenotypic variance along and beyond the reaction norm (numeric).

Author(s)

Pierre de Villemereuil

See Also

rn_vplas, rn_vgen

Examples

# Some environment vector
vec_env <- seq(-2, 2)

# Shape function
expr <- expression(
     cmax * exp(
         - exp(rho * (x - xopt) - 6) -
             sigmagaus * (x - xopt)^2
     ))

# Theta
theta <- c(cmax = 1, xopt = 0.9, rho = 8, sigmagaus = 0.4)
# G, only for cmax and xopt
G     <- matrix(c(0.1,      0.01,
                  0.01,     0.05),
                ncol = 2)
# Another covariance matrix for cmax and xopt (e.g. permanent environment, or maternal effet)
M     <- matrix(c(0.05,      0,
                  0,      0.01),
                ncol = 2)
# Full variance-covariance matrix
P     <- G + M
# Residual variance
vr    <- 0.1
                
# Computing V_tot
rn_vtot(theta   = theta,
        V_theta = P,
        var_res = vr,
        env     = vec_env,
        shape   = expr,
        fixed   = c(3, 4))
# Note that fixed is set for the third and forth parameters than are not in P

# With varying residual variance along the environmental (here with environmental variance)
vr    <- 0.05 * (vec_env^2)
rn_vtot(theta   = theta,
        V_theta = P,
        var_res = vr,
        env     = vec_env,
        shape   = expr,
        fixed   = c(3, 4))
# Same result because the average of Vr is the same as the unique value above

Reacnorm documentation built on April 3, 2025, 9:24 p.m.