glm_firstorder: First-Order Method of Generalized Linear Model

Description Usage Arguments Value Examples

View source: R/glm-firstorder.R

Description

This function gives a first-order solution for the GLM maximum likelihood problem using only gradient information, avoiding the Hessian matrix. A comparison of a constant step size and an adaptive one is also included.

Usage

1
2
glm_firstorder(form, data, mu_fun, step = "constant", gamma = 1e-06,
  maxit = 1000, tol = 1e-06)

Arguments

form

a formula with the legal format.

data

a dataframe provided by the user.

mu_fun

a specified link function inverse.

step

indicate method, constant or momentum step.

gamma

the learning rate.

maxit

the maximum number of iterations.

tol

the tolerance of the squared difference of beta to show convergence.

data

a dataframe provided by the user.

Value

a list including the coefficient estimates.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
set.seed(1713948)
n <- 1000
truth <- c(4, 0.5, 0.3, 1)
X <- cbind(rep(1,n), matrix(rnorm(3*n), ncol=3))
lambda <- exp(X %*% truth)
Y <- rpois(n, lambda=lambda)
covs <- X[,-1]
q2.data <- data.frame(cbind(Y, covs))
form <- Y ~ .
glm_firstorder(form, q2.data, step="momentum", mu_fun=function(eta) exp(eta))$beta

BillyTian/bis557 documentation built on Dec. 19, 2020, 7:30 a.m.