torch.distributions.FisherSnedecor
class FisherSnedecor extends Distributionnew FisherSnedecor(df1: number | Tensor, df2: number | Tensor, options?: DistributionOptions)
- readonly
df1(Tensor) - – First degrees of freedom parameter.
- readonly
df2(Tensor) - – Second degrees of freedom parameter.
- readonly
arg_constraints(unknown) - readonly
support(unknown) - readonly
has_rsample(unknown) - readonly
mean(Tensor) - readonly
mode(Tensor) - readonly
variance(Tensor)
Fisher-Snedecor (F) distribution: ratio of two independent chi-squared distributions.
Parameterized by two degrees of freedom parameters: df1 (numerator) and df2 (denominator). If U ~ Chi2(df1) and V ~ Chi2(df2) are independent, then F = (U/df1)/(V/df2) ~ F(df1, df2). Fundamental to hypothesis testing, ANOVA, and variance comparison. Essential for:
- Analysis of variance (ANOVA) for comparing group means
- F-tests for equality of variances across samples
- Linear regression hypothesis testing and model comparison
- Testing if one variance is significantly larger than another
- Quality control and process capability analysis
- Comparing nested models (e.g., model reduction testing)
- Repeated measures ANOVA and mixed-effects models
- Welch's test and other robust variance ratio tests
Geometric Interpretation: F = (variance of numerator model) / (variance of denominator model). Large F values indicate the numerator is more variable than denominator (reject null hypothesis).
Relationship to Chi2: F(df1, df2) = (Chi2(df1)/df1) / (Chi2(df2)/df2). This mixture of two chi-squared distributions (divided by their df) creates the F-distribution.
- Mean undefined if df2 ≤ 2: Only defined for df2 2; df2 ≤ 2 gives undefined mean
- Variance undefined if df2 ≤ 4: Variance only exists for df2 4
- Always positive support: F-statistic is always positive, ratio of positive values
- Right-skewed: Longer right tail; mode mean for reasonable df values
- Reciprocal property: If X ~ F(df1, df2), then 1/X ~ F(df2, df1)
- Chi2 ratio: F(df1, df2) = (Chi2(df1)/df1) / (Chi2(df2)/df2)
- Heavy tail with small df: Smaller degrees of freedom → heavier tails
- df1, df2 must be positive: df1 ≤ 0 or df2 ≤ 0 causes errors
- Mean undefined for df2 ≤ 2: Distribution has infinite mean in this case
- Variance undefined for df2 ≤ 4: Variance doesn't exist unless df2 4
- Large F values test model differences: Very large F statistic → strong evidence against null
Examples
// Simple F-test: compare variance of two samples
// Sample 1 has df1=10 degrees of freedom, Sample 2 has df2=15
const f_test = new torch.distributions.FisherSnedecor(10, 15);
const critical_value = f_test.icdf(torch.tensor([0.95])); // 95% quantile
// If computed F-statistic > critical_value, reject null hypothesis at 5% level
//
// ANOVA: test if group means differ (F-test for model fit)
// Between-groups chi-squared has df1 = num_groups - 1
// Within-groups chi-squared has df2 = num_samples - num_groups
const num_groups = 4;
const num_samples = 50;
const anova_dist = new torch.distributions.FisherSnedecor(
num_groups - 1, // df1 = 3
num_samples - num_groups // df2 = 46
);
const f_critical = anova_dist.icdf(torch.tensor([0.95])); // critical F value
// If F_computed > f_critical, reject null (group means differ)
//
// Linear regression: test if adding predictor helps (nested models)
// Full model has more parameters, reduced model has fewer
// F = (SS_reduced - SS_full)/p_diff / (SS_full/(n - p_full))
const p_diff = 3; // number of parameters added
const n_residual = 100 - 10; // residual df of full model
const model_test = new torch.distributions.FisherSnedecor(p_diff, n_residual);
const p_value = 1 - model_test.cdf(torch.tensor([f_stat])); // compute p-value
//
// Batched F-tests with different degrees of freedom
const df1_values = torch.tensor([1, 3, 5, 10]);
const df2_values = torch.tensor([10, 15, 20, 30]);
const dist = new torch.distributions.FisherSnedecor(df1_values, df2_values);
const critical_vals = dist.icdf(torch.tensor([0.95])); // [4] shaped critical values
const samples = dist.sample(); // [4] shaped F-statistics
// Distribution characteristics: higher df1 → more concentrated; higher df2 → lower mean
const narrow = new torch.distributions.FisherSnedecor(100, 100); // both large
const narrow_mean = narrow.mean; // ≈ 1.04 (very concentrated)
const wide = new torch.distributions.FisherSnedecor(1, 1); // both small
// wide distribution has very heavy tail, mean undefined
// Reciprocal property: F(df1, df2) reciprocal ~ F(df2, df1)
const f1 = new torch.distributions.FisherSnedecor(5, 10);
const f_reciprocal = f1.icdf(torch.tensor([0.95]));
// Should match approximately with F(10, 5) at 5% quantile