ppwe: Piecewise exponential cumulative distribution function

View source: R/helper_functions.R

ppweR Documentation

Piecewise exponential cumulative distribution function

Description

ppwe computes the cumulative distribution function (CDF) or survival rate for a piecewise exponential distribution.

Usage

ppwe(
  x = 0:20,
  failRates = tibble::tibble(duration = c(3, 100), rate = log(2)/c(9, 18)),
  lower.tail = FALSE
)

Arguments

x

times at which distribution is to be computed.

failRates

Piecewise constant failure rates in rate, duration for each piecewise constant failure rate period.

lower.tail

Indicator of whether lower (TRUE) or upper tail (FALSE; default) of CDF is to be computed.

Details

Suppose λ_i is the failure rate in the interval (t_{i-1},t_i], i=1,2,…,M where 0=t_0<t_i…,t_M=∞. The cumulative hazard function at an arbitrary time t>0 is then:

Λ(t)=∑_{i=1}^M δ(t≤ t_i)(\min(t,t_i)-t_{i-1})λ_i.

The survival at time t is then

S(t)=\exp(-Λ(t)).

Value

A vector with cumulative distribution function or survival values

Specification

The contents of this section are shown in PDF user manual only.

Examples

# Example: default
ppwe(seq(0:10))
# Example: plot a survival function with 2 different sets of time values
# to demonstrate plot precision corresponding to input parameters.
fr <- tibble::tibble(duration=c(3,3,1),rate=c(.2,.1,.005))
Time <- seq(0,10,10/pi)
Survival <-  ppwe(Time,fr)
plot(Time,Survival,type="l",ylim=c(0,1))
Time <- seq(0,10,.25)
Survival <-  ppwe(Time,fr)
lines(Time,Survival,col=2)

keaven/gsDesign2 documentation built on Oct. 13, 2022, 8:42 p.m.