MVSDIST_CI

This function wraps SciPy’s posterior distribution constructor for the mean, variance, and standard deviation inferred from sample data. It evaluates each frozen posterior distribution at its mean and extracts equal-tailed credible interval bounds.

Let \theta \in \{\mu, \sigma^2, \sigma\} denote one of the three parameters. The reported interval satisfies:

P(\theta_{L} \leq \theta \leq \theta_{U} \mid \text{data}) = \alpha

This is useful when the posterior distributions are needed directly before interval extraction.

Excel Usage

=MVSDIST_CI(data, alpha)
  • data (list[list], required): 2D array of sample observations (unitless).
  • alpha (float, optional, default: 0.9): Credible interval probability level (0 to 1).

Returns (list[list]): 2D table with posterior mean and lower/upper credible bounds for mean, variance, and standard deviation.

Example 1: Intervals from posterior distributions for typical sample

Inputs:

data alpha
5 7 8 0.9
9 10 12

Excel formula:

=MVSDIST_CI({5,7,8;9,10,12}, 0.9)

Expected output:

Metric Center Lower Upper
Mean 8.5 6.50181 10.4982
Variance 9.83333 2.66474 25.7535
Std Dev 2.88908 1.6324 5.07479
Example 2: Higher confidence interval extraction

Inputs:

data alpha
2 3 5 7 11 0.95

Excel formula:

=MVSDIST_CI({2,3,5,7,11}, 0.95)

Expected output:

Metric Center Lower Upper
Mean 5.6 1.15769 10.0423
Variance 25.6 4.59469 105.694
Std Dev 4.48399 2.14352 10.2807
Example 3: Lower confidence interval extraction

Inputs:

data alpha
1 2 2 3 4 0.75

Excel formula:

=MVSDIST_CI({1,2,2,3,4}, 0.75)

Expected output:

Metric Center Lower Upper
Mean 2.4 1.71449 3.08551
Variance 2.6 0.720816 4.26662
Std Dev 1.429 0.849009 2.06558
Example 4: Mixed-scale sample values

Inputs:

data alpha
0.5 1.2 0.85
2.8 3.6
4.4 5.1

Excel formula:

=MVSDIST_CI({0.5,1.2;2.8,3.6;4.4,5.1}, 0.85)

Expected output:

Metric Center Lower Upper
Mean 2.93333 1.68328 4.18339
Variance 5.41111 1.62198 11.6476
Std Dev 2.14315 1.27357 3.41285

Python Code

from scipy.stats import mvsdist as scipy_mvsdist

def mvsdist_ci(data, alpha=0.9):
    """
    Compute Bayesian credible intervals from posterior distributions of mean, variance, and standard deviation.

    See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.mvsdist.html

    This example function is provided as-is without any representation of accuracy.

    Args:
        data (list[list]): 2D array of sample observations (unitless).
        alpha (float, optional): Credible interval probability level (0 to 1). Default is 0.9.

    Returns:
        list[list]: 2D table with posterior mean and lower/upper credible bounds for mean, variance, and standard deviation.
    """
    try:
        def to2d(x):
            return [[x]] if not isinstance(x, list) else x

        data = to2d(data)

        if not isinstance(data, list) or not all(isinstance(row, list) for row in data):
            return "Error: Invalid input - data must be a 2D list"

        if not (0 < alpha < 1):
            return "Error: alpha must be between 0 and 1"

        flat = []
        for row in data:
            for value in row:
                try:
                    flat.append(float(value))
                except (TypeError, ValueError):
                    continue

        if len(flat) < 2:
            return "Error: data must contain at least two numeric values"

        mean_dist, var_dist, std_dist = scipy_mvsdist(flat)

        mean_interval = mean_dist.interval(alpha)
        var_interval = var_dist.interval(alpha)
        std_interval = std_dist.interval(alpha)

        return [
            ["Metric", "Center", "Lower", "Upper"],
            ["Mean", float(mean_dist.mean()), float(mean_interval[0]), float(mean_interval[1])],
            ["Variance", float(var_dist.mean()), float(var_interval[0]), float(var_interval[1])],
            ["Std Dev", float(std_dist.mean()), float(std_interval[0]), float(std_interval[1])]
        ]
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

2D array of sample observations (unitless).
Credible interval probability level (0 to 1).