BOLTZMANN
Overview
The BOLTZMANN
function computes values related to the Boltzmann (Truncated Discrete Exponential) distribution, a discrete probability distribution with support on {0, ..., N-1}
. This function can return the probability mass function (PMF), cumulative distribution function (CDF), survival function (SF), inverse CDF (quantile/ICDF), inverse SF (ISF), mean, variance, standard deviation, or median for a given value.
Excel does not provide a native Boltzmann distribution function. The Python function in Excel provided here supports PMF, CDF, SF, ICDF, ISF, and distribution statistics (mean, median, variance, standard deviation), which are not available natively in Excel.
For more details, see the scipy.stats.boltzmann documentation .
Usage
To use the function in Excel:
=BOLTZMANN(k, lambda, N, [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 value0 <= k < N
. For statistics modes, this is ignored and can be set to 0.lambda
(float, required): Rate parameterlambda > 0
.N
(int, required): Number of possible valuesN > 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
Example 1: PMF at k=3, lambda=1.4, N=19
Inputs:
k | lambda | N | mode | loc |
---|---|---|---|---|
3 | 1.4 | 19 | pmf | 0 |
Excel formula:
=BOLTZMANN(3, 1.4, 19, "pmf", 0)
Expected output:
Result |
---|
0.0113 |
Example 2: CDF at k=3, lambda=1.4, N=19
Inputs:
k | lambda | N | mode | loc |
---|---|---|---|---|
3 | 1.4 | 19 | cdf | 0 |
Excel formula:
=BOLTZMANN(3, 1.4, 19, "cdf", 0)
Expected output:
Result |
---|
0.9963 |
Example 3: Survival Function at k=3, lambda=1.4, N=19
Inputs:
k | lambda | N | mode | loc |
---|---|---|---|---|
3 | 1.4 | 19 | sf | 0 |
Excel formula:
=BOLTZMANN(3, 1.4, 19, "sf", 0)
Expected output:
Result |
---|
0.0037 |
Example 4: Inverse CDF (ICDF) for probability k=0.5, lambda=1.4, N=19
Inputs:
k | lambda | N | mode | loc |
---|---|---|---|---|
0.5 | 1.4 | 19 | icdf | 0 |
Excel formula:
=BOLTZMANN(0.5, 1.4, 19, "icdf", 0)
Expected output:
Result |
---|
0 |
Example 5: Mean, Variance, Std, Median
Inputs:
k | lambda | N | mode | loc |
---|---|---|---|---|
0 | 1.4 | 19 | mean | 0 |
0 | 1.4 | 19 | var | 0 |
0 | 1.4 | 19 | std | 0 |
0 | 1.4 | 19 | median | 0 |
Excel formulas:
=BOLTZMANN(0, 1.4, 19, "mean", 0)
=BOLTZMANN(0, 1.4, 19, "var", 0)
=BOLTZMANN(0, 1.4, 19, "std", 0)
=BOLTZMANN(0, 1.4, 19, "median", 0)
Expected outputs:
Result |
---|
0.3273 |
0.4344 |
0.6591 |
0 |
Python Code
from scipy.stats import boltzmann as scipy_boltzmann
def boltzmann(k, lambda_, N, mode="pmf", loc=0):
"""
Compute Boltzmann distribution values: PMF, CDF, SF, ICDF, ISF, mean, variance, std, or median.
Args:
k: Value(s) at which to evaluate (float or 2D list).
lambda_: Rate parameter (float, > 0).
N: Number of possible values (int, > 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.
"""
# Validate lambda_
try:
lam_val = float(lambda_)
if not (lam_val > 0):
return "Invalid input: lambda must be > 0."
except Exception:
return "Invalid input: lambda must be a number."
# Validate N
try:
N_val = int(N)
if not (N_val > 0):
return "Invalid input: N must be > 0."
except Exception:
return "Invalid input: N must be an integer."
# 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 scipy_boltzmann.mean(lam_val, N_val, loc=loc_val)
if mode == "var":
return scipy_boltzmann.var(lam_val, N_val, loc=loc_val)
if mode == "std":
return scipy_boltzmann.std(lam_val, N_val, loc=loc_val)
if mode == "median":
return scipy_boltzmann.median(lam_val, N_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_boltzmann.pmf(kval, lam_val, N_val, loc=loc_val))
elif mode == "cdf":
return float(scipy_boltzmann.cdf(kval, lam_val, N_val, loc=loc_val))
elif mode == "sf":
return float(scipy_boltzmann.sf(kval, lam_val, N_val, loc=loc_val))
elif mode == "icdf":
return float(scipy_boltzmann.ppf(kval, lam_val, N_val, loc=loc_val))
elif mode == "isf":
return float(scipy_boltzmann.isf(kval, lam_val, N_val, loc=loc_val))
# 2D list or scalar
if isinstance(k, list):
# 2D 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)