rn_vplas: Compute the purely environmental plastic variance...

View source: R/rn_plas.R

rn_vplasR Documentation

Compute the purely environmental plastic variance V_{\text{Plas}}

Description

This function calculates the purely environmental plastic variance arising from the average (across genotypes) shape of the reaction norm.

Usage

rn_vplas(theta, V_theta, 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)

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 V_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{Plas}} is the variance arising from the shape of the reaction norm after avering over the genetic variance, i.e. the purely environmental part of the variance of plasticity in the reaction norm.

It is very important that the parameters are in the same order in theta (which, again, must be named) and in V_theta.

Value

This function yields V_{\text{Plas}} (numeric).

Author(s)

Pierre de Villemereuil

See Also

rn_mean_by_env, rn_pi_decomp, rn_vgen, rn_vtot

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)

# Computing V_plas
rn_vplas(theta   = theta,
         V_theta = G,
         env     = vec_env,
         shape   = expr,
         fixed   = c(3, 4))
# Note that fixed is set for the third and forth parameters than are not in G

# Note the quite large difference when Bessel's correction is used
rn_vplas(theta   = theta,
         V_theta = G,
         env     = vec_env,
         shape   = expr,
         fixed   = c(3, 4),
         correction = TRUE)
         
# It is possible to weight the environment, e.g. according to a normal distribution
rn_vplas(theta   = theta,
         V_theta = G,
         env     = vec_env,
         shape   = expr,
         fixed   = c(3, 4),
         wt_env  = dnorm(vec_env),
         correction = TRUE)

# If a polynomial was used, it is possible to use the linear modeling rather having
# to compute integrals
theta <- c(a = 1.5, b = 0.5, c = -0.5)
X     <- cbind(1, vec_env, (vec_env - mean(vec_env))^2)
S     <- (10^-4) * diag(3)
rn_vplas(theta = theta, X = X, S = S)

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