StatsCalculators.com

Student's t-Distribution

Created:August 15, 2024

This calculator computes the probability of a Student's t-distribution based on the specified degrees of freedom (ν) and comparison type. It also generates a distribution chart to visualize the results.

Calculator

Parameters

Distribution Chart

Click Calculate to view the distribution chart

Learn More

Student's t-Distribution

Definition: The Student's t-distribution is a continuous probability distribution that arises when estimating the mean of a normally distributed population in situations where the sample size is small and the population standard deviation is unknown.

Formula:The probability density function (PDF) is given by:f(t)=Γ((ν+1)/2)νπΓ(ν/2)(1+t2ν)(ν+1)/2f(t) = \frac{\Gamma((\nu+1)/2)}{\sqrt{\nu\pi}\Gamma(\nu/2)}\left(1+\frac{t^2}{\nu}\right)^{-(\nu+1)/2}Where:ν=degrees of freedom\nu = \text{degrees of freedom}Γ=gamma function\Gamma = \text{gamma function}

Properties

  • Mean: E(X)=0E(X) = 0 for ν>1\nu > 1
  • Variance: Var(X)=νν2\text{Var}(X) = \frac{\nu}{\nu-2} for ν>2\nu > 2
  • Key Characteristics:
    • Bell-shaped and symmetric about 0
    • More peaked and heavier tails than normal distribution
    • Approaches normal distribution as ν increases
    • Support is all real numbers

How to Calculate t-Distribution in R

R
library(tidyverse)

df <- 10  # degrees of freedom
x1 <- -2 
x2 <- 2 

# P(x1 < X < x2)
prob <- pt(x2, df = df) - pt(x1, df = df)
print(str_glue("P({x1} < X < {x2}) = {round(prob, 4)}"))

# plot
x <- seq(-4, 4, length.out = 1000)
density <- dt(x, df = df)
df_plot <- tibble(x = x, density = density)

ggplot(df_plot, aes(x = x, y = density)) +
  geom_line(color = "blue") +
  geom_area(data = subset(df_plot, x >= x1 & x <= x2),
            aes(x = x, y = density),
            fill = "blue",
            alpha = 0.2) +
  labs(title = str_glue("Student's t-Distribution (df = {df})"),
       x = "t",
       y = "Probability Density") +
  geom_vline(xintercept = 0, 
             linetype = "dashed", 
             color = "gray50") +
  theme_minimal()

How to Calculate t-Distribution in Python

Python
import numpy as np
from scipy import stats
import matplotlib.pyplot as plt
import seaborn as sns

df = 10  # degrees of freedom
x1 = -2 
x2 = 2

# P(x1 < X < x2)
prob = stats.t.cdf(x2, df) - stats.t.cdf(x1, df)
print(f"P({x1} < X < {x2}) = {prob:.4f}")

# plot 
x = np.linspace(-4, 4, 1000)
pdf = stats.t.pdf(x, df)

plt.figure(figsize=(10, 6))
plt.plot(x, pdf, 'blue', label='PDF')

x_shade = x[(x >= x1) & (x <= x2)]
pdf_shade = stats.t.pdf(x_shade, df)
plt.fill_between(x_shade, pdf_shade, alpha=0.2, color='blue')

plt.axvline(x=0, color='gray', linestyle='--', alpha=0.5)

plt.title(f"Student's t-Distribution (df = {df})")
plt.xlabel('t')
plt.ylabel('Probability Density')
plt.grid(True, alpha=0.3)
plt.show()

Related Calculators