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(), only for abs(ncp) <= 37.62.
If omitted, use the central t distribution.
We recommend reading this documentation on https://pkg.mitchelloharawild.com/distributional/, where the math will render nicely.
In the following, let \(X\) be a central Students T random variable
with df = \(\nu\).
Support: \(R\), the set of all real numbers
Mean: Undefined unless \(\nu \ge 2\), in which case the mean is zero.
Variance:
$$ \frac{\nu}{\nu - 2} $$
Undefined if \(\nu < 1\), infinite when \(1 < \nu \le 2\).
Probability density function (p.d.f):
$$ f(x) = \frac{\Gamma(\frac{\nu + 1}{2})}{\sqrt{\nu \pi} \Gamma(\frac{\nu}{2})} (1 + \frac{x^2}{\nu} )^{- \frac{\nu + 1}{2}} $$
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] 0.53769647 -1.12161683 -0.03008724 -0.23799141 1.40382052
#> [6] 10.68439819 -4.59709841 -0.74840329 -10.61638467 -0.49604079
#>
#> [[2]]
#> [1] 4.50175371 2.63206675 7.82914627 0.04973132 2.49117596 0.23530374
#> [7] 2.90607445 -1.14776366 1.08072715 1.09743804
#>
#> [[3]]
#> [1] 2.8579755 4.3154884 -0.2946130 4.7344929 3.1980660 8.1827146
#> [7] 0.8940991 5.1130355 -1.1075269 -2.4289302
#>
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