| stdt | R Documentation |
These functions calculate and differentiate a cumulative distribution function and the density function of the standardized (to zero mean and unit variance) Student distribution. Quantile function and random number generator are also provided.
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)
x |
numeric vector of quantiles. |
df |
positive real value representing the number of degrees of freedom.
Since this function deals with the standardized Student distribution, the
argument |
log |
logical; if |
grad_x |
logical; if |
grad_df |
logical; if |
n |
positive integer. If the |
The 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 the cumulative distribution function of the beta distribution
which is calculated by the pbeta function.
Function rt0 returns a numeric vector of random numbers.
The function qt0 returns a numeric vector of quantiles.
The functions pt0 and dt0 return a list which may contain the
following elements:
prob - a numeric vector of the probabilities calculated for each
element of x. Exclusively for the pt0 function.
den - a numeric vector of the densities calculated for each
element of x. Exclusively for the dt0 function.
grad_x - a numeric vector of the derivatives with respect to
p for each element of x.
This element appears only if the input argument grad_x is TRUE.
grad_df - a numeric vector of the derivatives with respect to
p for each element of x.
This element appears only if the input argument
grad_df is TRUE.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.