View source: R/first_order_glm.R
first_order_GLM | R Documentation |
This is a function taking X, y and required parameters, and using gradient descent to fit a GLM
first_order_GLM(
X,
y,
family,
lr = "constant",
gamma = 1e-04,
iter = 1e+05,
tol = 1e-15,
decay = 0
)
X |
numeric data matrix |
y |
response vector |
family |
the family of GLM |
lr |
adaptive or constant learning rate, input "step" or "constant", default is constant |
gamma |
gamma_k, the starting learning rate, default is 0.0001 |
iter |
max number of iterations, default is 1e5 |
tol |
tolerance, default is 1e-15 |
decay |
step decay rate if chosen step for lr, default is 0.00 |
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)
first_order_GLM(X,y,family = poisson(link = "log"), lr = "constant")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.