Title: | Generalized Additive and Linear Models (GLAM) |
---|---|
Description: | Contains methods for fitting Generalized Linear Models (GLMs) and Generalized Additive Models (GAMs). Generalized regression models are common methods for handling data for which assuming Gaussian-distributed errors is not appropriate. For instance, if the response of interest is binary, count, or proportion data, one can instead model the expectation of the response based on an appropriate data-generating distribution. This package provides methods for fitting GLMs and GAMs under Beta regression, Poisson regression, Gamma regression, and Binomial regression (currently GLM only) settings. Models are fit using local scoring algorithms described in Hastie and Tibshirani (1990) <doi:10.1214/ss/1177013604>. |
Authors: | Andrew Cooper [aut, cre, cph] |
Maintainer: | Andrew Cooper <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.0.2 |
Built: | 2024-11-08 04:28:04 UTC |
Source: | https://github.com/cran/glam |
glam
fits Generalized Linear Models (GLMs) and Generalized Additive Models (GAMs).
glam(x, y, model, family, intercept = TRUE, tol = 1e-08, max_iter = 100)
glam(x, y, model, family, intercept = TRUE, tol = 1e-08, max_iter = 100)
x |
a |
y |
a |
model |
a string stating whether a GLM ( |
family |
the distributional family from which to model response. Options are
|
intercept |
a |
tol |
the tolerance for convergence. Must be positive. Default is |
max_iter |
an |
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).
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" ). |
# 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)
# 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)