tests/testthat/test-lasso.R

test_that("lasso and slope fits are equivalent if all lambda are equal", {
  set.seed(1)
  xy <- SLOPE:::randomProblem(100, 10)
  x <- xy$x
  y <- xy$y

  lambda <- 0.6

  library(glmnet)
  glmnet.control(fdev = 0)
  lasso <- glmnet(x, y, lambda = 0.6, standardize = FALSE)
  lasso_coef <- as.vector(coef(lasso))

  slope <- SLOPE(
    x,
    y,
    center = FALSE,
    scale = FALSE,
    lambda = rep(lambda, ncol(x)),
    alpha = 1
  )

  slope_coef <- coef(slope)

  expect_equivalent(lasso_coef, slope_coef, tol = 1e-3)
})

Try the SLOPE package in your browser

Any scripts or data that you put into this service are public.

SLOPE documentation built on June 10, 2022, 1:05 a.m.