class

FisherSnedecor

extendsDistribution
FisherSnedecor(df1: Tensor | float, df2: Tensor | float, validate_args: bool | None = None)
source

Fisher-Snedecor F-distribution — ratio of two scaled Chi-squared variates.

FisherSnedecor(df1=d1, df2=d2) is the distribution of the statistic

F=X/d1Y/d2F = \frac{X / d_1}{Y / d_2}

where Xχ2(d1)X \sim \chi^2(d_1) and Yχ2(d2)Y \sim \chi^2(d_2) are independent. The F-distribution is foundational in classical statistics: it arises in ANOVA F-tests and in the likelihood-ratio test for comparing nested linear models.

Parameters

df1Tensor | float
Numerator degrees of freedom d1>0d_1 > 0.
df2Tensor | float
Denominator degrees of freedom d2>0d_2 > 0.
validate_argsbool | None= None
If True, validate parameter constraints at construction time.

Attributes

df1Tensor
Numerator degrees of freedom d1d_1.
df2Tensor
Denominator degrees of freedom d2d_2.

Notes

PDF:

p(x;d1,d2)=1xB(d1/2,d2/2)(d1xd1x+d2)d1/2(d2d1x+d2)d2/2,x>0p(x; d_1, d_2) = \frac{1}{x \, B(d_1/2,\, d_2/2)} \left(\frac{d_1 x}{d_1 x + d_2}\right)^{d_1/2} \left(\frac{d_2}{d_1 x + d_2}\right)^{d_2/2}, \quad x > 0

Log-PDF (stable form using lgamma):

logp(x)=d12log(d1x)+d22logd2d1+d22log(d1x+d2)logxlogB(d1/2,d2/2)\log p(x) = \frac{d_1}{2}\log(d_1 x) + \frac{d_2}{2}\log d_2 - \frac{d_1+d_2}{2}\log(d_1 x + d_2) - \log x - \log B(d_1/2, d_2/2)

Moments (when defined):

  • Mean (d2>2d_2 > 2): E[X]=d2/(d22)E[X] = d_2 / (d_2 - 2)
  • Variance (d2>4d_2 > 4): Var[X]=2d22(d1+d22)/[d1(d22)2(d24)]\operatorname{Var}[X] = 2 d_2^2 (d_1 + d_2 - 2) / [d_1 (d_2 - 2)^2 (d_2 - 4)]

Sampling draws one χ2(d1)\chi^2(d_1) and one χ2(d2)\chi^2(d_2) sample and forms the ratio. Both χ2\chi^2 samples are drawn via the Gamma sampler.

Examples

>>> import lucid
>>> from lucid.distributions import FisherSnedecor
>>> dist = FisherSnedecor(df1=5.0, df2=10.0)
>>> samples = dist.sample((100,))
>>> dist.mean  # d2/(d2-2) = 10/8 = 1.25

Methods (5)

dunder

__init__

None
__init__(df1: Tensor | float, df2: Tensor | float, validate_args: bool | None = None)
source

Initialise a Fisher-Snedecor F-distribution.

Parameters

df1Tensor | float
Numerator degrees of freedom d1>0d_1 > 0.
df2Tensor | float
Denominator degrees of freedom d2>0d_2 > 0.
validate_argsbool | None= None
If True, validate parameter constraints at construction time.
prop

mean

Tensor
mean: Tensor
source

Mean of the F-distribution: E[X]=d2/(d22)E[X] = d_2 / (d_2 - 2).

Defined only for d2>2d_2 > 2; returns inf or nan otherwise.

Returns

Tensor

Mean values of shape batch_shape.

prop

variance

Tensor
variance: Tensor
source

Variance of the F-distribution.

Var[X]=2d22(d1+d22)/[d1(d22)2(d24)]\operatorname{Var}[X] = 2 d_2^2 (d_1 + d_2 - 2) / [d_1 (d_2 - 2)^2 (d_2 - 4)]

Defined only for d2>4d_2 > 4.

Returns

Tensor

Variance values of shape batch_shape.

fn

sample

Tensor
sample(sample_shape: tuple[int, ...] = ())
source

Draw samples from the F-distribution.

Forms the ratio F=(X/d1)/(Y/d2)F = (X/d_1) / (Y/d_2) where Xχ2(d1)X \sim \chi^2(d_1) and Yχ2(d2)Y \sim \chi^2(d_2) are independent samples drawn via the Gamma sampler.

Parameters

sample_shapetuple[int, ...]= ()
Leading shape of the output sample batch.

Returns

Tensor

Positive samples of shape (*sample_shape, *batch_shape).

fn

log_prob

Tensor
log_prob(value: Tensor)
source

Log-probability density of the F-distribution.

logp(x)=d12log(d1x)+d22logd2d1+d22log(d1x+d2)logxlogB(d1/2,d2/2)\log p(x) = \frac{d_1}{2}\log(d_1 x) + \frac{d_2}{2}\log d_2 - \frac{d_1+d_2}{2}\log(d_1 x + d_2) - \log x - \log B(d_1/2, d_2/2)

Parameters

valueTensor
Positive points x>0x > 0 at which to evaluate the density.

Returns

Tensor

Log-density values of the same shape as value.