Description Usage Arguments Value Examples
View source: R/glm-firstorder.R
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.
1 2 | glm_firstorder(form, data, mu_fun, step = "constant", gamma = 1e-06,
maxit = 1000, tol = 1e-06)
|
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. |
a list including the coefficient estimates.
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
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.