stdt {mnorm} | R Documentation |
Standardized Student t Distribution
Description
These functions calculate and differentiate a cumulative distribution function and density function of the standardized (to zero mean and unit variance) Student distribution. Quantile function and random numbers generator are also provided.
Usage
dt0(x, df = 10, log = FALSE, grad_x = FALSE, grad_df = FALSE)
pt0(x, df = 10, log = FALSE, grad_x = FALSE, grad_df = FALSE, n = 10L)
rt0(n = 1L, df = 10)
qt0(x = 1L, df = 10)
Arguments
x |
numeric vector of quantiles. |
df |
positive real value representing the number of degrees of freedom.
Since this function deals with standardized Student distribution, argument
|
log |
logical; if |
grad_x |
logical; if |
grad_df |
logical; if |
n |
positive integer. If |
Details
Standardized (to zero mean and unit variance) Student distribution has the following density and cumulative distribution functions:
f(x) = \frac{\Gamma\left(\frac{v + 1}{2}\right)}{
\sqrt{(v - 2)\pi}\Gamma\left(\frac{v}{2}\right)}
\left(1 + \frac{x^2}{v - 2}\right)^{-\frac{v+1}{2}},
F(x) =
\begin{cases}
1 - \frac{1}{2}I(\frac{v - 2}{x^2 + v - 2},
\frac{v}{2}, \frac{1}{2})\text{, if }x \geq 0\\
\frac{1}{2}I(\frac{v - 2}{x^2 + v - 2},
\frac{v}{2}, \frac{1}{2})\text{, if }x < 0
\end{cases},
where v > 2
is the number of degrees of freedom df
and
I(.)
is a cumulative distribution function of beta distribution
which is calculated by pbeta
function.
Value
Function rt0
returns a numeric vector of random numbers.
Function qt0
returns a numeric vector of quantiles.
Functions pt0
and dt0
return a list which may contain the
following elements:
-
prob
- numeric vector of probabilities calculated for each element ofx
. Exclusively forpt0
function. -
den
- numeric vector of densities calculated for each each element ofx
. Exclusively fordt0
function. -
grad_x
- numeric vector of derivatives respect top
for each element ofx
. This element appears only if input argumentgrad_x
isTRUE
. -
grad_df
- numeric vector of derivatives respect toq
for each element ofx
. This element appears only if input argumentgrad_df
isTRUE
.
Examples
# Simple examples
pt0(x = 0.3, df = 10, log = FALSE, grad_x = TRUE, grad_df = TRUE)
dt0(x = 0.3, df = 10, log = FALSE, grad_x = TRUE, grad_df = TRUE)
qt0(x = 0.3, df = 10)
# Compare analytical and numeric derivatives
delta <- 1e-6
x <- c(-2, -1, 0, 1, 2)
df <- 5
# For probabilities
out <- pt0(x, df = df, grad_x = TRUE, grad_df = TRUE)
p0 <- out$prob
# grad_x
p1 <- pt0(x + delta, df = df)$prob
data.frame(numeric = (p1 - p0) / delta, analytical = out$grad_x)
# grad_df
p1 <- pt0(x, df = df + delta)$prob
data.frame(numeric = (p1 - p0) / delta, analytical = out$grad_df)
# For densities
out <- dt0(x, df = df, grad_x = TRUE, grad_df = TRUE)
p0 <- out$den
# grad_x
p1 <- dt0(x + delta, df = df)$den
data.frame(numeric = (p1 - p0) / delta, analytical = out$grad_x)
# grad_df
p1 <- dt0(x, df = df + delta)$den
data.frame(numeric = (p1 - p0) / delta, analytical = out$grad_df)