tests/testthat/test-model-formula.R

library(testthat)
library(serp)
context("checks the availability of formula and response in model")
wine <- serp::wine

##
test_that("formula is specified in serp",
{
  expect_error(
    serp(globalEff=~temp, link = "probit", reverse=TRUE,
         slope = "parallel", data = wine))
  expect_error(
    serp(data = wine), "Model needs a formula")
  expect_vector(serp(rating~ 1, link = "cauchit", slope = "penalize",
                     tuneMethod = "finite", reverse=TRUE, data = wine)$coef)
})

##
test_that("response exist, is not in predictor or in 'GlobalEff'",
{
  expect_error(
    serp(~ temp + contact, link = "cauchit", slope = "penalize",
         tuneMethod = "finite", reverse=TRUE, data = wine))
  expect_error(
    serp(rating ~ temp + rating + contact, link = "logit",
         slope = "penalize", reverse=TRUE, data = wine))
  expect_error(
    serp(rating ~ temp + contact, link = "logit",
         slope = "penalize", reverse=TRUE, tuneMethod = "cv",
         globalEff = ~rating, data = wine))
  expect_error(
    serp(rating ~ temp + contact, link = "logit",
         slope = "penalize", reverse=TRUE, tuneMethod = "aic",
         globalEff = ~"rating", data = wine))
})

Try the serp package in your browser

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

serp documentation built on March 18, 2022, 6:33 p.m.