rfunctionstatisticsprobability

Student's t-distribution CDF R base documentation


In the context of the Student's t-distribution cumulative distribution function, R Version 4.3.1's ?dt documentation highlights the following result:

However, upon attempting to verify the accuracy of this formula, an inconsistency arises, as illustrated in the following code snippet:

v <- 5
t <- -1

## Student's t-distribution cumulative distribution function
pt(q = t, df = v, lower.tail = TRUE, ncp = 0)
#> [1] 0.1816087

## Application of the theorical result where there is a discrepancy 
## based on what is mentioned in R Version 4.3.1's ?dt documentation
1 - pbeta(q = v / (v + t^2), shape1 = v/2, shape2 = 1/2, 
          ncp = 0,lower.tail = TRUE)
#> [1] 0.6367825

Created on 2023-10-09 with reprex v2.0.2

This issue raises questions about the accuracy of the documentation. I am seeking clarification to determine whether the problem lies in the documentation itself before reporting a potential mistake to the R project. This inquiry is related to a theoretical concept, where a detailed explanation can be found here


Solution

  • Hmm looks like an error. Here is a valid identity:

    v <- 5
    t <- -1
    
    ## Student's t-distribution cumulative distribution function
    pt(q = t, df = v, lower.tail = TRUE, ncp = 0)
    #> [1] 0.1816087
    
    x = (t + sqrt(t * t + v)) / (2.0 * sqrt(t * t + v))
    pbeta(q = x, shape1 = v/2, shape2 = v/2, ncp = 0, lower.tail = TRUE)
    #> [1] 0.1816087
    

    And another one, closer to the claim of the R doc:

    pbeta(q = v / (v + t^2), shape1 = v/2, shape2 = 1/2, 
                ncp = 0,lower.tail = TRUE) / 2
    #> [1] 0.1816087