3

glmnet seems to slow down in an application I'm doing (Joint Lasso) if one parameter increases.

I figured out that the matrix I am giving to glmnet increases in its second half. It is comparable to the code below where the first half of X has the mean 70 and the second half has a mean of 0. Compared to the case where both halfs have mean 70 or mean 0 it takes about three times the computation time.

Is there a specific reason for this behaviour?

library(glmnet)
Sigma_matrix <- diag(x = 1, nrow = number_variables, ncol = number_variables)
rho <- 0.5
for (k in 1:number_variables) {
  for (j in 1:number_variables) {
    if (k != j) {
      Sigma_matrix[k, j] <- rho^((abs(k-j))^2)
    }
  }
}
number_variables <- 20
observations <- 250
X[1: (observations/2), ] <- mvrnorm(n = (observations/2), mu = c(rep(70, times = number_variables)), Sigma = Sigma_matrix)
X[((observations/2)+1): observations, ] <- mvrnorm(n = (observations/2), mu = c(rep(0, times = number_variables)), Sigma = Sigma_matrix)
y <- rnorm(n = observations)
start_one <- Sys.time()
for (i in 1:1000) {
  model <- cv.glmnet(X, y, intercept = TRUE)
}
end_one <- Sys.time()
print(end_one-start_one)
BB27
  • 31
  • 2

0 Answers0