rn_mean_by_env: Compute the phenotypic mean on the observed scale

View source: R/rn_plas.R

rn_mean_by_envR Documentation

Compute the phenotypic mean on the observed scale

Description

This function calculates the phenotypic mean on the observed scale from the latent mean and variance.

Usage

rn_mean_by_env(theta, V_theta, env, shape, fixed = NULL, 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).

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)

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

This function yields the phenotypic average (across genotypes) for each value of the environment. If the reaction norm is not linear in its parameters (the parameters in theta), then this average will generaly differ from the value yielded by shape evaluated at values in theta.

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 the phenotypic mean for each value of the environmental vector provided (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)

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

# This is (slightly) different from the function evaluated
# using the average values of the parameters in theta 
theta["cmax"] * exp(
         - exp(theta["rho"] * (vec_env - theta["xopt"]) - 6) -
             theta["sigmagaus"] * (vec_env - theta["xopt"])^2
     )

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