smooth_variance

smooth_variance(
    data,
    *,
    x,
    variance=None,
    se=None,
    df=None,
    method='gamma',
    name='variance_smoothed',
    diagnostics=False,
)

Return data with a column of smoothed variances, one row per domain.

Domains with a zero or missing variance are predicted, not fitted.

Parameters

Name Type Description Default
data pl.DataFrame One row per domain, with the direct variance or standard error and the covariates of the variance model. required
x str | Sequence[str] Covariates of the variance model. required
variance str | None Column of direct variances, or of standard errors; give exactly one. None
se str | None Column of direct variances, or of standard errors; give exactly one. None
df str | None Column of degrees of freedom, used as precision weights. Pass it when some domains have df = 0: they are then left out of the fit, while their variance, ~1e-25 rather than 0, would otherwise be fitted. None
method Literal['gamma', 'loglinear', 'loglinear_ratio'] “gamma”, a Gamma GLM with log link, so E[v] = exp(z’a) needs no correction; “loglinear”, OLS on log v back-transformed as exp(z’a), the median; “loglinear_ratio” scales that by sum(v) / sum(exp(z’a)) (Rivest and Belmonte 2000). 'gamma'
name str Name of the new column. 'variance_smoothed'
diagnostics bool Also return name_leverage, each domain’s hat value, and name_loo, its smoothed variance refitted without it: one refit per fitted domain. False