SKELLAM
Overview
The SKELLAM
function computes values for the Skellam distribution, which describes the difference between two independent Poisson random variables. It can return the probability mass function (PMF), cumulative distribution function (CDF), survival function (SF), inverse CDF (ICDF/quantile), inverse survival function (ISF), mean, variance, standard deviation, or median for a given value. This is useful in statistics for modeling score differences, such as in sports or queueing theory.
For more details, see the scipy.stats.skellam documentation .
This example function is provided as-is without any representation of accuracy.
Usage
To use the function in Excel:
=SKELLAM(k, mu_one, mu_two, [mode], [loc])
k
(float or 2D list, required): Value(s) at which to evaluate the distribution. For PMF, CDF, SF, ICDF, and ISF, this is the value or probability. For statistics modes, this is ignored and can be set to 0.mu_one
(float, required): Mean of the first Poisson variable (must be > 0).mu_two
(float, required): Mean of the second Poisson variable (must be > 0).mode
(str, optional, default=“pmf”): Output type. One of"pmf"
,"cdf"
,"sf"
,"icdf"
,"isf"
,"mean"
,"var"
,"std"
, or"median"
.loc
(float, optional, default=0): Location parameter (shifts the distribution).
The function returns a scalar or 2D list of floats (for array input), or an error message (string) if the input is invalid. The output depends on the selected mode:
pmf
: Probability mass function at k.cdf
: Cumulative distribution function at k.sf
: Survival function (1 - CDF) at k.icdf
: Inverse CDF (quantile) for probability k.isf
: Inverse survival function for probability k.mean
: Mean of the distribution.var
: Variance of the distribution.std
: Standard deviation of the distribution.median
: Median of the distribution.
Examples
Python Code
from scipy.stats import skellam as scipy_skellam
def skellam(k, mu_one, mu_two, mode="pmf", loc=0):
"""
Compute Skellam distribution values: PMF, CDF, SF, ICDF, ISF, mean, variance, std, or median.
Args:
k: Value(s) at which to evaluate (float or 2D list).
mu_one: Mean of first Poisson variable (float, > 0).
mu_two: Mean of second Poisson variable (float, > 0).
mode: Output type: 'pmf', 'cdf', 'sf', 'icdf', 'isf', 'mean', 'var', 'std', or 'median'.
loc: Location parameter (float, default 0).
Returns:
Scalar or 2D list of floats, or error message (str) if invalid.
This example function is provided as-is without any representation of accuracy.
"""
# Validate mu_one, mu_two
try:
mu_one_val = float(mu_one)
mu_two_val = float(mu_two)
if not (mu_one_val > 0 and mu_two_val > 0):
return "Invalid input: mu_one and mu_two must be > 0."
except Exception:
return "Invalid input: mu_one and mu_two must be numbers."
# Validate loc
try:
loc_val = float(loc)
except Exception:
return "Invalid input: loc must be a number."
# Validate mode
valid_modes = ["pmf", "cdf", "sf", "icdf", "isf", "mean", "var", "std", "median"]
if not isinstance(mode, str) or mode not in valid_modes:
return f"Invalid input: mode must be one of {valid_modes}."
# Helper to process k (scalar or 2D list)
def process_k(val):
try:
return float(val)
except Exception:
return None
# Handle statistics
if mode == "mean":
return float(scipy_skellam.mean(mu_one_val, mu_two_val, loc=loc_val))
if mode == "var":
return float(scipy_skellam.var(mu_one_val, mu_two_val, loc=loc_val))
if mode == "std":
return float(scipy_skellam.std(mu_one_val, mu_two_val, loc=loc_val))
if mode == "median":
return float(scipy_skellam.median(mu_one_val, mu_two_val, loc=loc_val))
# PMF, CDF, SF, ICDF, ISF
def compute(val):
kval = process_k(val)
if kval is None:
return "Invalid input: k must be a number."
if mode == "pmf":
return float(scipy_skellam.pmf(kval, mu_one_val, mu_two_val, loc=loc_val))
elif mode == "cdf":
return float(scipy_skellam.cdf(kval, mu_one_val, mu_two_val, loc=loc_val))
elif mode == "sf":
return float(scipy_skellam.sf(kval, mu_one_val, mu_two_val, loc=loc_val))
elif mode == "icdf":
return float(scipy_skellam.ppf(kval, mu_one_val, mu_two_val, loc=loc_val))
elif mode == "isf":
return float(scipy_skellam.isf(kval, mu_one_val, mu_two_val, loc=loc_val))
# 2D list or scalar
if isinstance(k, list):
if not all(isinstance(row, list) for row in k):
return "Invalid input: k must be a scalar or 2D list."
result = []
for row in k:
result_row = []
for val in row:
out = compute(val)
if isinstance(out, str):
return out
result_row.append(out)
result.append(result_row)
return result
else:
return compute(k)