plot_sensitivity: Plotting Sensitivities of a Stressed Model

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/plot_sensitivity.R

Description

Plots the sensitivity measures for components (random variables) of a stochastic model under the scenario weights.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
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 SWIM or SWIMw object.

xCol

Numeric or character vector, (names of) the columns of the underlying data of the object (default = "all"). If xCol = NULL, only the transformed data f(x) is considered.

wCol

Vector, the columns of the scenario weights of the object corresponding to different stresses (default = "all").

type

Character, one of "Gamma", "Kolmogorov", "Wasserstein", "reverse", "all" (default = "all").

f

A function, or list of functions, that, applied to x, constitute the transformation of the data for which the sensitivity is calculated.

k

A vector or list of vectors, same length as f, indicating which columns of x each function in f operates on.
When f is a list, k[[i]] corresponds to the input variables of f[[i]].

s

A function that, applied to x, defines the reverse sensitivity measure. If type = "reverse" and s = NULL, defaults to type = "Gamma".

displ

Logical, if TRUE the plot is displayed, otherwise the data.frame for customised plotting with ggplot is returned (default = TRUE).

p

Numeric vector, the p-th moment of Wasserstein distance (default = 1).

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## 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")

spesenti/SWIM documentation built on Jan. 15, 2022, 11:19 a.m.