Skip to Content

MULTIVARIATE_T

Overview

The MULTIVARIATE_T function computes the probability density function (PDF), cumulative distribution function (CDF), or draws random samples from the multivariate t-distribution. This distribution generalizes the Student’s t-distribution to multiple dimensions and is commonly used in statistics for modeling data with heavier tails than the multivariate normal distribution. The PDF for the multivariate t-distribution is:

f(x)=Γ(ν+d2)Γ(ν2)νd/2πd/2Σ1/2[1+1ν(xμ)TΣ1(xμ)]ν+d2f(x) = \frac{\Gamma\left(\frac{\nu + d}{2}\right)}{\Gamma\left(\frac{\nu}{2}\right) \nu^{d/2} \pi^{d/2} |\Sigma|^{1/2}} \left[1 + \frac{1}{\nu}(x - \mu)^T \Sigma^{-1} (x - \mu)\right]^{-\frac{\nu + d}{2}}

where xx is a dd-dimensional vector, μ\mu is the location vector, Σ\Sigma is the shape (covariance) matrix, and ν\nu is the degrees of freedom. For more details, see the scipy.stats.multivariate_t documentation.

This wrapper exposes only the most commonly used parameters: location, shape, degrees of freedom, and method. Advanced options such as singularity checks, random seed, and integration controls are omitted for simplicity. This example function is provided as-is without any representation of accuracy.

Usage

To use the function in Excel:

=MULTIVARIATE_T(x, [loc], [shape], [df], [method], [size])
  • x (2D list, required): Table of points at which to evaluate the function or fit the distribution. Each row is a point, each column is a dimension.
  • loc (2D column vector, optional, default=zero vector): Location of the distribution. Must have the same number of rows as columns in x.
  • shape (2D list, optional, default=identity matrix): Positive semidefinite shape (covariance) matrix. Must be square with size equal to the number of columns in x.
  • df (float, optional, default=1): Degrees of freedom. Must be greater than zero.
  • method (string, optional, default=“pdf”): Which method to compute: pdf, cdf, or rvs.
  • size (integer, optional): Number of samples to draw if method is rvs.

The function returns a 2D list of results for each input point, or an error message (string) if the input is invalid. For rvs, the output is a 2D list of random samples. For pdf and cdf, the output is a column vector of results for each input point.

Examples

Example 1: PDF at Origin

Inputs:

xlocshapedfmethod
0.00.00.00.01.00.02pdf
0.01.0

Excel formula:

=MULTIVARIATE_T({0,0}, {0;0}, {1,0;0,1}, 2, "pdf")

Expected output:

Result
0.159

Example 2: CDF at Origin

Inputs:

xlocshapedfmethod
0.00.00.00.01.00.02cdf
0.01.0

Excel formula:

=MULTIVARIATE_T({0,0}, {0;0}, {1,0;0,1}, 2, "cdf")

Expected output:

Result
0.250

Example 3: Random Samples

Inputs:

xlocshapedfmethodsize
0.00.00.00.01.00.02rvs2
0.01.0

Excel formula:

=MULTIVARIATE_T({0,0}, {0;0}, {1,0;0,1}, 2, "rvs", 2)

Expected output:

Sample 1 (dim 1)Sample 1 (dim 2)

(Two rows, each with two columns; values will vary.)

Example 4: PDF with Default Arguments

Inputs:

xmethod
1.01.0pdf

Excel formula:

=MULTIVARIATE_T({1,1}, "pdf")

Expected output:

Result
0.031

Python Code

from scipy.stats import multivariate_t as scipy_multivariate_t from typing import List, Optional, Union def multivariate_t( x: List[List[float]], loc: Optional[List[List[float]]] = None, shape: Optional[List[List[float]]] = None, df: Optional[float] = 1, method: str = 'pdf', size: Optional[int] = None ) -> Union[List[List[Optional[float]]], str]: """ Computes the PDF, CDF, or draws random samples from a multivariate t-distribution. Args: x: 2D list of float values. Points at which to evaluate the function or fit the distribution. loc: 2D list of float values (column vector). Location of the distribution. Default is zero vector. shape: 2D list of float values. Positive semidefinite shape matrix of the distribution. Default is identity matrix. df: Degrees of freedom of the distribution. Must be greater than zero. Default is 1. method: Which method to compute (str): 'pdf', 'cdf', 'rvs'. Default is 'pdf'. size: Number of samples to draw if method is 'rvs'. Optional. Returns: 2D list of results for each input point, or an error message (str) if input is invalid. This example function is provided as-is without any representation of accuracy. """ # Validate x if not isinstance(x, list) or not all(isinstance(row, list) and all(isinstance(val, (int, float)) for val in row) for row in x): return "Invalid input: x must be a 2D list of floats." if len(x) == 0 or len(x[0]) == 0: return "Invalid input: x must be a non-empty 2D list." dim = len(x[0]) # Validate loc if loc is not None: if not (isinstance(loc, list) and all(isinstance(row, list) and len(row) == 1 and isinstance(row[0], (int, float)) for row in loc)): return "Invalid input: loc must be a 2D column vector (list of lists with one float each)." if len(loc) != dim: return "Invalid input: loc must have the same number of rows as columns in x." loc_vec = [row[0] for row in loc] else: loc_vec = [0.0] * dim # Validate shape if shape is not None: if not (isinstance(shape, list) and all(isinstance(row, list) and len(row) == dim and all(isinstance(val, (int, float)) for val in row) for row in shape)): return "Invalid input: shape must be a 2D list of floats with shape (dim, dim)." if len(shape) != dim: return "Invalid input: shape must have the same number of rows as columns in x." shape_mat = shape else: shape_mat = [[float(i == j) for j in range(dim)] for i in range(dim)] # Validate df try: df_val = float(df) if df is not None else 1.0 except Exception: return "Invalid input: df must be a float." if df_val <= 0: return "Invalid input: df must be greater than zero." # Validate method if method not in ('pdf', 'cdf', 'rvs'): return "Invalid input: method must be 'pdf', 'cdf', or 'rvs'." # Validate size if method == 'rvs': if size is None: return "Invalid input: size must be specified for 'rvs' method." try: size_val = int(size) except Exception: return "Invalid input: size must be an integer." if size_val <= 0: return "Invalid input: size must be a positive integer." # Create distribution try: dist = scipy_multivariate_t(loc=loc_vec, shape=shape_mat, df=df_val) except Exception as e: return f"scipy.stats.multivariate_t error: {e}" # Compute result try: if method == 'pdf': result = [[float(dist.pdf(row))] for row in x] elif method == 'cdf': result = [[float(dist.cdf(row))] for row in x] elif method == 'rvs': samples = dist.rvs(size=size_val) # If samples is 1D, wrap as 2D list if dim == 1: result = [[float(val)] for val in samples] else: result = [[float(val) for val in row] for row in samples] else: return "Invalid method." except Exception as e: return f"scipy.stats.multivariate_t {method} error: {e}" # Check for invalid output values import math for row in result: for val in row: if isinstance(val, float) and (math.isnan(val) or math.isinf(val)): return "Invalid output: result contains NaN or infinite values." return result

Example Workbook

Link to Workbook

Last updated on