The Student's t-distribution is a continuous probability distribution used primarily in hypothesis testing and in constructing confidence intervals for small sample sizes. It is defined by one parameter: the degrees of freedom \(\nu > 0\).
Usage
Stud(df = 1)
# S4 method for class 'Stud,numeric'
d(distr, x, log = FALSE)
# S4 method for class 'Stud,numeric'
p(distr, q, lower.tail = TRUE, log.p = FALSE)
# S4 method for class 'Stud,numeric'
qn(distr, p, lower.tail = TRUE, log.p = FALSE)
# S4 method for class 'Stud,numeric'
r(distr, n)
# S4 method for class 'Stud'
mean(x)
# S4 method for class 'Stud'
median(x)
# S4 method for class 'Stud'
mode(x)
# S4 method for class 'Stud'
var(x)
# S4 method for class 'Stud'
sd(x)
# S4 method for class 'Stud'
skew(x)
# S4 method for class 'Stud'
kurt(x)
# S4 method for class 'Stud'
entro(x)
llt(x, df)
# S4 method for class 'Stud,numeric'
ll(distr, x)
Arguments
- df
numeric. The distribution degrees of freedom parameter.
- distr
an object of class
Stud
.- x
For the density function,
x
is a numeric vector of quantiles. For the moments functions,x
is an object of classStud
. For the log-likelihood and the estimation functions,x
is the sample of observations.- log, log.p
logical. Should the logarithm of the probability be returned?
- q
numeric. Vector of quantiles.
- lower.tail
logical. If TRUE (default), probabilities are \(P(X \leq x)\), otherwise \(P(X > x)\).
- p
numeric. Vector of probabilities.
- n
number of observations. If
length(n) > 1
, the length is taken to be the number required.
Value
Each type of function returns a different type of object:
Distribution Functions: When supplied with one argument (
distr
), thed()
,p()
,q()
,r()
,ll()
functions return the density, cumulative probability, quantile, random sample generator, and log-likelihood functions, respectively. When supplied with both arguments (distr
andx
), they evaluate the aforementioned functions directly.Moments: Returns a numeric, either vector or matrix depending on the moment and the distribution. The
moments()
function returns a list with all the available methods.Estimation: Returns a list, the estimators of the unknown parameters. Note that in distribution families like the binomial, multinomial, and negative binomial, the size is not returned, since it is considered known.
Variance: Returns a named matrix. The asymptotic covariance matrix of the estimator.
Details
The probability density function (PDF) of the Student's t-distribution is: $$ f(x; \nu) = \frac{\Gamma\left(\frac{\nu + 1}{2}\right)}{\sqrt{\nu\pi}\ \Gamma\left(\frac{\nu}{2}\right)}\left(1 + \frac{x^2}{\nu}\right)^{-\frac{\nu + 1}{2}} .$$
Examples
# -----------------------------------------------------
# Student Distribution Example
# -----------------------------------------------------
# Create the distribution
df <- 12
D <- Stud(df)
# ------------------
# dpqr Functions
# ------------------
d(D, c(-3, 0, 3)) # density function
#> [1] 0.01028313 0.39072631 0.01028313
p(D, c(-3, 0, 3)) # distribution function
#> [1] 0.005533348 0.500000000 0.994466652
qn(D, c(0.4, 0.8)) # inverse distribution function
#> [1] -0.2590327 0.8726093
x <- r(D, 100) # random generator function
# alternative way to use the function
d1 <- d(D) ; d1(x) # d1 is a function itself
#> [1] 0.073179785 0.213366385 0.273822581 0.158779925 0.201403312 0.077688511
#> [7] 0.348553507 0.196524538 0.109195424 0.237736256 0.346758652 0.332121040
#> [13] 0.305045327 0.305785895 0.294381515 0.221349475 0.304215580 0.385167577
#> [19] 0.390676766 0.271899025 0.216824582 0.228513034 0.135810426 0.155550204
#> [25] 0.355941745 0.387143322 0.220158847 0.096673576 0.246811552 0.115420628
#> [31] 0.369833128 0.374017741 0.106134830 0.247255798 0.355385296 0.008273681
#> [37] 0.171724209 0.255791184 0.212983206 0.390334291 0.362071031 0.360626427
#> [43] 0.097617118 0.383253525 0.389867731 0.366406489 0.385593710 0.389591488
#> [49] 0.378686774 0.388750415 0.363196501 0.043547878 0.321735903 0.186193372
#> [55] 0.388838797 0.238262456 0.285382750 0.357844810 0.308742381 0.342104760
#> [61] 0.081994968 0.387031331 0.039723525 0.369303712 0.305111345 0.289699421
#> [67] 0.193194692 0.272063528 0.094543450 0.366515072 0.219627148 0.368378820
#> [73] 0.012591657 0.209287423 0.344485782 0.346727246 0.382439222 0.282420470
#> [79] 0.316662449 0.353463531 0.387852946 0.250870806 0.341302341 0.388519159
#> [85] 0.385451066 0.314989912 0.330173291 0.352113206 0.200181729 0.326651183
#> [91] 0.268268462 0.027374649 0.037253969 0.221857172 0.388653113 0.345048923
#> [97] 0.326911772 0.360828675 0.381173834 0.383556939
# ------------------
# Moments
# ------------------
mean(D) # Expectation
#> [1] 0
median(D) # Median
#> [1] 0
mode(D) # Mode
#> [1] 0
var(D) # Variance
#> [1] 1.2
sd(D) # Standard Deviation
#> [1] 1.095445
skew(D) # Skewness
#> [1] 0
kurt(D) # Excess Kurtosis
#> [1] 0.75
entro(D) # Entropy
#> [1] 1.503907
# List of all available moments
mom <- moments(D)
mom$mean # expectation
#> [1] 0
# ------------------
# Point Estimation
# ------------------
ll(D, x)
#> [1] -146.2144
llt(x, df)
#> [1] -146.2144