Skip to Content

DLAPLACE

Overview

The DLAPLACE function computes values related to the Discrete Laplace distribution, a discrete probability distribution with a shape parameter a > 0. 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 function for the Discrete Laplace distribution. The Python function in Excel provided here supports all major distribution features, including PMF, CDF, SF, ICDF, ISF, and distribution statistics (mean, median, variance, standard deviation).

For more details, see the scipy.stats.dlaplace documentation.

Usage

To use the function in Excel:

=DLAPLACE(k, a, [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 integer value. For statistics modes, this is ignored and can be set to 0.
  • a (float, required): Shape parameter (a > 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=2, a=1.0

Inputs:

kamodeloc
21.0pmf0

Excel formula:

=DLAPLACE(2, 1.0, "pmf", 0)

Expected output:

Result
0.0625

Example 2: CDF at k=2, a=1.0

Inputs:

kamodeloc
21.0cdf0

Excel formula:

=DLAPLACE(2, 1.0, "cdf", 0)

Expected output:

Result
0.9636

Example 3: Survival Function at k=2, a=1.0

Inputs:

kamodeloc
21.0sf0

Excel formula:

=DLAPLACE(2, 1.0, "sf", 0)

Expected output:

Result
0.0364

Example 4: Inverse CDF (ICDF) for probability k=0.5, a=1.0

Inputs:

kamodeloc
0.51.0icdf0

Excel formula:

=DLAPLACE(0.5, 1.0, "icdf", 0)

Expected output:

Result
0

Example 5: Mean, Variance, Std, Median

Inputs:

kamodeloc
01.0mean0
01.0var0
01.0std0
01.0median0

Excel formulas:

=DLAPLACE(0, 1.0, "mean", 0) =DLAPLACE(0, 1.0, "var", 0) =DLAPLACE(0, 1.0, "std", 0) =DLAPLACE(0, 1.0, "median", 0)

Expected outputs:

Result
0
1.8413
1.357
0

Python Code

from scipy.stats import dlaplace as scipy_dlaplace def dlaplace(k, a, mode="pmf", loc=0): """ Compute Discrete Laplace distribution values: PMF, CDF, SF, ICDF, ISF, mean, variance, std, or median. Args: k: Value(s) at which to evaluate (float or 2D list). a: Shape parameter (float, a > 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 a try: a_val = float(a) if not (a_val > 0): return "Invalid input: a must be > 0." except Exception: return "Invalid input: a must be a number." # 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_dlaplace.mean(a_val, loc=loc_val) if mode == "var": return scipy_dlaplace.var(a_val, loc=loc_val) if mode == "std": return scipy_dlaplace.std(a_val, loc=loc_val) if mode == "median": return scipy_dlaplace.median(a_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_dlaplace.pmf(kval, a_val, loc=loc_val)) elif mode == "cdf": return float(scipy_dlaplace.cdf(kval, a_val, loc=loc_val)) elif mode == "sf": return float(scipy_dlaplace.sf(kval, a_val, loc=loc_val)) elif mode == "icdf": return float(scipy_dlaplace.ppf(kval, a_val, loc=loc_val)) elif mode == "isf": return float(scipy_dlaplace.isf(kval, a_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)

Live Demo

Example Workbook

Link to Workbook

Last updated on