glm_gd: Implement gradient descent GLM, constant

Description Usage Arguments Examples

View source: R/glm_gd.R

Description

This function implements gradient descent GLM using both a constant adaptive step size

Usage

1
glm_gd(X, Y, mu_fun, lr, max_n = 25, tol = 1e-10)

Arguments

X

a model matrix, the X variables as columns

Y

a factor vector, the response variable

mu_fun

a function depending on Xbeta, giving the mean of the link function

lr

the learning rate

max_n

max number of iterations (a positive integer)

tol

the difference threshold for which we will exit the algorithm for iterations less than max_n

Examples

1
2
3
4
5
6
7
n <- 5000; p <- 3
beta <- c(-1, 0.2, 0.1)
X <- cbind(1, matrix(rnorm(n*(p-1)), ncol = p-1))
eta <- X %*% beta
lambda <- exp(eta)
y <- stats::rpois(n, lambda = lambda)
beta_hat <- glm_gd(X, y, mu_fun = function(eta) exp(eta), lr=0.00000001, max_n = 100000)

kimgannon/bis557 documentation built on Nov. 25, 2020, 7:09 a.m.