MyNixOS website logo
Description

Densities and Sampling for the Skellam Distribution.

Functions for the Skellam distribution, including: density (pmf), cdf, quantiles and regression.

Skellam

License: GPL v3 CRAN R-CMD-check Downloads CRAN downloads

Overview

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.

Installation

Install the latest stable version from CRAN:

install.packages("skellam")

Alternatively, install the development version from GitHub:

# install.packages("remotes")  # Uncomment if needed
remotes::install_github("monty-se/skellam")

Usage

Distribution Functions

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.

Additional Functionalities

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.

Theoretical Background

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 ​

Examples

Random Variate Generation and Density Estimation

Set parameters

N <- 5000
lambda1 <- 1.5
lambda2 <- 0.5

Generate independent Poisson samples and compute their difference

X <- rpois(N, lambda1)
Y <- rpois(N, lambda2)
XminusY <- X - Y

Generate Skellam random variates

Z <- rskellam(N, lambda1, lambda2)

Plot empirical and theoretical densities

xseq <- seq(min(XminusY), max(XminusY))
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"))

Maximum Likelihood Estimation

Estimate Skellam parameters from the difference data

mle_result <- skellam.mle(XminusY)
print(mle_result)

Skellam Regression

Simulate covariate data and corresponding Poisson outcomes

set.seed(123)
x_cov <- rnorm(N)
y1 <- rpois(N, exp(1 + x_cov))
y2 <- rpois(N, exp(-1 + x_cov))
y_diff <- y2 - y1

Fit a Skellam regression model

reg_result <- skellam.reg(y_diff, x_cov)
print(reg_result)

References

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

License

The skellam package is licensed under the GPL (>= 2).

Maintainers

Montasser Ghachem ([email protected]) Oguz Ersan ([email protected])

Metadata

Version

0.2.4

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows