Skip to Main Content

Sample_logistic.R

  #############################################################################
### Sample code to get LASSO, p, pLASS, LASSO-A, p-A, pLASSO-A estimators ###
#############################################################################

library(grplasso)
library(MASS)
source("function_logistic.R")
options(warn = -1)

###====== Read x and y ======###
x <- read.table("x_logistic.txt", header = FALSE)
y <- read.table("y_logistic.txt", header = FALSE)
x <- as.matrix(x)
y <- as.matrix(y)
n <- nrow(x)
p <- ncol(x)
        
###====== Settings ======###    
# prior set
pos.prior <- c(1 : 10)

# refit or not?
is.refit <- 1

# computational controls
n.threshold <- p/6
length.1 <- 10
length.2 <- 4
lambda.min <- 2

# sequence of tuning parameters
eta.seq <- c(seq(10, 1, by = -2), seq(1, 0.2, by = -0.2))
tau.seq <- c(2, 1, 0.5)
        
# 3-fold cross validation grouping
cv.group <- c(rep(1 : 3, each = floor(n/3)), rep(3, n - 3 * floor(n/3)))

###====== LASSO ======###
index <- 0 : p
index[1] <- NA
beta.1 <- find.beta(x, y, 0, 0, rep(0, p + 1), index, cv.group, lambda.min, length.1, length.2, n.threshold, is.refit)

###====== Prior ======###
index <- 0 : p
index[c(1, pos.prior + 1)] <- NA
beta.2 <- find.beta(x, y, 0, 0, rep(0, p + 1), index, cv.group, lambda.min, length.1, length.2, n.threshold, is.refit)

#====== pLASSO ======###
index <- 0 : p
index[1] <- NA
beta.3 <- find.beta(x, y, eta.seq, 0, beta.2, index, cv.group, lambda.min, length.1, length.2, n.threshold, is.refit)

#====== LASSO-A ======###
index <- 0 : p
index[1] <- NA
beta.4 <- find.beta(x, y, 0, tau.seq, beta.1, index, cv.group, lambda.min, length.1, length.2, n.threshold, is.refit)

#====== p-A ======###
index <- 0 : p
index[1] <- NA
beta.5 <- find.beta(x, y, 0, tau.seq, beta.2, index, cv.group, lambda.min, length.1, length.2, n.threshold, is.refit)

#====== pLASSO-A ======###
index <- 0 : p
index[1] <- NA
beta.6 <- find.beta(x, y, 0, tau.seq, beta.3, index, cv.group, lambda.min, length.1, length.2, n.threshold, is.refit)

cbind(beta.1, beta.2, beta.3, beta.4, beta.5, beta.6)