Skip to contents

This function calculates the cumulative distribution function (CDF) of the difference between two independent t-distributed random variables using exact numerical integration via convolution. This method provides the most accurate results (within numerical precision) compared to approximation methods. Specifically, it computes P(T1 - T2 ≤ q) or P(T1 - T2 > q) where T1 and T2 follow t-distributions with potentially different location, scale, and degrees of freedom parameters.

Usage

pNI2tdiff(q, mu.t1, mu.t2, sd.t1, sd.t2, nu.t1, nu.t2, lower.tail = TRUE)

Arguments

q

A numeric value representing the quantile threshold.

mu.t1

A numeric value representing the location parameter (μ) of the first t-distribution.

mu.t2

A numeric value representing the location parameter (μ) of the second t-distribution.

sd.t1

A positive numeric value representing the scale parameter (σ) of the first t-distribution.

sd.t2

A positive numeric value representing the scale parameter (σ) of the second t-distribution.

nu.t1

A positive numeric value representing the degrees of freedom (ν) of the first t-distribution. Must be > 2 for finite variance.

nu.t2

A positive numeric value representing the degrees of freedom (ν) of the second t-distribution. Must be > 2 for finite variance.

lower.tail

A logical value; if TRUE (default), probabilities are P(T1 - T2 ≤ q), otherwise P(T1 - T2 > q).

Value

A numeric value in [0, 1] representing the cumulative probability that the difference between the two t-distributed variables is below (if lower.tail = TRUE) or exceeds (if lower.tail = FALSE) the quantile q.

Details

This function uses the exact convolution approach to compute the distribution of the difference between two t-distributed variables. The method involves:

  • Using the convolution formula: $$P(T_1 - T_2 \le q) = \int_{-\infty}^{\infty} f_1(x) \cdot F_2(x - q) dx$$

  • Where \(f_1(x)\) is the probability density function (PDF) of the first t-distribution

  • And \(F_2(x - q)\) is the cumulative distribution function (CDF) of the second t-distribution evaluated at \(x - q\)

  • Adaptive integration bounds based on the distribution characteristics (approximately ±8 standard deviations from the mean)

  • High-precision numerical integration with relative tolerance 1e-6 and absolute tolerance 1e-8

Advantages:

  • Provides exact results within numerical precision

  • Handles arbitrary combinations of parameters

  • No approximations required

Computational considerations:

  • More computationally intensive than approximation methods (e.g., Welch-Satterthwaite)

  • Recommended for final analyses where accuracy is critical

  • For exploratory analyses, consider using faster approximation methods

Examples

# Calculate P(t1 - t2 > 3) for equal parameters
pNI2tdiff(q = 3, mu.t1 = 2, mu.t2 = 0, sd.t1 = 1, sd.t2 = 1,
         nu.t1 = 17, nu.t2 = 17, lower.tail = FALSE)
#> [1] 0.24857

# Calculate P(t1 - t2 > 1) for unequal variances
pNI2tdiff(q = 1, mu.t1 = 5, mu.t2 = 3, sd.t1 = 2, sd.t2 = 1.5,
         nu.t1 = 10, nu.t2 = 15, lower.tail = FALSE)
#> [1] 0.6478101

# Calculate P(t1 - t2 > 0) for different degrees of freedom
pNI2tdiff(q = 0, mu.t1 = 1, mu.t2 = 1, sd.t1 = 1, sd.t2 = 1,
         nu.t1 = 5, nu.t2 = 20, lower.tail = FALSE)
#> [1] 0.4999528

# Calculate lower tail probability P(t1 - t2 ≤ 2)
pNI2tdiff(q = 2, mu.t1 = 3, mu.t2 = 0, sd.t1 = 1.5, sd.t2 = 1.2,
         nu.t1 = 12, nu.t2 = 15, lower.tail = TRUE)
#> [1] 0.3100353