TDist
The Student's t Distribution

### Description

Calculates density, cumulative probability, quantile, and generate random sample for the Student's t distribution (continuous).

### Usage

    dt(x, df, ncp = 0, log = FALSE) # density
    pt(q, df, ncp = 0, lower.tail = TRUE, log.p = FALSE) # probability
    qt(p, df, ncp = 0, lower.tail = TRUE, log.p = FALSE) # quantile
    rt(n, df, ncp = 0) # random

### Arguments

x, q | numeric vectors in the range (-Inf, Inf) that specify the quantiles.
p | a numeric vector in the range [0, 1] that specifies the probabilities.
n | an integer scalar in the range [0, Inf) that specifies the number of random samples requested. If the input value is not an integer, it is truncated. If length(n) is greater than 1, the random function returns length(n) random samples.
df | a numeric vector in the range [0, Inf) that specifies the degrees of freedom.
ncp | a numeric vector in the range (-Inf, Inf) that specifies the noncentrality parameter.
log | a logical value. If FALSE (default), the density function returns the density itself. If TRUE, it returns the log of the density.
lower.tail | a logical value. If TRUE (default), the probability supplied to the quantile function or returned by the probability function is P[X <= x]. If FALSE, it is P[X > x].
log.p | a logical value. If FALSE (default), the probability supplied to the quantile function or returned by the probability function is the probability itself. If TRUE, it is the log of the probability.

### Details

The distribution parameter(s) are replicated cyclically to be the same length as the input x, q, p, or the number of random samples requested.
Missing values (NAs) in the input or the distribution parameter(s) will cause the corresponding elements of the result to be missing.
A noncentral Student's t distribution is given by: (Z + d) / sqrt( chi^2 / df ) where:

- Z is standard normal
- d is the noncentrality parameter
- df is the degrees of freedom of the chi^2 variable.

To generate random variates from the noncentral Student's t distribution:
rnorm(n, d) / sqrt(rchisq(n, df=df) / df)

| Note |
|  | To generate random variates you can use either rt() from Student's t distribution or rnorm() from the normal distribution. However, if you require consistency in random variate generation, you should use rnorm(), as shown in the preceding formula, instead of rt(). This is true even for cases where the noncentrality parameter d is equal to zero. When (d = 0), rt() generates a different sequence of random numbers each time but (rnorm) generates consistent random variates.

If there are missing values (NAs) in the q or p numeric vectors, the corresponding values in the numeric vector for the result will also be missing.
Value
returns density (dt), cumulative probability (pt), quantile (qt), or random sample (rt) for Student's t distribution with parameter df and an optional noncentrality parameter ncp.
Side Effects
If the .Random.seed dataset exists, the random sample function updates its value. The random sample function creates the .Random.seed dataset if it does not exist.
Background
The Student's t distribution is a family of continuous probability distributions defined on the interval (-Inf, Inf) and parameterized by a positive parameter, df.
References
Johnson, N. L. and Kotz, S. 1970. Continuous Univariate Distributions, Volume 2. Boston, MA: Houghton-Mifflin.
Posten, H. O. 1993. An effective algorithm for the noncentral beta distribution function. The American Statistician. Volume 47. 129-131.
See Also
F, Normal, set.seed
Examples

    (1 - pt(1.96, 12))*2 # two-tailed p-value for t with 12 df

Package stats version 6.1.5-18
Package Index