Skip to main content
v2026.11,986 entries · CC-BY 4.0

pt in R: Student t Distribution Function (pt, qt, dt, rt)

pt() in R gives the Student t cumulative probability. Learn pt vs qt, how to get a p-value, lower.tail, rt and dt, with a worked example.

Written and maintained by CASRAI Editorial Board

Published · Last updated

On this page

pt() in R returns the cumulative probability of the Student t distribution: given a t value and degrees of freedom, it gives P(T ≤ t). Researchers use it mainly to turn a t statistic into a p-value; its inverse, qt(), turns a probability into a critical value. This guide shows which of the four t-distribution functions to call for which task, with a worked example you can reproduce.

What pt() is used for in research

R’s stats package groups four functions for the Student t distribution on one manual page (“The Student t Distribution”): dt (density), pt (distribution function), qt (quantile function) and rt (random generation). Most analysis work needs only pt and qt: pt converts an observed t statistic into a tail probability, and qt converts a chosen tail probability (such as 0.975) into the t value that cuts it off. For background on the distribution itself, see what the t distribution is.

Access: nothing to install

All four functions are part of the stats package, which ships with base R. Download R from the R Project and the functions are available without loading any package.

Which function answers which question

Question Function Call
Probability below a t value (lower tail) pt pt(q, df)
Probability above a t value (upper tail) pt pt(q, df, lower.tail = FALSE)
t value that cuts off a given lower-tail probability (critical value) qt qt(p, df)
Height of the density curve at a t value (for plotting) dt dt(x, df)
Random draws from a t distribution (simulation) rt rt(n, df)

The full signatures on the manual page are dt(x, df, ncp, log = FALSE), pt(q, df, ncp, lower.tail = TRUE, log.p = FALSE), qt(p, df, ncp, lower.tail = TRUE, log.p = FALSE) and rt(n, df, ncp). The argument df is the degrees of freedom; ncp is an optional non-centrality parameter, and if it is omitted the central t distribution is used.

Step by step: how to solve for a p-value in R

This is a worked example with made-up numbers, not data from a real study. Suppose a one-sample t statistic is 2.31 with 14 degrees of freedom.

  1. Lower-tail probability. pt(2.31, df = 14) returns about 0.9817, the probability of a t value at or below 2.31.
  2. Upper-tail (one-sided) p-value. pt(2.31, df = 14, lower.tail = FALSE) returns about 0.0183. With lower.tail = FALSE the probability is P(T > t) rather than P(T ≤ t).
  3. Two-sided p-value. 2 * pt(-abs(2.31), df = 14) returns about 0.0366. Using -abs(t) puts the value in the lower tail whatever the sign of the statistic, then doubles it for the two tails. Forgetting abs() with a positive t gives a p-value above 1.
  4. Critical value. qt(0.975, df = 14) returns about 2.1448, the cutoff for a 95% two-sided test. Because 2.31 exceeds it, the two-sided p-value falls below 0.05, which agrees with step 3.

For a left-tailed or two-tailed hypothesis, see left-tailed tests and two-tailed hypothesis testing. The same pattern with the normal distribution is covered in pnorm in R; the t distribution approaches it as the degrees of freedom grow.

qt vs pt: inverse functions

qt is the inverse of pt. pt goes from a t value to a probability; qt goes from a probability to a t value. Round trip: pt(qt(0.975, 14), 14) returns 0.975. Use pt when you have a statistic and want a p-value, and qt when you have a significance level and want the critical value or a confidence-interval multiplier.

qt in R

qt(p, df) is the quantile function. Its lower.tail argument works as for pt: qt(0.05, df = 14, lower.tail = FALSE) equals qt(0.95, df = 14), about 1.7613. The R manual’s own example, qt(.975, df = c(1:10, 20, 50, 100, 1000)), shows the 97.5% quantile shrinking toward 1.96 as df grows (about 2.228 at df = 10, 2.086 at 20, 2.009 at 50, 1.984 at 100 and 1.962 at 1000).

rt in R

