plot_cdf {SWIM} | R Documentation |
Plotting the Distribution Functions of a Stressed Model
Description
Plots the empirical distribution function of a stressed SWIM model component (random variable) or KDE distribution function of a stressed SWIMw model component under the scenario weights.
Usage
plot_cdf(
object,
xCol = 1,
wCol = "all",
base = FALSE,
n = 500,
x_limits,
y_limits,
displ = TRUE
)
Arguments
object |
A |
xCol |
Numeric or character, (name of) the column of the underlying data
of the |
wCol |
Vector, the columns of the scenario weights
of the |
base |
Logical, if |
n |
Integer, the number of points used to plot
|
x_limits |
Vector, the limits of the x-axis of the plot, the
value for |
y_limits |
Vector, the limits of the y-axis of the plot, the
value for |
displ |
Logical, if |
Value
If displ = TRUE
, a plot displaying the empirical or KDE
distribution function 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: the column,
xCol
, of the data of the stressed model,
stress
(the stresses) and value
(the values).
Denote by res
the return of the function call, then
ggplot
can be called via:
ggplot(res, aes(x = res[ ,1], w = value))
+ stat_{ecdf}(aes(color = factor(stress)), n = n).
Note that the ggplot2 default of stat_ecdf
does not
take weight
as an aesthetic. We use the workaround
by Nicolas Woloszko, see Note below.
Note
This function is based on the ggplot stat_ecdf
function. However, the stat_ecdf
does not allow for
specifying weights
, thus the function is based on
the workaround by Nicolas Woloszko, see
https://github.com/NicolasWoloszko/stat_ecdf_weighted.
Author(s)
Silvana M. Pesenti, Zhuomin Mao
See Also
See cdf
for the empirical or KDE distribution function
of a stressed model and quantile_stressed
for
sample quantiles of a stressed model.
Examples
## example with a stress on VaR
set.seed(0)
x <- as.data.frame(cbind(
"normal" = rnorm(10 ^ 5),
"gamma" = rgamma(10 ^ 5, shape = 2)))
res1 <- stress(type = "VaR", x = x,
alpha = c(0.75, 0.95), q_ratio = 1.15)
plot_cdf(res1, xCol = 1, wCol = 1:2, base = TRUE)
plot_cdf(res1, xCol = 1, wCol = 1:2, base = TRUE,
x_limits = c(0, 5), y_limits = c(0.5, 1))