# 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)
Run the code above in your browser using DataLab