plot_sensitivity {SWIM} | R Documentation |
Plotting Sensitivities of a Stressed Model
Description
Plots the sensitivity measures for components (random variables) of a stochastic model under the scenario weights.
Usage
plot_sensitivity(
object,
xCol = "all",
wCol = "all",
type = c("Gamma", "Kolmogorov", "Wasserstein", "reverse", "all"),
f = NULL,
k = NULL,
s = NULL,
displ = TRUE,
p = 1
)
Arguments
object |
A |
xCol |
Numeric or character vector, (names of) the columns
of the underlying data of the |
wCol |
Vector, the columns of the scenario weights
of the |
type |
Character, one of |
f |
A function, or list of functions, that, applied to
|
k |
A vector or list of vectors, same length as |
s |
A function that, applied to |
displ |
Logical, if |
p |
Numeric vector, the p-th moment of Wasserstein distance ( |
Details
For the definition of the sensitivity
measures (type
), see sensitivity
.
Note that the Kolmogorov distance is the same for all inputs under the same stress for a SWIM object. Thus, it should only be used to compare different stresses, not individual components.
Value
If displ = TRUE
, a plot displaying the sensitivity
measures of the stochastic model under the scenario weights.
If displ = FALSE
, a data.frame for customised plotting with
ggplot
. The data.frame
contains the columns: stress
(the stresses), type
(the types of sensitivity), X_all
(the random variables),
value
(the values of the sensitivities).
Denote by result
the return of the function call, then
ggplot
can be called via:
ggplot(result, aes(x = X_{all}, y = value))
+ geom_{point}(aes(color = factor(stress), shape = type)).
Author(s)
Silvana M. Pesenti
See Also
See sensitivity
for the values of the
sensitivity measures of a stressed model and
importance_rank
for ranking of random
variables according to their sensitivities.
Examples
## Consider the portfolio Y = X1 + X2 + X3 + X4 + X5,
## where (X1, X2, X3, X4, X5) are correlated normally
## distributed with equal mean and different standard deviations,
## see the README for further details.
set.seed(0)
SD <- c(70, 45, 50, 60, 75)
Corr <- matrix(rep(0.5, 5 ^ 2), nrow = 5) + diag(rep(1 - 0.5, 5))
if (!requireNamespace("mvtnorm", quietly = TRUE))
stop("Package \"mvtnorm\" needed for this function
to work. Please install it.")
x <- mvtnorm::rmvnorm(10 ^ 5,
mean = rep(100, 5),
sigma = (SD %*% t(SD)) * Corr)
data <- data.frame(rowSums(x), x)
names(data) <- c("Y", "X1", "X2", "X3", "X4", "X5")
rev.stress <- stress(type = "VaR", x = data,
alpha = c(0.75, 0.9), q_ratio = 1.1, k = 1)
sensitivity(rev.stress, type = "all")
plot_sensitivity(rev.stress, xCol = 2:6, type = "Gamma")
plot_sensitivity(rev.stress, xCol = 6, wCol = 1, type = "all")