| ptdiff_NI | R Documentation |
Calculates the cumulative distribution function (CDF) of the difference
between two independent non-standardised t-distributed random variables
using numerical integration. Specifically, computes
P(T_t - T_c \le q) or P(T_t - T_c > q), where
T_k \sim t(\mu_k, \sigma_k^2, \nu_k) for k \in \{t, c\}.
ptdiff_NI(q, mu_t, mu_c, sd_t, sd_c, nu_t, nu_c, lower.tail = TRUE)
q |
A numeric scalar representing the quantile threshold. |
mu_t |
A numeric scalar or vector giving the location parameter of the t-distribution for the treatment group. |
mu_c |
A numeric scalar or vector giving the location parameter of the t-distribution for the control group. |
sd_t |
A positive numeric scalar or vector giving the scale parameter of the t-distribution for the treatment group. |
sd_c |
A positive numeric scalar or vector giving the scale parameter of the t-distribution for the control group. |
nu_t |
A numeric scalar giving the degrees of freedom of the t-distribution for the treatment group. Must be greater than 2 for finite variance. |
nu_c |
A numeric scalar giving the degrees of freedom of the t-distribution for the control group. Must be greater than 2 for finite variance. |
lower.tail |
A logical scalar; if |
The upper-tail probability is obtained via the convolution formula:
P(T_t - T_c > q)
= \int_{-\infty}^{\infty}
F_{t(\mu_c, \sigma_c^2, \nu_c)}(x - q)\,
f_{t(\mu_t, \sigma_t^2, \nu_t)}(x)\, dx
where f_{t(\mu_t, \sigma_t^2, \nu_t)} is the density of T_t
and F_{t(\mu_c, \sigma_c^2, \nu_c)} is the CDF of T_c.
The integral is evaluated by adaptive Gauss-Kronrod quadrature via
stats::integrate.
When the input parameters are vectors, mapply applies the scalar
integration function across all parameter sets.
Advantages:
Exact within numerical precision.
Handles arbitrary parameter combinations.
Computational note: this method is substantially slower than the
Moment-Matching approximation (ptdiff_MM) because it calls
integrate() once per parameter set. For large-scale simulation
(many parameter sets), prefer CalcMethod = 'MM' in
pbayesdecisionprob1cont.
A numeric scalar or vector in [0, 1]. When mu_t,
mu_c, sd_t, or sd_c are vectors of length
n, a vector of length n is returned.
# P(T_t - T_c > 3) with equal parameters
ptdiff_NI(q = 3, mu_t = 2, mu_c = 0, sd_t = 1, sd_c = 1,
nu_t = 17, nu_c = 17, lower.tail = FALSE)
# P(T_t - T_c > 1) with unequal scales
ptdiff_NI(q = 1, mu_t = 5, mu_c = 3, sd_t = 2, sd_c = 1.5,
nu_t = 10, nu_c = 15, lower.tail = FALSE)
# P(T_t - T_c > 0) with different degrees of freedom
ptdiff_NI(q = 0, mu_t = 1, mu_c = 1, sd_t = 1, sd_c = 1,
nu_t = 5, nu_c = 20, lower.tail = FALSE)
# Lower tail: P(T_t - T_c <= 2)
ptdiff_NI(q = 2, mu_t = 3, mu_c = 0, sd_t = 1.5, sd_c = 1.2,
nu_t = 12, nu_c = 15, lower.tail = TRUE)
# Vectorised usage
ptdiff_NI(q = 1, mu_t = c(2, 3, 4), mu_c = c(0, 1, 2),
sd_t = c(1, 1.2, 1.5), sd_c = c(1, 1.1, 1.3),
nu_t = 10, nu_c = 10, lower.tail = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.