R/dist_student_t.R
dist_student_t.RdThe Student's T distribution is closely related to the Normal()
distribution, but has heavier tails. As \(\nu\) increases to \(\infty\),
the Student's T converges to a Normal. The T distribution appears
repeatedly throughout classic frequentist hypothesis testing when
comparing group means.
dist_student_t(df, mu = 0, sigma = 1, ncp = NULL)degrees of freedom (\(> 0\), maybe non-integer). df
= Inf is allowed.
The location parameter of the distribution.
If ncp == 0 (or NULL), this is the median.
The scale parameter of the distribution.
non-centrality parameter \(\delta\);
currently except for rt(), accurate only for abs(ncp) <= 37.62.
If omitted, use the central t distribution.
We recommend reading this documentation on pkgdown which renders math nicely. https://pkg.mitchelloharawild.com/distributional/reference/dist_student_t.html
In the following, let \(X\) be a location-scale Student's T random variable with
df = \(\nu\), mu = \(\mu\), sigma = \(\sigma\), and
ncp = \(\delta\) (non-centrality parameter).
If \(Z\) follows a standard Student's T distribution (with df = \(\nu\)
and ncp = \(\delta\)), then \(X = \mu + \sigma Z\).
Support: \(R\), the set of all real numbers
Mean:
For the central distribution (ncp = 0 or NULL):
$$ E(X) = \mu $$
for \(\nu > 1\), and undefined otherwise.
For the non-central distribution (ncp \(\neq\) 0):
$$ E(X) = \mu + \delta \sqrt{\frac{\nu}{2}} \frac{\Gamma((\nu-1)/2)}{\Gamma(\nu/2)} \sigma $$
for \(\nu > 1\), and undefined otherwise.
Variance:
For the central distribution (ncp = 0 or NULL):
$$ \mathrm{Var}(X) = \frac{\nu}{\nu - 2} \sigma^2 $$
for \(\nu > 2\). Undefined if \(\nu \le 1\), infinite when \(1 < \nu \le 2\).
For the non-central distribution (ncp \(\neq\) 0):
$$ \mathrm{Var}(X) = \left[\frac{\nu(1+\delta^2)}{\nu-2} - \left(\delta \sqrt{\frac{\nu}{2}} \frac{\Gamma((\nu-1)/2)}{\Gamma(\nu/2)}\right)^2\right] \sigma^2 $$
for \(\nu > 2\). Undefined if \(\nu \le 1\), infinite when \(1 < \nu \le 2\).
Probability density function (p.d.f):
For the central distribution (ncp = 0 or NULL), the standard
t distribution with df = \(\nu\) has density:
$$ f_Z(z) = \frac{\Gamma((\nu + 1)/2)}{\sqrt{\pi \nu} \Gamma(\nu/2)} \left(1 + \frac{z^2}{\nu} \right)^{- (\nu + 1)/2} $$
The location-scale version with mu = \(\mu\) and sigma = \(\sigma\)
has density:
$$ f(x) = \frac{1}{\sigma} f_Z\left(\frac{x - \mu}{\sigma}\right) $$
For the non-central distribution (ncp \(\neq\) 0), the density is
computed numerically via stats::dt().
Cumulative distribution function (c.d.f):
For the central distribution (ncp = 0 or NULL), the cumulative
distribution function is computed numerically via stats::pt(), which
uses the relationship to the incomplete beta function:
$$ F_\nu(t) = \frac{1}{2} I_x\left(\frac{\nu}{2}, \frac{1}{2}\right) $$
for \(t \le 0\), where \(x = \nu/(\nu + t^2)\) and \(I_x(a,b)\) is
the incomplete beta function (stats::pbeta()). For \(t \ge 0\):
$$ F_\nu(t) = 1 - \frac{1}{2} I_x\left(\frac{\nu}{2}, \frac{1}{2}\right) $$
The location-scale version is: \(F(x) = F_\nu((x - \mu)/\sigma)\).
For the non-central distribution (ncp \(\neq\) 0), the cumulative
distribution function is computed numerically via stats::pt().
Moment generating function (m.g.f):
Does not exist in closed form. Moments are computed using the formulas for mean and variance above where available.
dist <- dist_student_t(df = c(1,2,5), mu = c(0,1,2), sigma = c(1,2,3))
dist
#> <distribution[3]>
#> [1] t(1, 0, 1) t(2, 1, 2) t(5, 2, 3)
mean(dist)
#> [1] NA 1 2
variance(dist)
#> [1] NA Inf 15
generate(dist, 10)
#> [[1]]
#> [1] 1.19912754 10.25605980 -3.61233726 -0.26323684 1.91403157 -0.11615272
#> [7] -1.06442672 0.07819642 5.30882381 0.33890248
#>
#> [[2]]
#> [1] 3.1180216 1.1487996 0.2438915 2.3557446 -0.6345444 -1.5501759
#> [7] -3.9453000 2.6425754 -2.9443546 6.8841964
#>
#> [[3]]
#> [1] 1.4596097 -2.5646151 0.5835472 0.6545391 -1.1037197 0.4738808
#> [7] 2.1053927 -4.0510490 4.2514369 1.7944504
#>
density(dist, 2)
#> [1] 0.06366198 0.14814815 0.12653556
density(dist, 2, log = TRUE)
#> [1] -2.754168 -1.909543 -2.067232
cdf(dist, 4)
#> [1] 0.9220209 0.8638034 0.7327454
quantile(dist, 0.7)
#> [1] 0.7265425 2.2344268 3.6782889