Description Usage Arguments Examples
This is a simple algorithm to solve a generalized linear regression model.
1 2 3 4 5 6 7 8 9 10 |
X |
design matrix |
Y |
a vector of outcome |
family |
an R 'family' object. |
step_option |
a character string of "constant" or "momentum", if "momentum", then gamma should be specified |
lambda |
a numeric number indicating the learning rate for gradient descent algorithm |
gamma |
a fraction for momentum step size |
maxit |
an integer indicating the maximum number iterations |
tol |
a numeric number indicating the precision of the algorithm |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | n <- 1000; p <- 3
beta <- c(0.2, 2, 1)
X <- cbind(1, matrix(rnorm(n * (p-1)), ncol = (p-1) ))
mu <- 1 - pcauchy(X %*% beta)
Y <- as.numeric(runif(n) > mu)
df <- as.data.frame(cbind(Y, X))
fit0 <- glm(Y ~ . -1, data = df, family = binomial(link = "cauchit"))
fit1 <- my_glm(X, Y, family = binomial(link = "cauchit"),
step_option = "constant", lambda = 0.001)
fit2 <- my_glm(X, Y, family = binomial(link = "cauchit"),
step_option = "momentum", lambda = 0.001, gamma = 0.2)
cbind(fit0$coefficients, fit1$coefficients, fit2$coefficients)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.