tests/testthat/test-mlc.R

context("mlc")
suppressPackageStartupMessages(library(caret))

set.seed(1)
mat <- matrix(rnorm(300), ncol = 3, nrow = 100)
colnames(mat) <- letters[1:3]
y <- sample(factor(c("a", "b")), 100, replace = TRUE)


test_that("fit mlc",{
          expect_is( mr <- mlc(mat,y), "list")
          expect_equal(names(mr), c("a", "b", "levels")) 
          expect_equal(vapply(mr$a, length, numeric(1)), c(m=3,D=1,I=9))   
      })

test_that("predict mlc",{
                      mod <- train( mat, y, method = mlcCaret, trControl = trainControl(method = "none"))
                      expect_is(pred <- predict.mlc(mod, mat), "factor")
                      expect_equal(length(pred), nrow(mat))
                      expect_equal(levels(pred), c("a", "b"))
                      expect_is(prob <- predict.mlc.prob(mod, mat), "matrix")
                      expect_equal(nrow(prob), nrow(mat))
                      expect_equal(ncol(prob), 2)
                  })  
          
          

Try the RStoolbox package in your browser

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

RStoolbox documentation built on March 18, 2022, 5:37 p.m.