Skip to Content

T_DIST

Overview

The T_DIST function provides a unified interface to the main methods of the Student’s t distribution, including PDF, CDF, inverse CDF, survival function, and distribution statistics.

Excel provides several t-distribution functions, including T.DIST, T.DIST.2T, T.DIST.RT for the PDF and CDF, and T.INV, T.INV.2T for the inverse CDF (quantile). The Python function in Excel here also supports the survival function, inverse survival, and distribution statistics (mean, median, variance, standard deviation), as well as location and scale parameters, which are not available in native Excel functions.

The Student’s t distribution is widely used in statistics, especially for hypothesis testing and confidence intervals when the sample size is small and the population standard deviation is unknown. The PDF is given by:

f(x,df,loc,scale)=Γ(df+12)dfπ  Γ(df2)(1+(xloc)2df  scale2)df+12f(x, \mathrm{df}, \mathrm{loc}, \mathrm{scale}) = \frac{\Gamma\left(\frac{\mathrm{df}+1}{2}\right)}{\sqrt{\mathrm{df}\pi}\;\Gamma\left(\frac{\mathrm{df}}{2}\right)} \left(1 + \frac{(x-\mathrm{loc})^2}{\mathrm{df}\;\mathrm{scale}^2}\right)^{-\frac{\mathrm{df}+1}{2}}

for df>0\mathrm{df} > 0, scale>0\mathrm{scale} > 0.

The t distribution is symmetric and bell-shaped, like the normal distribution, but has heavier tails. The degrees of freedom parameter (df) controls the shape; as df increases, the t distribution approaches the normal distribution.

For more details, see the official SciPy documentation.

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

Usage

To use the function in Excel:

=T_DIST(value, df, [loc], [scale], [method])
  • value (float, required for pdf, cdf, icdf, sf, isf):
    • For pdf, cdf, sf: the value xx at which to evaluate the function
    • For icdf, isf: the probability qq (must be between 0 and 1)
    • For mean, median, var, std: skip parameter
  • df (float, required): Degrees of freedom. Must be >0> 0.
  • loc (float, optional, default=0.0): Location parameter.
  • scale (float, optional, default=1.0): Scale parameter. Must be >0> 0.
  • method (string, optional, default=“pdf”): One of pdf, cdf, icdf, sf, isf, mean, median, var, std.
MethodDescriptionOutput
pdfProbability Density Function: f(x)f(x), the likelihood of a specific value xx.Density at xx
cdfCumulative Distribution Function: P(Xx)P(X \leq x), the probability that XX is less than or equal to xx.Probability
icdfInverse CDF (Quantile Function): Returns xx such that P(Xx)=qP(X \leq x) = q for a given probability qq.Value xx
sfSurvival Function: P(X>x)P(X > x), the probability that XX is greater than xx.Probability
isfInverse Survival Function: Returns xx such that P(X>x)=qP(X > x) = q for a given probability qq.Value xx
meanMean (expected value) of the distribution.Mean value
medianMedian of the distribution.Median value
varVariance of the distribution.Variance
stdStandard deviation of the distribution.Standard deviation

The function returns a single value (float): the result of the requested method, or an error message (string) if the input is invalid.

Examples

Example 1: PDF at x=0

Inputs:

valuedflocscalemethod
0501pdf

Excel formula:

=T_DIST(0, 5, 0, 1, "pdf")

Expected output:

Result
0.3796067

Example 2: CDF at x=0

Inputs:

valuedflocscalemethod
0501cdf

Excel formula:

=T_DIST(0, 5, 0, 1, "cdf")

Expected output:

Result
0.5

Example 3: Inverse CDF (Quantile) at q=0.975

Inputs:

valuedflocscalemethod
0.975501icdf

Excel formula:

=T_DIST(0.975, 5, 0, 1, "icdf")

Expected output:

Result
2.570582

Example 4: Mean of the distribution

Inputs:

valuedflocscalemethod
501mean

Excel formula:

=T_DIST( , 5, 0, 1, "mean")

Expected output:

Result
0.0

Python Code

from scipy.stats import t as scipy_t import math def t_dist(value=None, df=1.0, loc=0.0, scale=1.0, method="pdf"): """ Student's t distribution function supporting multiple methods. Args: value: Input value (float), required for methods except 'mean', 'median', 'var', 'std'. df: Degrees of freedom (float, >0). loc: Location parameter (float, default: 0.0). scale: Scale parameter (float, default: 1.0, >0). method: Which method to compute (str): 'pdf', 'cdf', 'icdf', 'sf', 'isf', 'mean', 'median', 'var', 'std'. Default is 'pdf'. Returns: Result of the requested method (float or str), or an error message (str) if input is invalid. """ valid_methods = ['pdf', 'cdf', 'icdf', 'sf', 'isf', 'mean', 'median', 'var', 'std'] if not isinstance(method, str) or method.lower() not in valid_methods: return f"Invalid method: {method}. Must be one of {valid_methods}." method = method.lower() try: df = float(df) loc = float(loc) scale = float(scale) except Exception: return "Invalid input: df, loc, and scale must be numbers." if df <= 0: return "Invalid input: df must be > 0." if scale <= 0: return "Invalid input: scale must be > 0." dist = scipy_t(df, loc, scale) # Methods that require value if method in ['pdf', 'cdf', 'icdf', 'sf', 'isf']: if value is None: return f"Invalid input: missing required argument 'value' for method '{method}'." try: value = float(value) except Exception: return "Invalid input: value must be a number." try: if method == 'pdf': result = dist.pdf(value) elif method == 'cdf': result = dist.cdf(value) elif method == 'sf': result = dist.sf(value) elif method == 'isf': if not (0 <= value <= 1): return "Invalid input: value (probability) must be between 0 and 1 for isf." result = dist.isf(value) elif method == 'icdf': if not (0 <= value <= 1): return "Invalid input: value (probability) must be between 0 and 1 for icdf." result = dist.ppf(value) except Exception as e: return f"scipy.stats.t error: {e}" if isinstance(result, float): if math.isnan(result): return "Result is NaN (not a number)" if math.isinf(result): return "inf" if result > 0 else "-inf" return result # Methods that do not require value try: if method == 'mean': result = dist.mean() elif method == 'median': result = dist.median() elif method == 'var': result = dist.var() elif method == 'std': result = dist.std() except Exception as e: return f"scipy.stats.t error: {e}" if isinstance(result, float): if math.isnan(result): return "Result is NaN (not a number)" if math.isinf(result): return "inf" if result > 0 else "-inf" return result

Live Notebook

Edit this function in a live notebook.

Live Demo

Last updated on