torch.special.gammaincc
function gammaincc<S1 extends Shape, S2 extends Shape>(input: Tensor<S1, 'float32'>, other: Tensor<S2, 'float32'>, _options?: SpecialBinaryOptions): Tensor<DynamicShape, 'float32'>Computes the regularized upper incomplete gamma function, Q(a, x) = Γ(a, x) / Γ(a).
The upper incomplete gamma function Γ(a, x) = ∫ₓ^∞ tᵃ⁻¹ exp(-t) dt represents the upper tail (complement) of the incomplete gamma integral. Q(a, x) = 1 - P(a, x) normalizes to range [0, 1]. The upper tail is particularly important for hypothesis testing (right-tail probabilities) and survival analysis. Essential for:
- Hypothesis testing: p-values and critical values (chi-squared, F-tests)
- Survival analysis: complementary CDF (tail probabilities, reliability)
- Risk assessment: upper tail probabilities for extreme events
- Bayesian inference: posterior predictive probabilities
- Quality control: acceptance sampling under gamma models
- Medical statistics: survival probabilities beyond a time point
Key Properties:
- Q(a, 0) = 1 (all mass above 0)
- Q(a, ∞) = 0 (no mass above ∞)
- Q(a, x) decreases monotonically from 1 to 0 (tail probability)
- Relationship: P(a, x) + Q(a, x) = 1 (completeness)
- Complement: P(a, x) = gammainc(a, x) = 1 - Q(a, x)
- Special: Q(a, a) ≈ 0.5 (median probability)
- Survival: S(t) = Q(shape, rate*t) for gamma survival function
- Upper incomplete: Integral from x to ∞ (upper tail)
- Tail probability: Represents right-tail area, natural for p-values
- Decreasing: Strictly decreases from 1 to 0
- Complement: Q(a,x) = 1 - P(a,x) = gammaincc(a,x)
- Hypothesis testing: Right-tail test p-values use Q, not P
- Survival function: S(t) = Q(shape, rate*t) in survival analysis
- Reliability: Q represents unreliability (failure probability)
- Shape parameter a 0: Required for well-defined gamma
- Argument x ≥ 0: Negative x not meaningful, domain is [0, ∞)
- Numerical precision: For large a and large x, both P and Q can lose precision
- Stability: Use log-scaled versions for extreme probabilities if available
Parameters
inputTensor<S1, 'float32'>- Input tensor a (shape parameter, must be 0)
otherTensor<S2, 'float32'>- Input tensor x (argument, must be ≥ 0)
_optionsSpecialBinaryOptionsoptional
Returns
Tensor<DynamicShape, 'float32'>– Tensor with Q(a, x) values in [0, 1] (tail probability)Examples
// Upper tail probability: complement of CDF
const a = torch.tensor([1, 2, 3, 5, 10]); // Shape parameters
const x = torch.tensor([1, 2, 3, 5, 10]); // Argument
const tail_prob = torch.special.gammaincc(a, x); // Q(a, x) = 1 - P(a,x)
// Values gradually decrease from ~0.37 to ~0.01// Chi-squared hypothesis test: right-tail p-value
const chi2_stat = 15.3; // Observed test statistic
const df = 6; // Degrees of freedom
const p_value = torch.special.gammaincc(
torch.tensor([df / 2]),
torch.tensor([chi2_stat / 2])
); // Probability of observing worse fit
// P-value = P(χ²(6) > 15.3) ≈ 0.017// Survival analysis: probability of survival beyond time t
const shape = torch.tensor([2.5]); // Weibull/gamma shape
const times = torch.linspace(0, 10, 100); // Time points
const survival = torch.special.gammaincc(shape, times);
// S(t) = P(T > t) = probability surviving beyond time t// Medical study: prognosis prediction
const disease_progression = torch.tensor([1.8]); // Shape parameter (experience-based)
const years_since_diagnosis = torch.tensor([5, 10, 15, 20]); // Time points
const prob_survival = torch.special.gammaincc(disease_progression, years_since_diagnosis);
// Probability of surviving beyond each time pointSee Also
- PyTorch torch.special.gammaincc()
- torch.special.gammainc - Lower incomplete gamma: P(a,x) = 1 - Q(a,x)
- torch.special.ndtr - Normal tail probability (similar role)
- torch.special.erfcx - Scaled complementary error (similar scaling pattern)