cdfDiff: Cumulative probability distribution segments

cdfDiffR Documentation

Cumulative probability distribution segments

Description

Calculates the difference between two values of a cumulative probability distribution. Will result in negative probabilities when cdf(b) < cdf(a), e.g. when the ends of the cdf probability segment are reversed.

Usage

cdfDiff(a, b, dist, ...)

Arguments

a

Vector of the left sides of segments. Must be the same length as b=, or a single value. If a single value, that value will be used as the left side of all segments

b

Vector of the right sides of segments. Must be the same length as a=, or a single value. If a single value, that value will be used as the right side of all segments.

dist

Name of distribution to use, one of: "normal". Will be partially matched, case insensitively, but must match uniquely.

...

Distribution parameter, e.g. mean= and sd= for the normal distribution.

Value

The probability of each of the specified line segments. Note that for segments specified backwards like b[i] < a[i], the corresponding probabilities will be negative.

Examples

# P( x > 0 ), standard normal distribution
cdfDiff( 0, Inf, "norm" )
#> [1] 0.5

# P( x > 0 ), standard normal distribution (backwards)
cdfDiff( Inf, 0, "norm" )
#> [1] -0.5

# P( x < 2.1 ), normal with mean= 2.1 ( and sd= 1)
cdfDiff( -Inf, 2.1, "norm", mean= 2.1 )
#> [1] 0.5

# P( x = -Inf, x < 0, x < Inf ), standard normal distribution
cdfDiff( -Inf, c(-Inf, 0, Inf), "norm" )
#> [1] 0.0 0.5 1.0

# Mix of forwards and backwards
cdfDiff( c(-Inf, -2.1, Inf), c(-2.1, -Inf, -2.1), "norm", mean=-2.1 )
#> [1]  0.5 -0.5 -0.5

# P( x < 2 or x > 2 ) standard normal
sum(cdfDiff( c(-Inf, 2), c(-2, Inf), "norm"))
#> 0.04550026

jefferys/JefferysRUtils documentation built on Jan. 12, 2024, 9:18 p.m.