Fit generalized linear models using iterative reweighted least squares (IRLS) with MLX providing the heavy lifting for weighted least squares solves. Final convergence is done at double precision on the cpu.
Usage
mlxs_glm(
formula,
family = mlxs_gaussian(),
data,
subset,
weights,
na.action = stats::na.exclude,
start = NULL,
control = list(),
...
)Arguments
- formula
an object of class
"formula"(or one that can be coerced to that class): a symbolic description of the model to be fitted. The details of model specification are given under ‘Details’.- family
A mlxs family object (e.g.,
mlxs_gaussian(),mlxs_binomial(),mlxs_poisson()). You can use"gaussian"etc.- data
an optional data frame, list or environment (or object coercible by
as.data.frameto a data frame) containing the variables in the model. If not found indata, the variables are taken fromenvironment(formula), typically the environment from whichglmis called.- subset
an optional vector specifying a subset of observations to be used in the fitting process. (See additional details about how this argument interacts with data-dependent bases in the ‘Details’ below.)
- weights
an optional vector of ‘prior weights’ to be used in the fitting process. Should be
NULLor a numeric vector.- na.action
A function indicating how missing values should be handled. Defaults to
stats::na.exclude()so residuals, fitted values, and training-data predictions are padded back to the original row count.- start
starting values for the parameters in the linear predictor.
- control
Optional list of control parameters passed to
mlxs_glm_control(). Control parameters can includeepsilon,epsilon_f64,maxitandtrace.- ...
For
glm: arguments to be used to form the defaultcontrolargument if it is not supplied directly.For
weights: further arguments passed to or from other methods.
Value
An object of class c("mlxs_glm", "mlxs_model") containing elements
similar to the result of stats::glm(). Unlike stats::glm(),
rank-deficient model matrices are rejected rather than fit with aliased
coefficients.
Examples
fit <- mlxs_glm(mpg ~ cyl + disp, family = mlxs_gaussian(), data = mtcars)
coef(fit)
#> (Intercept) cyl disp
#> 34.66099167 -1.58727658 -0.02058364