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)
Run the code above in your browser using DataLab