Learn R Programming

fitPlotR (version 0.1.0)

plot_sf: Plot for the Survival Function of a Probability Distribution

Description

#' Plots the SF of a probability distribution. Supports multiple sets of parameters with shaded areas under the curves.

Usage

plot_sf(
  sf,
  param_list,
  xlim = c(0, 10),
  ylim = c(0, 1),
  n = 500,
  main = "SF Plot",
  xlab = "x",
  ylab = "SF",
  colors = NULL,
  shade_colors = NULL,
  lwd = 3,
  lty = 2,
  grid = TRUE,
  grid_lty = 3,
  grid_col = "gray80",
  grid_lwd = 1
)

Value

A SF plot is displayed. The function invisibly returns NULL.

Arguments

sf

Function that computes the SF. Must accept x as the first argument.

param_list

A list of parameter lists. Each element is a named list of parameters for sf.

xlim

Numeric vector of length 2, specifying the x-axis limits. Default is c(0, 10).

ylim

Numeric vector of length 2, specifying the y-axis limits. Default is c(0, 1).

n

Number of points to evaluate on the x-axis. Default is 500.

main

Title of the plot. Default is "SF Plot".

xlab

Label for the x-axis. Default is "x".

ylab

Label for the y-axis. Default is "SF".

colors

Vector of colors for the lines. Default is rainbow.

shade_colors

Vector of colors for shading under curves. Default is semi-transparent version of colors.

lwd

Line width. Default is 3.

lty

Line type. Default is 2 (dashed).

grid

Logical, whether to draw a grid. Default is TRUE.

grid_lty

Line type for grid. Default is 3.

grid_col

Grid color. Default is "gray80".

grid_lwd

Grid line width. Default is 1.

Examples

Run this code
# Example 1: Generalized Exponential Distribution
ge_sf <- function(x, alpha, lambda) {
  1 - (1 - exp(-lambda * x))^alpha
}
param_values <- list(
  list(alpha = 1, lambda = 1),
  list(alpha = 2, lambda = 1),
  list(alpha = 3, lambda = 0.5),
  list(alpha = 4, lambda = 1.5),
  list(alpha = 5, lambda = 2.5)
)
plot_sf(sf = ge_sf, param_list = param_values, main = "SF GE Distribution")

# Example 2: Exponentiated Weibull Distribution
sf_expweibull <- function(x, a, b, c) {
  1 - (1 - exp(-(b*x)^c))^a
}
param_values <- list(
  list(a = 0.3, b = 1.2, c = 1.0),
  list(a = 1.3, b = 0.4, c = 2.3),
  list(a = 1.5, b = 0.9, c = 3.0),
  list(a = 2.0, b = 1.8, c = 2.8),
  list(a = 3.7, b = 2.0, c = 1.5)
)
colors <- c("green", "purple", "yellow", "orange", "darkblue")
plot_sf(sf = sf_expweibull, param_list = param_values,
        main = "SF of EW Distribution", colors = colors, xlim = c(0, 5))

Run the code above in your browser using DataLab