Skip to contents

This function creates a cumulative distribution function (CDF) based on a given probability density function (PDF). The CDF is defined as the integral of the PDF from 0 to a given value of t.

Usage

cdf_function(pdf)

Arguments

pdf

The probability density function.

Value

The cumulative distribution function in terms of time t and the parameters that index the probability density function passed as an argument to pdf. The function, returned by cdf_function(), is vectorized in relation to t.

When using the cdf_function(), utilizing the concept of closure, a function is returned in terms of t and the parameters that index the PDF passed as an argument to pdf. When using the function returned by cdf_function(), the cumulative probabilities in relation to time t, i.e., \(P(T \leq t)\) are returned. In addition, the function carries the time attribute which is the time t

used to calculate the cumulative probability and can be used to plot the cumulative distribution function. The class of the object returned by using the function that is returned by cdf_function() is cdf_function.

Details

cdf_function() returns a cumulative distribution function (CDF) obtained numerically from a probability density function (PDF). The idea of this function is that the user does not need to integrate a probability density function and can easily obtain the cumulative distribution function for their experiments, simply by passing the probability density function as an argument, thus significantly reducing the amount of code.

From a computational performance standpoint, in some situations, it might make sense to implement the analytical form of the CDF. However, the numerical approach is more general and can be applied to any probability density function without much effort.

Examples

# Create a CDF based on a PDF
cdf <- cdf_function(pdf = dweibull)

# Evaluate the CDF at a specific value of t
cdf(t = 1, shape = 2, scale = 1)
#> [1] 0.6321206
#> attr(,"time")
#> [1] 1
#> attr(,"class")
#> [1] "cdf_function"

# Evaluate the CDF for a vector of values
cdf(t = 1L:30L, shape = 2, scale = 1)
#>  [1] 0.6321206 0.9816844 0.9998766 0.9999999 1.0000000 1.0000000 1.0000000
#>  [8] 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000
#> [15] 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000
#> [22] 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000
#> [29] 1.0000000 1.0000000
#> attr(,"time")
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#> [26] 26 27 28 29 30
#> attr(,"class")
#> [1] "cdf_function"