discretize {actuar} | R Documentation |
Discretization of a Continuous Distribution
Description
Compute a discrete probability mass function from a continuous cumulative distribution function (cdf) with various methods.
discretise
is an alias for discretize
.
Usage
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)
Arguments
cdf |
an expression written as a function of |
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 |
by |
an alias for |
xlim |
numeric of length 2; if specified, it serves as default
for |
Details
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 denote the cdf,
the
limited expected value at
,
the step,
the probability mass at
in the discretized distribution and
set
from
and
to
.
Method "upper"
is the forward difference of the cdf :
for .
Method "lower"
is the backward difference of the cdf :
for and
.
Method "rounding"
has the true cdf pass through the
midpoints of the intervals :
for and
. 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:
Value
A numeric vector of probabilities suitable for use in
aggregateDist
.
Author(s)
Vincent Goulet vincent.goulet@act.ulaval.ca
References
Klugman, S. A., Panjer, H. H. and Willmot, G. E. (2012), Loss Models, From Data to Decisions, Fourth Edition, Wiley.
See Also
Examples
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)