models.glm

Generalised linear model (gaussian, binomial, poisson or Gamma) on a table of any size: iteratively reweighted least squares with one streaming pass per iteration, memory independent of the number of rows. It follows R's glm.fit step for step -- starting values, link functions, convergence test, dispersion -- so it fits the model stats.glm fits (tested to agree to 1e-8, with the same iteration count), and writes the same glm model for models.predict.

Nesting (/, %in%) and cross-validation are not offered; use stats.glm for tables that fit in memory and need them. A model that does not converge within max_iter fails.

  • Kind: standard
  • Network: no

Inputs🔗

NameTypeDescription
datafile (Parquet or CSV)Training table: one row per observation, with the target, the predictor columns, and any weights or id columns.
formulastringModel formula, e.g. ESTIMATE ~ B5 + log(B25) + FORTYPE + 0. Use instead of target and features. Default empty.
targetstringThe response column (when no formula is given). Default empty.
featuresstringColumn selector for the predictors (when no formula is given): names, globs and exclusions, e.g. B*,MB*,-B0. Default empty.
interceptbooleanInclude an intercept when building the model from target and features. With a formula, write + 0 in the formula instead. Default true.
distributionstringResponse distribution: gaussian (default), binomial (0/1, TRUE/FALSE or a proportion with the number of trials as weights), poisson (counts) or Gamma (positive values).
linkstringLink function: canonical (default; the distribution's own), identity, log, logit or inverse. Supported: gaussian identity/log/inverse, binomial logit, poisson log/identity, Gamma inverse/log/identity.
id_columnsstringColumn selector for identifier columns, never used as predictors; kept as text when reading CSV. Default empty.
weightsstringColumn of non-negative observation weights. Empty fits unweighted.
categoricalstringColumn selector for predictors to treat as categorical even though they are stored as numbers. Default empty.
na_actionstringfail (default, naming the columns) or drop: what to do with a row that has a missing value in a model column.
max_iternumberMaximum IRLS iterations; a model that has not converged fails. Default 25.

Outputs🔗

NameTypeDescription
modelfile (SpadeModel)The fitted model (family glm), for models.predict.
coefficientsfile (CSV)One row per design column: term, estimate, std_error, statistic, p_value.
fitjsonRows used and dropped, the arguments that shaped the fit, and metrics: rmse and mae on the response scale, deviance, null_deviance, aic, bic, dispersion, df_residual, iterations.

Example🔗

- id: "@counts"
  name: models.glm
  inputs:
    - "@plots"
  args:
    formula: "stem_count ~ elevation + forest_type"
    distribution: "poisson"