glm_new: glm_new() function

Description Usage Arguments Examples

View source: R/glm_new.R

Description

another way to build a generalized linear model using only gradient information

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
glm_new(
  X,
  y,
  mu_fun,
  var_fun,
  itr = 50,
  step,
  method,
  friction,
  tolerance = 1e-10
)

Arguments

X

a data matrix used for the function

y

a vector of response values

mu_fun

expectation function of the distribution

var_fun

variance function of the distribution

itr

number of iteration

step

learning rate for gradient descent

method

constant step size or momentum update

friction

a number to control the velocity and prevents overshooting

tolerance

allowed tolerance for two residuals

Examples

1
2
3
 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 <- rpois(n, lambda = lambda)
   fit_linear_model <- glm_new(X, y, mu_fun = function(eta) exp(eta), var_fun = identity, step = 0.0001, method = "constant")

Yannuo10/bis557 documentation built on Dec. 21, 2020, 10:02 p.m.