rt(n, df) draws n random values from a t distribution, for example rt(1000, df = 14) for a simulation. The result has length n. Use set.seed() first if you need reproducible draws.

dt in R

dt(x, df) gives the density, useful for drawing the curve, for example with curve(dt(x, df = 14), from = -4, to = 4).

Reading the output

  • All four functions return numbers, not test reports. pt and qt are vectorised: arguments are recycled to the length of the longest, so pt(c(1, 2, 3), df = 14) returns three probabilities.
  • lower.tail = TRUE (the default) gives P(X ≤ x); FALSE gives P(X > x).
  • log.p = TRUE returns log probabilities, useful for very small tails.
  • The central t distribution has mean 0 for df > 1 and variance df/(df − 2) for df > 2.
  • If you run a test with t.test(), the returned object already contains statistic, parameter (the degrees of freedom), p.value and conf.int, so you can compare your manual pt calculation to t.test(x)$p.value. See t-test in R. By default t.test() uses the Welch test (var.equal = FALSE) for two samples, so its degrees of freedom may not be an integer; pt and qt accept non-integer df.

Troubleshooting

  • NaN with a warning: invalid arguments, such as non-positive df, return NaN with a warning. df must be positive; it may be non-integer, and Inf is allowed.
  • p-value above 1: usually 2 * pt(t, df) with a positive t. Use 2 * pt(-abs(t), df).
  • p-value near 1 when you expected near 0: you probably need lower.tail = FALSE (upper tail), or the opposite sign.
  • Setting ncp = 0 is not the same as omitting it: the manual notes that ncp = 0 uses the non-central algorithm, which differs from the central one. Leave ncp out for ordinary tests; the non-central form is mainly for power calculations, and results are documented as accurate only for |ncp| up to 37.62.

What are the t and F distributions?

The Student t distribution is a symmetric, bell-shaped distribution centred on 0 that is used for test statistics when the population standard deviation is estimated from the sample; its single parameter is the degrees of freedom. The F distribution is a different distribution, used for ratios of variances such as in ANOVA, and it has two degrees-of-freedom parameters. R follows the same d/p/q/r naming for it (df, pf, qf, rf), and for the normal distribution (dnorm, pnorm, qnorm, rnorm).

What does the t() function do in R?

Nothing related to the t distribution. In base R, t(x) is the matrix transpose: given a matrix or data frame, it returns the transpose (R base documentation, “Matrix Transpose”). The t distribution functions are dt, pt, qt and rt.

Free alternatives

Task R Python (SciPy)
CDF (lower tail) pt(t, df) scipy.stats.t.cdf(t, df)
Upper tail pt(t, df, lower.tail = FALSE) scipy.stats.t.sf(t, df)
Quantile qt(p, df) scipy.stats.t.ppf(p, df)

The SciPy results for the worked example above (cdf 0.9817, sf 0.0183, ppf 2.1448) match the R values given.

FAQ

What does pt give in R?

The cumulative probability of the Student t distribution: P(T ≤ q) for a t value q and degrees of freedom df, or P(T > q) with lower.tail = FALSE.

What is pt in R code?

It is the distribution-function member of the t-distribution family in the stats package: pt(q, df, ncp, lower.tail = TRUE, log.p = FALSE).

How do I solve for a p-value in R?

Two-sided: 2 * pt(-abs(t), df). One-sided upper: pt(t, df, lower.tail = FALSE). See the worked example above and the p-value definition.

What does the t() function do in R?

It transposes a matrix or data frame; it is unrelated to the t distribution.

What are the t and F distributions?

Both are probability distributions used for test statistics: t has one degrees-of-freedom parameter, F has two. R provides dt/pt/qt/rt and df/pf/qf/rf.

What is the difference between qt and pt?

pt maps a t value to a probability; qt maps a probability to a t value.

Sources

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about pt in R: Student t Distribution Function (pt, qt, dt, rt)

2 free questions a day, no account.

An AI assistant for research: funder rules, compliance, methods and publishing. It links the sources behind its answers and labels answers that come from a web search.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays open to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →