Skip to contents

Fits 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 family object, such as binomial(), poisson(), or gaussian().

offset

Numeric vector of length 1 or n, default 0. Optional offset in the linear predictor.

max_iter

Integer. Maximum number of IRLS iterations (default = 25).

tol

Numeric. Convergence tolerance (default = 1e-8).

Value

Numeric scalar: estimated slope \(\theta\).

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 eta is clamped for Poisson models to prevent overflow.

  • Variance and derivative evaluations are floored to avoid division by zero.

  • Extremely large weights are capped.

Examples

if (FALSE) { # \dontrun{
x <- rnorm(100)
y <- rbinom(100, 1, plogis(2 * x))
univariate_irls_glm_no_intercept(x, y, family = binomial())

x <- rnorm(100)
y <- 1 + 3 * x + rnorm(100)
univariate_irls_glm_no_intercept(x, y, family = gaussian())
} # }