# NOT RUN {
## Use the Logistic Group Lasso on the splice data set
data(splice)
## Define a list with the contrasts of the factors
contr <- rep(list("contr.sum"), ncol(splice) - 1)
names(contr) <- names(splice)[-1]
## Fit a logistic model
fit.splice <- grplasso(y ~ ., data = splice, model = LogReg(), lambda = 20,
contrasts = contr, center = TRUE, standardize = TRUE)
## Perform the Logistic Group Lasso on a random dataset
set.seed(79)
n <- 50 ## observations
p <- 4 ## variables
## First variable (intercept) not penalized, two groups having 2 degrees
## of freedom each
index <- c(NA, 2, 2, 3, 3)
## Create a random design matrix, including the intercept (first column)
x <- cbind(1, matrix(rnorm(p * n), nrow = n))
colnames(x) <- c("Intercept", paste("X", 1:4, sep = ""))
par <- c(0, 2.1, -1.8, 0, 0)
prob <- 1 / (1 + exp(-x %*% par))
mean(pmin(prob, 1 - prob)) ## Bayes risk
y <- rbinom(n, size = 1, prob = prob) ## binary response vector
## Use a multiplicative grid for the penalty parameter lambda, starting
## at the maximal lambda value
lambda <- lambdamax(x, y = y, index = index, penscale = sqrt,
model = LogReg()) * 0.5^(0:5)
## Fit the solution path on the lambda grid
fit <- grplasso(x, y = y, index = index, lambda = lambda, model = LogReg(),
penscale = sqrt,
control = grpl.control(update.hess = "lambda", trace = 0))
## Plot coefficient paths
plot(fit)
# }
Run the code above in your browser using DataLab