glm_hw3b: GLM Using First-Order Gradient Descent

Description Usage Arguments Value Examples

View source: R/glm_hw3b.R

Description

This function solves generalized linear models using only first-order conditions, avoiding the Hessian matrix. This uses the gradient descent algorithm, with either a constant or adaptive step size.

Usage

1
glm_hw3b(X, y, family, steps, maxiter = 1000, tol = 1e-12)

Arguments

X

Numeric (continuous or categorical) data matrix

y

Response/Target vector

family

Error distribution and link function, such as poisson or Gamma

steps

Step size for each iteration

maxiter

Maximum number of iterations

tol

Tolerance

Value

Estimated beta coefficients

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
set.seed(2020)
n <- 3000; p <- 4; maxiter <- 500; steps <- rep(1e-3, maxiter)
X <- cbind(1, matrix(rnorm(n * (p-1)), ncol = p-1))
beta <- c(-1, 0.2, 0.1, 0.3)
y <- rpois(n, lambda = exp(X %*% beta))
glm_hw3b(X, y, family = poisson(link = "log"), steps, maxiter)

set.seed(2020)
steps2 <- 5e-3/(1:maxiter)
glm_hw3b(X, y, family = poisson(link = "log"), steps = steps2, maxiter)

brian-d1018/bis557 documentation built on Dec. 17, 2020, 6:21 p.m.