| discretize {actuar} | R Documentation | 
Compute a discrete probability mass function from a continuous cumulative distribution function (cdf) with various methods.
discretise is an alias for discretize.
discretize(cdf, from, to, step = 1,
           method = c("upper", "lower", "rounding", "unbiased"),
           lev, by = step, xlim = NULL)
discretise(cdf, from, to, step = 1,
           method = c("upper", "lower", "rounding", "unbiased"),
           lev, by = step, xlim = NULL)
cdf | 
an expression written as a function of x, or
alternatively the name of a function, giving the cdf to discretize. | 
from, to | 
the range over which the function will be discretized. | 
step | 
numeric; the discretization step (or span, or lag). | 
method | 
discretization method to use. | 
lev | 
an expression written as a function of x, or
alternatively the name of a function, to compute the limited
expected value of the distribution corresponding to
cdf. Used only with the "unbiased" method. | 
by | 
an alias for step. | 
xlim | 
numeric of length 2; if specified, it serves as default
for c(from, to). | 
Usage is similar to curve.
discretize returns the probability mass function (pmf) of the
random variable obtained by discretization of the cdf specified in
cdf.
Let F(x) denote the cdf, E[min(X, x)]] the
limited expected value at x, h the step, p[x]
the probability mass at x in the discretized distribution and
set a = from and b = to.
Method "upper" is the forward difference of the cdf F:
p[x] = F(x + h) - F(x)
for x = a, a + h, ..., b - step.
Method "lower" is the backward difference of the cdf F:
p[x] = F(x) - F(x - h)
for x = a + h, ..., b and p[a] = F(a).
Method "rounding" has the true cdf pass through the
midpoints of the intervals [x - h/2, x + h/2):
p[x] = F(x + h/2) - F(x - h/2)
for x = a + h, ..., b - step and p[a] =
F(a + h/2). The function assumes the cdf is continuous. Any
adjusment necessary for discrete distributions can be done via
cdf.
Method "unbiased" matches the first moment of the discretized
and the true distributions. The probabilities are as follows:
p[a] = (E[min(X, a)] - E[min(X, a + h)])/h + 1 - F(a)
p[x] = (2 E[min(X, x)] - E[min(X, x - h)] - E[min(X, x + h)])/h, a < x < b
p[b] = (E[min(X, b)] - E[min(X, b - h)])/h - 1 + F(b).
A numeric vector of probabilities suitable for use in
aggregateDist.
Vincent Goulet vincent.goulet@act.ulaval.ca
Klugman, S. A., Panjer, H. H. and Willmot, G. E. (2004), Loss Models, From Data to Decisions, Second Edition, Wiley.
x <- seq(0, 5, 0.5)
op <- par(mfrow = c(1, 1), col = "black")
## Upper and lower discretization
fu <- discretize(pgamma(x, 1), method = "upper",
                 from = 0, to = 5, step = 0.5)
fl <- discretize(pgamma(x, 1), method = "lower",
                 from = 0, to = 5, step = 0.5)
curve(pgamma(x, 1), xlim = c(0, 5))
par(col = "blue")
plot(stepfun(head(x, -1), diffinv(fu)), pch = 19, add = TRUE)
par(col = "green")
plot(stepfun(x, diffinv(fl)), pch = 19, add = TRUE)
par(col = "black")
## Rounding (or midpoint) discretization
fr <- discretize(pgamma(x, 1), method = "rounding",
                 from = 0, to = 5, step = 0.5)
curve(pgamma(x, 1), xlim = c(0, 5))
par(col = "blue")
plot(stepfun(head(x, -1), diffinv(fr)), pch = 19, add = TRUE)
par(col = "black")
## First moment matching
fb <- discretize(pgamma(x, 1), method = "unbiased",
                 lev = levgamma(x, 1), from = 0, to = 5, step = 0.5)
curve(pgamma(x, 1), xlim = c(0, 5))
par(col = "blue")
plot(stepfun(x, diffinv(fb)), pch = 19, add = TRUE)
par(op)