The skellam package provides functions for working
with the Skellam distribution – the distribution of the difference
between two independent Poisson random variables. It includes routines
for: - Calculating the probability mass function (dskellam
)
- Computing the cumulative distribution function (pskellam
)
- Determining quantiles (qskellam
) - Generating random
variates (rskellam
) - Performing maximum likelihood
estimation (skellam.mle
) - Conducting regression analysis
under the Skellam model (skellam.reg
)
This package is designed to offer enhanced numerical accuracy and robust handling of a wide range of parameter values.
Install the latest stable version from CRAN:
install.packages("skellam")
Alternatively, install the development version from GitHub:
# install.packages("remotes") # Uncomment if needed
::install_github("monty-se/skellam") remotes
dskellam(x, lambda1, lambda2 = lambda1, log = FALSE)
Returns the (log) density of the Skellam distribution.
pskellam(q, lambda1, lambda2 = lambda1, lower.tail = TRUE, log.p = FALSE)
Computes the (log) cumulative distribution function.
qskellam(p, lambda1, lambda2 = lambda1, lower.tail = TRUE, log.p = FALSE)
Returns the quantile function for the Skellam distribution.
rskellam(n, lambda1, lambda2 = lambda1)
Generates random variates following the Skellam distribution.
skellam.mle(x)
Performs maximum likelihood estimation (MLE) for the Skellam distribution parameters based on observed differences.
skellam.reg(y, x)
Fits a regression model assuming a Skellam distribution, using an exponential link to ensure positivity of the rate parameters.
If \(X \sim \text{Poisson}(\lambda_1)\) and \(Y \sim \text{Poisson}(\lambda_2)\) are independent, then the difference
\[ Z = X - Y \]
follows a Skellam distribution:
\[ Z \sim \text{Skellam}(\lambda_1, \lambda_2) \]
This property is the theoretical foundation behind the functions provided in the skellam package. For more details, see the Wikipedia page on the Skellam distribution
<- 5000
N <- 1.5
lambda1 <- 0.5 lambda2
<- rpois(N, lambda1)
X <- rpois(N, lambda2)
Y <- X - Y XminusY
<- rskellam(N, lambda1, lambda2) Z
<- seq(min(XminusY), max(XminusY))
xseq plot(table(XminusY), main = "Empirical vs. Theoretical Density",
xlab = "X - Y", ylab = "Frequency", pch = 1)
points(xseq, N * dskellam(xseq, lambda1, lambda2), col = "blue", pch = 4)
legend("topright", legend = c("Empirical", "Theoretical"), pch = c(1, 4),
col = c("black", "blue"))
<- skellam.mle(XminusY)
mle_result print(mle_result)
set.seed(123)
<- rnorm(N)
x_cov <- rpois(N, exp(1 + x_cov))
y1 <- rpois(N, exp(-1 + x_cov))
y2 <- y2 - y1 y_diff
<- skellam.reg(y_diff, x_cov)
reg_result print(reg_result)
Skellam, J. G. (1946). The frequency distribution of the difference between two Poisson variates belonging to different populations. Journal of the Royal Statistical Society, Series A, 109(3), 296-296.
Johnson, N. L. (1959). On an extension of the connection between Poisson and χ² distributions. Biometrika, 46, 352–362.
Wikipedia: Skellam distribution
The skellam package is licensed under the GPL (>= 2).
Montasser Ghachem (mg@pinstimation.com) Oguz Ersan (oe@pinstimation.com)