mixle.ppl.regression module¶
Regression / GLMs for mixle.ppl.
A linear predictor in a parameter slot makes a model a regression; the outer family sets the link:
Normal(a*Field(“x”) + b, sigma) identity link -> linear regression Bernoulli(a*Field(“x”) + b) logit link -> logistic regression Poisson(a*Field(“x”) + b) log link -> Poisson regression
Coefficients may be free or may carry Normal penalty handles. Fitting is
IRLS/Fisher scoring for a likelihood or penalized-likelihood point estimate.
For Normal responses a Normal coefficient prior is scaled by the residual
variance (the fixed sigma, or the working sigma^2 when it is free), so
result.beta / result.cov are the exact Gaussian posterior mean and
covariance at that plug-in scale. Non-Gaussian GLM families (Bernoulli /
Poisson) have unit dispersion, so the prior enters the IRLS equations
unscaled – the exact penalized-likelihood (MAP) mode. Fit with
.fit(y, given={"x": xs}).
- class RegressionResult(names, idx_of, beta, cov, sigma, columns, link='identity', *, converged=True, iterations=1, termination_reason='closed_form', objective_delta=0.0, loglik=None, n_params=None, nobs=None)[source]
Bases:
objectRegression point estimate with coefficient curvature diagnostics.
- samples(param=None, n=4000, rng=None)[source]
Draw from the Gaussian coefficient approximation represented by
betaandcov.- Parameters:
n (int)
- predict(given, *, n=None, rng=None)[source]
Predict the response mean at covariates
given(dict of arrays): the fitted value through the link (probabilities for logistic, rates for Poisson, mean for linear). Withn, returnsndraws of the fitted mean under the Gaussian coefficient approximation; observation noise is not added.
- summary()[source]
Return coefficient summaries and residual scale metadata.
- to_exponential_family(engine=None)[source]
Return the conditional exponential-family view
p(y|x)for a canonical link.For a canonical link the linear predictor is the natural parameter:
eta(x) = offset + X @ betais the logit (Bernoulli) / log-rate (Poisson) directly, and the meanmu(x)/sigma^2paired with-1/(2 sigma^2)for the Normal. The returnedConditionalExponentialFamilyFormexposesnatural_parameters(x),sufficient_statistics(y),log_partition,log_base_measure(y),mean(x)(the inverse link ==predict()), andlog_density(y, x).
- predict_at(fitted, given, rng)[source]
One predictive draw per row of
givenfrom a fitted regression.A fitted regression’s law depends on its covariates, so there is no single distribution to draw from and
predict(n)had nothing to do: a caller who passed the covariates instead got “predictive sample count must be an exact positive integer” and one who passed a count got a NotImplementedError about the missing lowering (P08-F15). Draws are from the fitted conditional at each row – the plug-in predictive, the same onepredictgives a point fit.
- class LMMResult(names, beta, cov, Sigma, sigma, b, group_levels, re_names, *, converged, iterations, objective_delta, loglik=None, n_params=None, nobs=None)[source]
Bases:
objectLinear mixed model: fixed-effect coefficients + variance components + group effects.
- summary()[source]
Return fixed effects, random-effects covariance, scale, and group count.
- class GLMMResult(family, link, names, beta, cov, Sigma, b, group_levels, re_names, *, converged, outer_iterations, inner_iterations, inner_converged, objective_delta)[source]
Bases:
objectGeneralized linear mixed model: fixed-effect coefficients (on the link scale) + the random-effects covariance + per-group effects. No residual scale (the family sets dispersion).
- summary()[source]
Return fixed effects, random-effects covariance, link, and group count.
- class LocationScaleResult(family, names_m, names_s, beta, cov, spec_m, spec_s, *, iterations, objective_delta, termination_reason)[source]
Bases:
objectHeteroskedastic (location-scale) regression: separate mean and log-scale coefficients.
The scale follows a log link,
scale = exp(eta_scale), so the dispersion can vary with covariates (Normal(mean_pred, free*Field("x") + free)).predictreturns per-rowlocandscale.- predict(given, **_)[source]
Return
{'loc': array, 'scale': array}at covariatesgiven.
- summary()[source]
Return separate coefficient summaries for location and scale predictors.
- regression_fit(rv, data, *, given=None, how='auto', max_iter=100, inner_max_iter=100, tol=1e-9, quantile=None, l2=0.0, **unknown)[source]
Fit a PPL regression expression using the appropriate linear-model route.