R/dist_student_t.R
dist_student_t.Rd
The 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.08808012 -1.93113430 -3.46182652 0.74689224 1.54425503 -0.19301405
#> [7] -0.67914176 0.96010252 0.19686454 -3.10147957
#>
#> [[2]]
#> [1] 5.33659937 0.66755900 1.06674924 0.88246880 2.63206675 7.82914627
#> [7] 0.04973132 2.49117596 0.23530374 2.90607445
#>
#> [[3]]
#> [1] -3.8580694 -0.5277899 0.5172049 -2.7594600 2.1386771 2.1126339
#> [7] 2.8579755 4.3154884 -0.2946130 4.7344929
#>
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