glm.apg: Fit a generalized linear model with various regularizations.

Description Usage Arguments Value Examples

Description

Fit a generalized linear model via penalized maximum likelihood. Fits linear and logistic regression models, with elastic net or isotonic regularization.

Usage

1
2
3
glm.apg(x, y, family = c("gaussian", "binomial", "survival"),
  penalty = c("elasticnet", "isotonic", "boundednondecreasing"), lambda = 1,
  intercept = TRUE, opts = list())

Arguments

x

The input matrix, each row is a sample, each column a feature.

y

The response variable. Quantitative for family="gaussian", binary with values +1 and -1 for family="binomial", survival data with two columes (follow-up time and event) for family="survival"

family

The response type. For family="gaussian", ...

penalty

The penalty type.

lambda

The scaling of the penalty (default 1)

intercept

Should intercept(s) be fitted (default=TRUE) or set to zero (FALSE)

opts

List of parameters, which must include:

Value

toto

Examples

 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))

jpvert/apg documentation built on May 19, 2019, 11:51 p.m.