Description Usage Arguments Value Examples
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.
1 |
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 |
Estimated beta coefficients
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.