stdt: Standardized Student t Distribution

stdtR Documentation

Standardized Student t Distribution

Description

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.

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 the standardized Student distribution, the argument df should be greater than 2 because otherwise the variance is undefined.

log

logical; if TRUE, then probabilities (or densities) p are given as log(p) and the derivatives will be given with respect to log(p).

grad_x

logical; if TRUE, then the function returns the derivative with respect to x.

grad_df

logical; if TRUE, then the function returns the derivative with respect to df.

n

positive integer. If the rt0 function is used then this argument represents the number of random draws. Otherwise, n stands for the number of iterations used to calculate the derivatives associated with the pt0 function via the pbetaDiff function.

Details

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.

Value

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.

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)


mnorm documentation built on April 14, 2026, 5:07 p.m.

Related to stdt in mnorm...