glmPenaltyFit: Fit the generalized linear model with a vector of penalty...

Description Usage Arguments Examples

View source: R/elnglm.R

Description

Fit the generalized linear model with a vector of penalty parameters.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
glmPenaltyFit(
  y,
  x,
  family = c("gaussian", "binomial", "multinomial"),
  lambdaLength = 100L,
  minLambdaRatio = 0.001,
  lambdaVec = NULL,
  alpha = 0.5,
  standardize = TRUE,
  maxit = 100L,
  tol = 1e-04,
  ver = c("r", "arma")
)

Arguments

y

the vector of the response variable.

x

the matrix of the predictors.

family

string. One of the response families, "gaussian", "binomial" or "multinomial".

lambdaLength

integer. The number of tuning penalty parameters. The default is 100.

minLambdaRatio

double. The ratio of the minimal value to the maximal value of the penalty parameter. The default is 1e-3.

lambdaVec

vector. The optional input of the tuning penalty parameters. The default is NULL that the function automatically computes the maximal value of the penalty parameter and generates a sequence of penalty parameter values of length lambdaLength.

alpha

double. The elastic net parameter between 0 and 1. The default value is 0.5.

standardize

boolean. If TRUE, the function first standardizes the predictor matrix.

maxit

integer. The number of maximal iterations of the coordinate descent algorithm. The default is 100.

tol

double. The value of the convergence tolerance of the coordinate descent algorithm. The default is 1e-4.

ver

string. The version of the coordinate descent engine, "r": R codes or "arma": C++ codes with armadillo library.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# Generate data of continuous response
trueb0 <- 1
trueact <- c(1, 1, 1, 0, 0, 0, 0, 0, 0, 0)
trueb <- runif(10, -1, 1)*10
trueb[which(trueact == 0)] <- 0 
df <- glmDataGen(n = 500, d = 10, family = "gaussian", trueb0, trueb, s = 0.5, seed = 1)

# Run cross-validation
mdl <- glmPenaltyFit(y = df$y, x = df$x, family = "gaussian", lambdaLength = 100,
                     minLambdaRatio = 1e-3, maxit = 1e5, tol = 1e-7, alpha = 0.5, ver = "arma")
# Estimated intercept of the best model
print(mdl$b0)
# Estimated coefficients of the best model
print(mdl$b)

PingYangChen/elnglm documentation built on Jan. 6, 2022, 5:50 a.m.