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 this module uses the ridge/penalized-least-squares convention documented in the book and reports a scale-adjusted inverse-curvature diagnostic; it is not a full Gaussian-prior posterior unless the likelihood and prior precisions are scaled consistently. Fit with .fit(y, given={"x": xs}).

class RegressionResult(names, idx_of, beta, cov, sigma, columns, link='identity')[source]

Bases: object

Regression point estimate with coefficient curvature diagnostics.

samples(param=None, n=4000, rng=None)[source]

Draw from the Gaussian coefficient approximation represented by beta and cov.

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). With n, returns n draws of the fitted mean under the Gaussian coefficient approximation; observation noise is not added.

summary()[source]
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 @ beta is the logit (Bernoulli) / log-rate (Poisson) directly, and the mean mu(x)/sigma^2 paired with -1/(2 sigma^2) for the Normal. The returned ConditionalExponentialFamilyForm exposes natural_parameters(x), sufficient_statistics(y), log_partition, log_base_measure(y), mean(x) (the inverse link == predict()), and log_density(y, x).

class LMMResult(names, beta, cov, Sigma, sigma, b, group_levels, re_names)[source]

Bases: object

Linear mixed model: fixed-effect coefficients + variance components + group effects.

summary()[source]
class GLMMResult(family, link, names, beta, cov, Sigma, b, group_levels, re_names)[source]

Bases: object

Generalized 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]
class LocationScaleResult(family, names_m, names_s, beta, cov, spec_m, spec_s)[source]

Bases: object

Heteroskedastic (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)). predict returns per-row loc and scale.

predict(given, **_)[source]

Return {'loc': array, 'scale': array} at covariates given.

summary()[source]
regression_fit(rv, data, *, given=None, max_iter=100, tol=1e-9, quantile=None, l2=0.0, **_)[source]
Parameters:
  • rv (RandomVariable)

  • max_iter (int)

  • tol (float)

Return type:

RandomVariable