glam {glam}R Documentation

Generalized Linear/Additive Model (GLAM)

Description

glam fits Generalized Linear Models (GLMs) and Generalized Additive Models (GAMs).

Usage

glam(x, y, model, family, intercept = TRUE, tol = 1e-08, max_iter = 100)

Arguments

x

a matrix with covariate data.

y

a vector of responses.

model

a string stating whether a GLM ("linear") or GAM ("additive") should be fit.

family

the distributional family from which to model response. Options are "beta", "binomial" (GLM only), "poisson", and "gamma".

intercept

a logical indicating whether an intercept is desired. Only applicable when model = "linear". Default is TRUE.

tol

the tolerance for convergence. Must be positive. Default is 1e-8.

max_iter

an integer specifying the maximum number of allowed iterations. Default is 100.

Details

This is a function for training and fitting Generalized Linear Models (GLMs) and Generalized Additive Models (GAMs). It implements these models using Iterative Reweighted Least Squares (IRLS) described in Hastie and Tibshirani 1990 (doi:10.1214/ss/1177013604). This function supports Beta regression, Logistic regression, Poisson regression, and Gamma regression (Logistic GAMs are currently not supported).

Value

The output is a list containing:

eta a vector of un-transformed fitted values.
mu a vector of transformed fitted values.
num_iter the number of iterations until convergence or timeout.
dev the convergence criteria achieved at the end.
coef a numeric vector of estimated coefficients (only applicable when model = "linear").

Examples

# generate random inputs
set.seed(10)
n <- 200
X <- sort(runif(n))
# Beta GLM vs. GAM
Y <- (X - 0.5)^2 + 0.5 + rnorm(n, sd = 1e-1)
beta_glm <- glam(cbind(X, X^2), Y, model = "linear", family = "beta")
beta_gam <- glam(cbind(X, X^2), Y, model = "additive", family = "beta")
plot(X, Y, pch = 20, xlab = "X", ylab = "Y", main = "Beta Regression Example")
lines(X, beta_glm$mu, col = "red", lwd = 2)
lines(X, beta_gam$mu, col = "blue", lwd = 2)
legend("bottomright", legend = c("GLM", "GAM"), col = c("red", "blue"), lwd = 2)

[Package glam version 1.0.2 Index]