| Title: | Perform a Partition of Variance of Reaction Norms |
|---|---|
| Description: | Partitions the phenotypic variance of a plastic trait, studied through its reaction norm. The variance partition distinguishes between the variance arising from the average shape of the reaction norms (V_Plas) and the (additive) genetic variance . The latter is itself separated into an environment-blind component (V_G/V_A) and the component arising from plasticity (V_GxE/V_AxE). The package also provides a way to further partition V_Plas into aspects (slope/curvature) of the shape of the average reaction norm (pi-decomposition) and partition V_Add (gamma-decomposition) and V_AxE (iota-decomposition) into the impact of genetic variation in the reaction norm parameters. Reference: de Villemereuil & Chevin (2025) <doi:10.32942/X2NC8B>. |
| Authors: | Pierre de Villemereuil [aut, cre] |
| Maintainer: | Pierre de Villemereuil <[email protected]> |
| License: | GPL-3 |
| Version: | 0.2.1 |
| Built: | 2026-05-15 08:53:33 UTC |
| Source: | https://github.com/devillemereuil/reacnorm |
A simulated dataset on the reaction norm of aggressiveness and thermal performance of dragons measured directly in a wild population, with heterogenous temperatures. Offspring from the same mothers are considered as half-sibs.
dragon_continuousdragon_continuous
A data frame with 1000 rows and 5 variables:
The individual on which the measures were performed at the different temperatures.
The family to which each individual belongs to, i.e.\ which mother they are the offspring off. Offspring from the same mothers are considered as half-sibs.
The value of the recorded temperature at which the experiment was performed in the field. For convenience, the value was standardised so that the average is 0.
Aggressiveness of the dragon, measured using a very precise, continuous index, when presented with an armored knight to combat in the field.
Performance (sprint speed to rush toward a dummy princess) of each individual dragon evaluated directly on the field.
A simulated dataset on the reaction norm of aggressiveness and thermal performance of dragons according to a series of experimental measures at a discretised gradient of temperature
dragon_discretedragon_discrete
A data frame with 1000 rows and 5 variables:
A character string for the "name" of the experimental temperature at which the experiment was performed.
The value of the experimental temperature at which the experiment was performed. For convenience, the value was standardised so that the average is 0.
The individual on which the measures were performed at the different temperatures.
Aggressiveness of the dragon, measured using a very precise, continuous index, when presented with an armored knight to combat.
Performance (sprint speed to rush toward a dummy princess) of each individual dragon evaluated at each of the experimental temperatures.
-matrix from a character-state modelThis function takes the -matrix estimated from a character-state model and returns the values for , , and
rn_cs_gen(G_cs, wt = NULL)rn_cs_gen(G_cs, wt = NULL)
G_cs |
(Additive) genetic variance-covariance matrix estimated from a character-state model (i.e. where environments are treated as a categorical variable). (numerical matrix) |
wt |
Weights to apply to the different environments, e.g. reflecting their frequencies in the wild. The weights must non-negative, and at least one must be non-zero. The vector |
is the (weighted) average of the diagonal elements of G_cs, is the (weighted) average of all the elements of G_cs and is the difference between and . Finally, the efficient number of dimensions is the ratio of the sum of the eigen values of G_cs over its maximum eigen value. Note that is returned for information, but is expected to be biased in practice due to an over-estimation of the maximum eigen value.
This function yields , , and as a one-row data.frame (data.frame, all numeric).
Pierre de Villemereuil
G <- diag(10) rn_cs_gen(G_cs = G)G <- diag(10) rn_cs_gen(G_cs = G)
-decomposition of additive genetic variance per environmentThis function computes the -decomposition of the additive genetic variance for each environment.
rn_gamma_env(theta, G_theta, env = NULL, shape = NULL, X = NULL, fixed = NULL, width = 10)rn_gamma_env(theta, G_theta, env = NULL, shape = NULL, X = NULL, fixed = NULL, width = 10)
theta |
Average parameters of the shape function. It must be a named vector, with the names corresponding to the parameters in the |
G_theta |
Genetic variance-covariance matrix of the parameters. It can be of lesser dimensions than |
env |
Vector of environmental values (numeric). |
shape |
Expression providing the shape of the reaction where |
X |
If the model used was linear in the parameters, the design matrix X of the model (numeric, incompatible with the arguments |
fixed |
If some parameters of |
width |
Parameter for the integral computation. The integral is evaluated from |
This function provides the -decomposition (according to each parameter of the reaction norm and their covariances) of the additive genetic variance in each environment.
It is very important that the parameters are in the same order in the argument of the shape function, in theta and in G_theta.
If X is provided the second column is returned as the value for the "environment" (based on the assumption that a polynomial function was used).
This function yields a data.frame containing the input values for the environment, the additive genetic variance in each of them, with its corresponding -decomposition (data.frame, all numeric).
Pierre de Villemereuil
# 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_gen rn_gamma_env(env = vec_env, shape = expr, theta = theta, G_theta = G, fixed = c(3, 4)) # Note that fixed is set for the third and forth parameters than are not in G # 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) G <- 0.1 * diag(3) rn_gamma_env(theta = theta, G_theta = G, X = X)# 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_gen rn_gamma_env(env = vec_env, shape = expr, theta = theta, G_theta = G, fixed = c(3, 4)) # Note that fixed is set for the third and forth parameters than are not in G # 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) G <- 0.1 * diag(3) rn_gamma_env(theta = theta, G_theta = G, X = X)
- and -decompositionThis function calculates the total additive genetic variance of the reaction norm (, and its -decomposition), the marginal additive genetic variance of the trait () and the additive genetic variance of plasticity (, and its -decomposition).
rn_gen_decomp(theta, G_theta, env = NULL, shape = NULL, X = NULL, fixed = NULL, wt_env = NULL, compute_gamma = TRUE, compute_iota = TRUE, add_vars = NULL, width = 10)rn_gen_decomp(theta, G_theta, env = NULL, shape = NULL, X = NULL, fixed = NULL, wt_env = NULL, compute_gamma = TRUE, compute_iota = TRUE, add_vars = NULL, width = 10)
theta |
Average parameters of the shape function. It must be a named vector, with the names corresponding to the parameters in the |
G_theta |
Genetic variance-covariance matrix of the parameters. It can be of lesser dimensions than |
env |
Vector of environmental values (numeric). |
shape |
Expression providing the shape of the reaction where |
X |
If the model used was linear in the parameters, the design matrix X of the model (numeric, incompatible with the arguments |
fixed |
If some parameters of |
wt_env |
Weights to apply to the |
compute_gamma |
Should the |
compute_iota |
Should the |
add_vars |
Optional, provide additive genetic variances |
width |
Parameter for the integral computation. The integral is evaluated from |
The variance is the total additive genetic variance in the reaction norm. It can be decomposed according to each of the parameters in G_theta (and their pairwise covariance), using the -decomposition, if the compute_gamma is activated. It can also be decomposed into the marginal additive genetic variance of the trait (, the additive genetic variance of the trait that would be computed if plasticity were ignored), and the additive genetic variance of plasticity itself (, i.e. the genetic-by-environment interaction variance). This last component can also be decomposed according to each of the parameters in G_theta (and their pairwise covariance), using the -decomposition (for interaction).
It is very important that the parameters are in the same order in the argument of the shape function, in theta and in G_theta.
This function yields the values for , and , as well as the - and -decomposition if requested, formatted as a 1-row data.frame (data.frame, all numeric).
Pierre de Villemereuil
# 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_gen out <- rn_gen_decomp(theta = theta, G_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 # Checking that V_Add = V_A + V_AxE out$V_Add == out$V_A + out$V_AxE # Checking that the sum of \eqn{\gamma}'s is 1 out$Gamma_cmax + out$Gamma_xopt + out$Gamma_cmax_xopt # Checking that the sum of \eqn{\iota}'s is 1 out$Iota_cmax + out$Iota_xopt + out$Iota_cmax_xopt # Applying some weighting to the environmental values according to a normal distribution rn_gen_decomp(theta = theta, G_theta = G, env = vec_env, shape = expr, fixed = c(3, 4), wt_env = dnorm(vec_env)) # 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) G <- 0.1 * diag(3) rn_gen_decomp(theta = theta, G_theta = G, X = X)# 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_gen out <- rn_gen_decomp(theta = theta, G_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 # Checking that V_Add = V_A + V_AxE out$V_Add == out$V_A + out$V_AxE # Checking that the sum of \eqn{\gamma}'s is 1 out$Gamma_cmax + out$Gamma_xopt + out$Gamma_cmax_xopt # Checking that the sum of \eqn{\iota}'s is 1 out$Iota_cmax + out$Iota_xopt + out$Iota_cmax_xopt # Applying some weighting to the environmental values according to a normal distribution rn_gen_decomp(theta = theta, G_theta = G, env = vec_env, shape = expr, fixed = c(3, 4), wt_env = dnorm(vec_env)) # 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) G <- 0.1 * diag(3) rn_gen_decomp(theta = theta, G_theta = G, X = X)
This function calculates the phenotypic mean on the observed scale from the latent mean and variance.
rn_mean_by_env(theta, V_theta, env, shape, fixed = NULL, width = 10)rn_mean_by_env(theta, V_theta, env, shape, fixed = NULL, width = 10)
theta |
Average parameters of the shape function. It must be a named vector, with the names corresponding to the parameters in the |
V_theta |
Full variance-covariance matrix of the parameters. It can be of lesser dimensions than |
env |
Vector of environmental values (numeric). |
shape |
Expression providing the shape of the reaction where |
fixed |
If some parameters of |
width |
Parameter for the integral computation. The integral is evaluated from |
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.
This function yields the phenotypic mean for each value of the environmental vector provided (numeric).
Pierre de Villemereuil
# 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 )# 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 )
-decomposition of
This function calculates, for a linear (in its parameters) model, the plastic variance of the average (over genotypes) reaction norm shape and its -decomposition (depending on the parameters rather than slope/curvature). This is especially useful when the reaction norm model was a polynomial.
rn_phi_decomp(theta, X, S = NULL, wt_env = NULL, correction = FALSE, v_plas = NA)rn_phi_decomp(theta, X, S = NULL, wt_env = NULL, correction = FALSE, v_plas = NA)
theta |
Average parameters of the shape function. It must be a named vector, with the names corresponding to the parameters in the |
X |
The design matrix X of the reaction norm model. For a polynomial, X contains all the exponents of the environment. (numerical matrix) |
S |
The error variance-covariance matrix of the estimated fixed effects |
wt_env |
Weights to apply to the |
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) |
v_plas |
If already computed, an estimate for |
The variance 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. Its -decomposition is based on the parameters of the linear model , rather than on slope and curvature, as for the -decomposition.
It is very important that the parameters are in the same order in theta (which, again, must be named) and in G_theta.
This function yields the -decomposition of as a one-row data.frame. If was provided as an argument (e.g. as computed from a separate character-state model), it also outputs , the ratio between as computed from the linear model parameters and the provided value for (data.frame, all numeric).
Pierre de Villemereuil
# Parameters vec_env <- rnorm(20) 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) # Computing the phi-decomposition rn_phi_decomp(theta = theta, X = X, S = S)# Parameters vec_env <- rnorm(20) 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) # Computing the phi-decomposition rn_phi_decomp(theta = theta, X = X, S = S)
-decomposition of
This function calculates the plastic variance of the average (over genotypes) reaction norm shape and its -decomposition into and .
rn_pi_decomp(theta, V_theta, env, shape, fixed = NULL, wt_env = NULL, correction = FALSE, width = 10)rn_pi_decomp(theta, V_theta, env, shape, fixed = NULL, wt_env = NULL, correction = FALSE, width = 10)
theta |
Average parameters of the shape function. It must be a named vector, with the names corresponding to the parameters in the |
V_theta |
Full variance-covariance matrix of the parameters. It can be of lesser dimensions than |
env |
Vector of environmental values (numeric). |
shape |
Expression providing the shape of the reaction where |
fixed |
If some parameters of |
wt_env |
Weights to apply to the |
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 |
The variance is the variance arising from the shape of the reaction norm after averaging over the genetic variance, i.e. the purely environmental part of the variance of plasticity in the reaction norm. Its -decomposition into a slope () and curvature () components allows to distinguish the importance of each of those components in . Note that the -decomposition requires that the environmental variable is normally distributed, or that the reaction norm shape is quadratic.
It is very important that the parameters are in the same order in theta (which, again, must be named) and in V_theta.
This function yields the -decomposition of as a one-row data.frame (data.frame, all numeric).
Pierre de Villemereuil
# Some environment vector vec_env <- rnorm(20) # 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 the pi-decomposition of V_Plas rn_pi_decomp(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 # Applying some weighting to the environmental values according to a normal distribution # if the env variable is actually fixed vec_env2 <- seq(-2, 2, length.out = 20) rn_pi_decomp(theta = theta, V_theta = G, env = vec_env2, shape = expr, fixed = c(3, 4), wt_env = dnorm(vec_env2))# Some environment vector vec_env <- rnorm(20) # 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 the pi-decomposition of V_Plas rn_pi_decomp(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 # Applying some weighting to the environmental values according to a normal distribution # if the env variable is actually fixed vec_env2 <- seq(-2, 2, length.out = 20) rn_pi_decomp(theta = theta, V_theta = G, env = vec_env2, shape = expr, fixed = c(3, 4), wt_env = dnorm(vec_env2))
This function calculates the total genetic variance arising from genetic variation in the reaction norm.
rn_vgen(theta, G_theta, env = NULL, shape = NULL, X = NULL, fixed = NULL, wt_env = NULL, average = TRUE, width = 10)rn_vgen(theta, G_theta, env = NULL, shape = NULL, X = NULL, fixed = NULL, wt_env = NULL, average = TRUE, width = 10)
theta |
Average parameters of the shape function. It must be a named vector, with the names corresponding to the parameters in the |
G_theta |
Genetic variance-covariance matrix of the parameters. It can be of lesser dimensions than |
env |
Vector of environmental values (numeric). |
shape |
Expression providing the shape of the reaction where |
X |
If the model used was linear in the parameters, the design matrix X of the model (numeric, incompatible with the arguments |
fixed |
If some parameters of |
wt_env |
Weights to apply to the |
average |
Should the values for each environment be given, or just their average (default)? (boolean) |
width |
Parameter for the integral computation. The integral is evaluated from |
The variance is the total genetic variance in the reaction norm. If the reaction norm is linear in its parameters, then is it also equal to the total additive genetic variance in the reaction norm (). Otherwise, see the function rn_gen_decomp to compute .
It is very important that the parameters are in the same order in the argument of the shape function, in theta and in G_theta.
This function yields the genetic variance arising from all the genetic variation in the reaction norm (numeric).
Pierre de Villemereuil
rn_gen_decomp, rn_vplas, rn_vtot
# 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_gen rn_vgen(theta = theta, G_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 # Applying some weighting according to a normal distribution rn_vgen(theta = theta, G_theta = G, env = vec_env, shape = expr, fixed = c(3, 4), wt_env = dnorm(vec_env)) # Setting average to FALSE allows to obtain the value for each environment rn_vgen(theta = theta, G_theta = G, env = vec_env, shape = expr, fixed = c(3, 4), average = FALSE) # 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) G <- 0.1 * diag(3) rn_vgen(theta = theta, G_theta = G, X = X) # Should be very close to the computation with integration rn_vgen(theta = theta, G_theta = G, env = vec_env, shape = expression(a + b * x + c * x^2))# 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_gen rn_vgen(theta = theta, G_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 # Applying some weighting according to a normal distribution rn_vgen(theta = theta, G_theta = G, env = vec_env, shape = expr, fixed = c(3, 4), wt_env = dnorm(vec_env)) # Setting average to FALSE allows to obtain the value for each environment rn_vgen(theta = theta, G_theta = G, env = vec_env, shape = expr, fixed = c(3, 4), average = FALSE) # 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) G <- 0.1 * diag(3) rn_vgen(theta = theta, G_theta = G, X = X) # Should be very close to the computation with integration rn_vgen(theta = theta, G_theta = G, env = vec_env, shape = expression(a + b * x + c * x^2))
This function calculates the total phenotypic variance arising along and beyond the reaction norm, i.e. including the residual variance.
rn_vp_env(theta, V_theta, var_res, env = NULL, shape = NULL, X = NULL, fixed = NULL, wt_env = NULL, width = 10)rn_vp_env(theta, V_theta, var_res, env = NULL, shape = NULL, X = NULL, fixed = NULL, wt_env = NULL, width = 10)
theta |
Average parameters of the shape function. It must be a named vector, with the names corresponding to the parameters in the |
V_theta |
Full variance-covariance matrix of the parameters. It can be of lesser dimensions than |
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 |
Vector of environmental values (numeric). |
shape |
Expression providing the shape of the reaction where |
X |
If the model used was linear in the parameters, the design matrix X of the model (numeric, incompatible with the arguments |
fixed |
If some parameters of |
wt_env |
Weights to apply to the |
width |
Parameter for the integral computation. The integral is evaluated from |
The phenotypic variance at a given environment depends on the variation in the parameters and the residual variance. It thus account for everything but the variance due to the average shape of the reaction norm (i.e. ).
This function yields the phenotypic variance in each environment (numerical vector).
Pierre de Villemereuil
# 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_vp_env(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# 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_vp_env(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
This function calculates the purely environmental plastic variance arising from the average (across genotypes) shape of the reaction norm.
rn_vplas(theta, V_theta, env = NULL, shape = NULL, X = NULL, S = NULL, fixed = NULL, wt_env = NULL, correction = FALSE, width = 10)rn_vplas(theta, V_theta, env = NULL, shape = NULL, X = NULL, S = NULL, fixed = NULL, wt_env = NULL, correction = FALSE, width = 10)
theta |
Average parameters of the shape function. It must be a named vector, with the names corresponding to the parameters in the |
V_theta |
Full variance-covariance matrix of the parameters. It can be of lesser dimensions than |
env |
Vector of environmental values (numeric). |
shape |
Expression providing the shape of the reaction where |
X |
If the model used was linear in the parameters, the design matrix X of the model (numeric, incompatible with the arguments |
S |
The error variance-covariance matrix of the estimated fixed effects |
fixed |
If some parameters of |
wt_env |
Weights to apply to the |
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 |
The variance 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.
This function yields (numeric).
Pierre de Villemereuil
rn_mean_by_env, rn_pi_decomp, rn_vgen, rn_vtot
# 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)# 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)
This function calculates the total phenotypic variance arising along and beyond the reaction norm, i.e. including the residual variance.
rn_vtot(theta, V_theta, var_res, env = NULL, shape = NULL, X = NULL, S = NULL, fixed = NULL, wt_env = NULL, correction = FALSE, width = 10)rn_vtot(theta, V_theta, var_res, env = NULL, shape = NULL, X = NULL, S = NULL, fixed = NULL, wt_env = NULL, correction = FALSE, width = 10)
theta |
Average parameters of the shape function. It must be a named vector, with the names corresponding to the parameters in the |
V_theta |
Full variance-covariance matrix of the parameters. It can be of lesser dimensions than |
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 |
Vector of environmental values (numeric). |
shape |
Expression providing the shape of the reaction where |
X |
If the model used was linear in the parameters, the design matrix X of the model (numeric, incompatible with the arguments |
S |
The error variance-covariance matrix of the estimated fixed effects |
fixed |
If some parameters of |
wt_env |
Weights to apply to the |
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 |
The variance is the total phenotypic variance of the trait along and beyond the reaction norm. In the simplest case, it is equal to the sum , in which case this function is rather useless. But in cases where the parameters in the reaction norm curve is fitted with more than the (additive) genetic effect, then computing becomes non-trivial. This function allows to do it, e.g. by providing (i) a way to specify the full variation assumed in , using the V_theta full variance-covariance argument, and (ii) a way to specify a varying residual variance by environment.
This function yields the total phenotypic variance along and beyond the reaction norm (numeric).
Pierre de Villemereuil
# 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# 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