Description Usage Arguments Value Examples
Fit a generalized linear model via penalized maximum likelihood. Fits linear and logistic regression models, with elastic net or isotonic regularization.
1 2 3 |
x |
The input matrix, each row is a sample, each column a feature. |
y |
The response variable. Quantitative for |
family |
The response type. For |
penalty |
The penalty type. |
lambda |
The scaling of the penalty (default |
intercept |
Should intercept(s) be fitted (default= |
opts |
List of parameters, which must include: |
toto
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | n <- 100
p <- 5
x <- matrix(rnorm(n*p),n,p)
y <- rbinom(n,1,0.5)*2-1
lambda <- 0.2*max(abs(crossprod(y,x)))/n
# Lasso regression with intercept:
m <- glm.apg(x, y, lambda=lambda)
# same as
library(glmnet)
m2 <- glmnet(x, y, standardize=FALSE, lambda=lambda)
# Ridge regression with intercept:
m <- glm.apg(x, y, lambda=lambda, opts=list(alpha=0))
# Does the same as
m2 <- glmnet(x, y, standardize=FALSE, lambda=lambda, alpha=0)
# Elastic net regression with intercept:
m <- glm.apg(x, y, lambda=lambda, opts=list(alpha=0.5))
# Does the same as
m2 <- glmnet(x, y, standardize=FALSE, lambda=lambda, alpha=0.5)
# Elastic net regression without intercept:
m <- glm.apg(x, y, lambda=lambda, intercept=FALSE, opts=list(alpha=0.5))
# Does the same as
m2 <- glmnet(x, y, standardize=FALSE, lambda=lambda, alpha=0.5, intercept=FALSE)
# Lasso penalized logistic regression with intercept:
m <- glm.apg(x, y, family="binomial", lambda=lambda)
# Does the same as
m2 <- glmnet(x, y, family="binomial", lambda=lambda, standardize=FALSE)
# Elastic net penalized logistic regression with intercept:
m <- glm.apg(x, y, family="binomial", lambda=lambda, opts=list(alpha=0.5))
# Does the same as
m2 <- glmnet(x, y, family="binomial", lambda=lambda, standardize=FALSE, alpha=0.5)
# Isotonic regression with offset
m <- glm.apg(x, y, penalty="isotonic", lambda=lambda)
# Isotonic logistic regression with offset
m <- glm.apg(x, y, family="binomial", penalty="isotonic", lambda=lambda)
# Isotonic logistic regression with offset, with non-decreasing model of bounded norm
m <- glm.apg(x, y, family="binomial", penalty="boundednondecreasing", lambda=lambda, opts=list(maxnorm=2))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.