Statistical Concepts in nonconform¶
This guide explains the key statistical concepts that underpin nonconform's functionality.
Conformal Inference¶
Conformal inference is a framework for uncertainty quantification that provides valid prediction intervals and p-values without making strong distributional assumptions. In the context of anomaly detection, it allows us to:
- Convert raw anomaly scores into statistically valid p-values
- Control false discovery rates at specified levels
- Provide uncertainty quantification for anomaly detection
Exchangeability¶
The key assumption in conformal inference is exchangeability, which is weaker than independence. Data points are exchangeable if their joint distribution is invariant to permutations. This means:
- The order of the data points doesn't matter
- Each data point is treated equally in the analysis
- The statistical guarantees hold under this assumption
P-values in Anomaly Detection¶
In nonconform, p-values represent the probability of observing a more extreme anomaly score under the null hypothesis (that the point is normal). Specifically:
- Small p-values indicate strong evidence against the null hypothesis
- Large p-values suggest the point is likely normal
- The p-values are valid in the sense that under the null hypothesis, they are stochastically larger than uniform
False Discovery Rate (FDR) Control¶
FDR control is a multiple testing procedure that limits the expected proportion of false discoveries among all discoveries. nonconform implements the Benjamini-Hochberg procedure, which:
- Controls FDR at a specified level α
- Is more powerful than family-wise error rate control
- Provides valid inference even when tests are dependent
How FDR Control Works¶
- Sort p-values in ascending order
- Find the largest p-value that satisfies p(i) ≤ (i/m)α
- Reject all null hypotheses with p-values less than or equal to this threshold
Weighted Conformal p-values¶
When the exchangeability assumption is violated (e.g., due to covariate shift), weighted conformal p-values can be used. These:
- Account for differences between training and test distributions
- Maintain statistical validity under weaker assumptions
- Can improve power in the presence of distributional shifts
Calibration and Validation¶
The calibration process in nonconform involves:
- Splitting the data into training and calibration sets
- Computing nonconformity scores on the calibration set
- Using these scores to calibrate the p-values for new observations
This process ensures that the resulting p-values are valid and can be used for statistical inference.
Statistical Guarantees¶
nonconform provides the following statistical guarantees:
- Marginal Validity: P-values are valid marginally over the calibration set
- FDR Control: The Benjamini-Hochberg procedure controls FDR at the specified level
- Power: The methods are designed to maximize power while maintaining validity
Best Practices¶
For optimal statistical performance:
- Use sufficient calibration data (typically >1000 points)
- Ensure the calibration data is representative of the normal class
- Consider using resampling strategies in low-data regimes
- Use weighted conformal p-values when dealing with distributional shifts
- Validate the exchangeability assumption when possible