plot_pop: Add Population Line(s) to an Existing Grid

View source: R/plot_functions.R

plot_popR Documentation

Add Population Line(s) to an Existing Grid

Description

This function adds one (or multiple) linearized CDF(s) to an existing plot grid.

Usage

plot_pop(
  p_obj = NULL,
  x,
  dist_params_tbl,
  distribution = c("weibull", "lognormal", "loglogistic", "sev", "normal", "logistic",
    "exponential"),
  tol = 1e-06,
  title_trace = "Population",
  plot_method = c("plotly", "ggplot2")
)

Arguments

p_obj

A plot object to which the population line(s) is (are) added or NULL. If NULL the population line(s) is (are) plotted in an empty grid.

x

A numeric vector of length two or greater used for the x coordinates of the population line. If length(x) == 2 a sequence of length 200 between x[1] and x[2] is created. This sequence is equidistant with respect to the scale of the x axis. If length(x) > 2 the elements of x are the x coordinates of the population line.

dist_params_tbl

A data.frame. See 'Details'.

distribution

Supposed distribution of the random variable. The distinction between a threshold distribution and the respective standard variant is made with dist_params_tbl.

tol

The failure probability is restricted to the interval [tol, 1 - tol]. The default value is in accordance with the decimal places shown in the hover for plot_method = "plotly".

title_trace

A character string which is assigned to the legend trace.

plot_method

Package, which is used for generating the plot output. Only used when p_obj = NULL. If p_obj != NULL the plot object is used to determine the plot method.

Details

dist_params_tbl is a data.frame with parameter columns. An overview of the distribution-specific parameters and their order can be found in section 'Distributions'.

If only one population line should be displayed, a numeric vector is also supported. The order of the vector elements also corresponds to the table in section 'Distributions'.

Value

A plot object containing the linearized CDF(s).

Distributions

The following table summarizes the available distributions and their parameters

  • location parameter \mu,

  • scale parameter \sigma or \theta and

  • threshold parameter \gamma.

The column order within dist_params_tbl is given in the table header.

distribution dist_params_tbl[1] dist_params_tbl[2] dist_params_tbl[3]
"sev" \mu \sigma -
"weibull" \mu \sigma (\gamma)
"normal" \mu \sigma -
"lognormal" \mu \sigma (\gamma)
"logistic" \mu \sigma -
"loglogistic" \mu \sigma (\gamma)
"exponential" \theta (\gamma) -

Examples

x <- rweibull(n = 100, shape = 1, scale = 20000)

# Example 1 - Two-parametric straight line:
pop_weibull <- plot_pop(
  p_obj = NULL,
  x = range(x),
  dist_params_tbl = c(log(20000), 1),
  distribution = "weibull"
)

# Example 2 - Three-parametric curved line:
x2 <- rweibull(n = 100, shape = 1, scale = 20000) + 5000

pop_weibull_2 <- plot_pop(
  p_obj = NULL,
  x = x2,
  dist_params_tbl = c(log(20000 - 5000), 1, 5000),
  distribution = "weibull"
)

# Example 3 - Multiple lines:
pop_weibull_3 <- plot_pop(
  p_obj = NULL,
  x = x,
  dist_params_tbl = data.frame(
    p_1 = c(log(20000), log(20000), log(20000)),
    p_2 = c(1, 1.5, 2)
    ),
  distribution = "weibull",
  plot_method = "ggplot2"
)

# Example 4 - Compare two- and three-parametric distributions:
pop_weibull_4 <- plot_pop(
  p_obj = NULL,
  x = x,
  dist_params_tbl = data.frame(
    param_1 = c(log(20000), log(20000)),
    param_2 = c(1, 1),
    param_3 = c(NA, 2)
  ),
  distribution = "weibull"
)


weibulltools documentation built on April 5, 2023, 5:10 p.m.