tests/testthat/test-sparsity.R

test_that("sparse and dense implementations give equivalent results", {
  set.seed(2)
  n <- 100
  p <- 2

  for (family in c("gaussian", "binomial", "poisson")) {
    d <- SLOPE:::randomProblem(n, p, 0.5, density = 0.5, response = family)
    sparse_x <- d$x
    dense_x <- as.matrix(sparse_x)
    y <- d$y
    beta <- d$beta

    sparse_fit <- SLOPE(sparse_x, y, family = family, center = FALSE)

    sparse_coefs <- coef(sparse_fit)

    dense_fit <- SLOPE(dense_x, y, family = family, center = FALSE)

    dense_coefs <- coef(dense_fit)

    expect_equal(sparse_coefs, dense_coefs, tol = 1e-4)
  }
})

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.