Cumulative Distribution Function of the Difference of Two t-Distributed Variables Using the Welch-Satterthwaite Approximation
Source:R/pWS2tdiff.R
pWS2tdiff.RdThis function calculates the cumulative distribution function (CDF) of the difference between two independent t-distributed random variables using the Welch-Satterthwaite approximation. This method provides a fast and reasonably accurate approximation, particularly useful for unequal variances and degrees of freedom. Specifically, it computes P(T1 - T2 ≤ q) or P(T1 - T2 > q) where T1 and T2 follow t-distributions with potentially different parameters.
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
The Welch-Satterthwaite approximation approximates the distribution of the difference between two t-distributed variables using a single t-distribution with adjusted parameters. The method involves:
Step 1: Calculate the pooled variance (sum of squared scale parameters): $$\sigma_{\text{pooled}}^2 = \sigma_1^2 + \sigma_2^2$$
Step 2: Calculate the effective degrees of freedom using the Welch-Satterthwaite formula: $$\nu^* = \frac{(\sigma_1^2 + \sigma_2^2)^2}{\frac{\sigma_1^4}{\nu_1} + \frac{\sigma_2^4}{\nu_2}}$$
Step 3: Standardize the quantile: $$q_{\text{standardized}} = \frac{q - (\mu_1 - \mu_2)}{\sqrt{\sigma_1^2 + \sigma_2^2}}$$
Step 4: Compute the CDF using a single t-distribution with the effective degrees of freedom ν*
Advantages:
Computationally fast and efficient
Works well for unequal variances and degrees of freedom
Provides good approximation in most practical scenarios
Particularly accurate when degrees of freedom are not too small (ν > 5)
Computational considerations:
Much faster than numerical integration methods
Suitable for exploratory analyses and large-scale simulations
For final analyses requiring highest accuracy, consider using numerical integration (pNIdifft)
Examples
# Calculate P(t1 - t2 > 3) for equal parameters
pWS2tdiff(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.2421594
# Calculate P(t1 - t2 > 1) for unequal variances
pWS2tdiff(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.6533185
# Calculate P(t1 - t2 > 0) for different degrees of freedom - should be ~0.5
pWS2tdiff(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.5
# Calculate lower tail probability P(t1 - t2 ≤ 2)
pWS2tdiff(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.3036847