Fit a Univariate GLM Without Intercept Using IRLS
Source:R/Rinternal.R
univariate_irls_glm_no_intercept.RdFits a generalized linear model (GLM) using a single covariate and no intercept term via the iteratively reweighted least squares (IRLS) algorithm.
Arguments
- x
Numeric vector of length
n: predictor values.- y
Numeric vector of length
n: response values.- family
An R
familyobject, such asbinomial(),poisson(), orgaussian().- offset
Numeric vector of length 1 or
n, default0. Optional offset in the linear predictor.- max_iter
Integer. Maximum number of IRLS iterations (default = 25).
- tol
Numeric. Convergence tolerance (default = 1e-8).
Details
The linear predictor is defined as: $$\eta = \theta \cdot x + \mathrm{offset}$$ where \(g(\mu) = \eta\) is the canonical link function from the specified GLM family.
The function uses R's family object (e.g., binomial(), poisson(), gaussian())
to evaluate the inverse link, variance, and derivative functions at each iteration.
Numerical safeguards are included:
The linear predictor
etais clamped for Poisson models to prevent overflow.Variance and derivative evaluations are floored to avoid division by zero.
Extremely large weights are capped.