plot_hist: Plotting Histograms of a Stressed Model

Description Usage Arguments Value See Also Examples

View source: R/plot_hist.R

Description

Plots the histogram of a stressed model component (random variable) under the scenario weights.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
plot_hist(
  object,
  xCol = 1,
  wCol = "all",
  base = FALSE,
  x_limits,
  displ = TRUE,
  binwidth,
  displLines = FALSE
)

Arguments

object

A SWIM or SWIMw object.

xCol

Numeric or character, (name of) the column of the underlying data of the object (default = 1).

wCol

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

base

Logical, if TRUE, statistics under the baseline are also returned (default = "FALSE").

x_limits

Vector, the limits of the x-axis of the plot, the value for xlim in the coord_cartesian function in ggplot.

displ

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

binwidth

Numeric, the width of the bins used to plot the histogram, the binwidth in the geom_freqpoly function in ggplot (default corresponds to 30 bins).

displLines

Logical, if TRUE lines are displayed instead of bins (default = FALSE).

Value

If displ = TRUE, a histogram 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], y = ..density.., weight = value)))

+ geom_{freqpoly}(binwidth, aes(color = factor(stress))).

See Also

See cdf and plot_cdf for values and plotting of the empirical distribution function of a stressed model, respectively, and quantile_stressed for sample quantiles of a stressed model.

Examples

1
2
3
4
5
6
7
## example with a stress on VaR
set.seed(0)
x <- data.frame("gamma" = rgamma(10^5, shape = 2))
res1 <- stress(type = "VaR", x = x,
  alpha = c(0.75, 0.95), q_ratio = 1.1)
plot_hist(res1, xCol = "gamma", wCol = 1:2, base = TRUE, binwidth = 0.4)
plot_hist(res1, xCol = "gamma", wCol = 1:2, base = TRUE, binwidth = 0.4, displLines = TRUE)

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