ml_glm

ml_glm(
    x,
    y,
    intercept=True,
    link='identity',
    local_method='nelder_mead',
    robust_se=False,
    newdata=None,
    alpha=0.1,
)

Generalized linear model.

Mirrors the C# GeneralizedLinearModel class: fits a linear predictor mapped to the response scale by a link function, by maximizing the family log-likelihood with a local optimizer.

The link selects the family as well as the transform: "identity" is Normal, "log" is Poisson, and "logit", "probit" and "complementary_log_log" are Binomial.

local_method accepts all five optimizers here, unlike :func:optim_minimize’s local_method argument (which takes three) – the two upstream classes construct different sets, and this surface follows each one rather than imposing a single list.

Parameters

Name Type Description Default
x array_like Predictors, one row per observation. required
y array_like The response, one value per row of x. required
intercept bool Fit an intercept term. True
link ('identity', 'log', 'logit', 'probit', 'complementary_log_log') The link function, which also selects the family. "identity"
local_method ('nelder_mead', 'bfgs', 'powell', 'adam', 'gradient_descent') The optimizer. "nelder_mead"
robust_se bool Use the sandwich (heteroskedasticity-consistent) covariance rather than the delta-method one. Changes the standard errors, not the coefficients. False
newdata array_like Predictors to predict for. When supplied the result gains prediction and prediction_intervals. None
alpha float The interval level for prediction_intervals: 0.1 gives a 90% interval. 0.1

Returns

Name Type Description
dict coefficients, standard_errors, z_values, p_values, sigma, df, n, aic, aicc, bic, vcov and residuals; plus prediction and prediction_intervals when newdata is supplied. The interval table has three columns in the order lower, mean, upper.

Examples

>>> from corehydropy import ml_glm
>>> x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> y = [2.1, 3.9, 6.2, 7.8, 10.1, 12.2, 13.8, 16.1, 18.0, 20.2]
>>> len(ml_glm(x, y)["coefficients"])
2