# NOT RUN {
set.seed(0)
x <- data.frame(cbind(
"normal" = rnorm(1000),
"gamma" = rgamma(1000, shape = 2),
"beta" = rbeta(1000, shape1 = 2, shape2 = 2)))
## stressing covariance of columns 1, 2 while leaving the means unchanged
res1 <- stress_moment(x = x,
f = list(function(x)x, function(x)x, function(x)x[1] * x[2]),
k = list(1, 2, c(1, 2)), m = c(0, 2, 0.5),
method = "Newton", control = list(maxit = 1000, ftol = 1E-10))
## means under the stressed model
summary(res1)
apply(x, 2, stats::weighted.mean, w = get_weights(res1))
## covariance of columns 1,2 under the stressed model
stats::weighted.mean(x[, 1] * x[, 2], w = get_weights(res1))
## stressing jointly the tail probabilities of columns 1, 3
res2 <- stress_moment(x = x,
f = list(function(x)(x > 1.5), function(x)(x > 0.9)),
k = list(1, 3), m = c(0.9, 0.9))
summary(res2)
## probabilities under the stressed model
mean((x[, 1] > 1.5) * get_weights(res2))
mean((x[, 3] > 0.9) * get_weights(res2))
# }
Run the code above in your browser using DataLab