
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.
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)
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 of x
. Exclusively for pt0
function.
den
- numeric vector of densities calculated for each
each element of x
. Exclusively for dt0
function.
grad_x
- numeric vector of derivatives respect to p
for
each element of x
.
This element appears only if input argument grad_x
is TRUE
.
grad_df
- numeric vector of derivatives respect to q
for
each element of x
.
This element appears only if input argument grad_df
is TRUE
.
numeric vector of quantiles.
positive real value representing the number of degrees of freedom.
Since this function deals with standardized Student distribution, argument
df
should be greater than 2
because otherwise variance is
undefined.
logical; if TRUE
then probabilities (or densities) p
are given as log(p) and derivatives will be given respect to log(p).
logical; if TRUE
then function returns a derivative
respect to x
.
logical; if TRUE
then function returns a derivative
respect to df
.
positive integer. If rt0
function is used then this
argument represents the number of random draws. Otherwise n
states
for the number of iterations used to calculate the derivatives associated
with pt0
function via pbetaDiff
function.
Standardized (to zero mean and unit variance) Student distribution
has the following density and cumulative distribution functions:
df
and
pbeta
function.
# 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)
Run the code above in your browser using DataLab