tests/testthat/test_lambda00.R

library(testthat)  
library(enetLTS)

test_that("lambda00 works", {
  set.seed(86)
  n <- 100; p <- 25                             # number of observations and variables
  beta <- rep(0,p); beta[1:6] <- 1              # 10\% nonzero coefficients
  sigma <- 0.5                                  # controls signal-to-noise ratio
  x <- matrix(rnorm(n*p, sigma),nrow=n)
  e <- rnorm(n,0,1)                             # error terms
  eps <-0.05                                    # \%10 contamination to only class 0
  m <- ceiling(eps*n)
  y <- sample(0:1,n,replace=TRUE)
  xout <- x
  xout[y==0,][1:m,] <- xout[1:m,] + 10;         # class 0
  yout <- y                                     # wrong classification for vertical outliers
  # compute smallest value of the upper limit for the penalty parameter
  l00 <- lambda00(xout,yout)
  expect_equal(round(l00,9), c(0.005927559))
})
fatmasevinck/enetLTS documentation built on Jan. 21, 2023, 10:35 p.m.