tests/testthat/test-variance_model.R

testthat::context("Formalize the construction of a variance model")


iris$y <- sample(1:5, size = nrow(iris),
                 replace = TRUE)

# I - MODEL WHERE THRESHOLDS ARE ESTIMATED ------

# A/ NO formulaSD ARGUMENT -----

ordered_logit <- oglmx(
  data = iris,
  formulaMEAN = "y ~ Sepal.Length + Sepal.Width + Petal.Length + Petal.Width",
  link = "logit",
  threshparam = NULL, constantSD = FALSE,
  constantMEAN = FALSE, delta = 0)



testthat::test_that(
  "[no newdata] Model for variance is a column of 1s when formulaSD is NULL",{
    testthat::expect_equal(
      variance_model(ordered_logit), matrix(rep(1, nrow(iris)))
    )
  }
)

testthat::test_that(
  "[with newdata] Model for variance is a column of 1s when formulaSD is NULL",{
    testthat::expect_equal(
      variance_model(ordered_logit, newdata = data.frame(runif(100L))),
      matrix(rep(1, 100L))
    )
  }
)


# B/ MODEL HAS A formulaSD ARGUMENT

ordered_logit <- oglmx(
  data = iris,
  formulaMEAN = "y ~ Sepal.Length + Sepal.Width",
  formulaSD = "y ~ Sepal.Width",
  link = "logit",
  threshparam = NULL,
  constantMEAN = FALSE, delta = 0)

testthat::expect_error(
  Z_no_newdata <- variance_model(ordered_logit)
)




# MODEL WHERE THRESHOLDS ARE KNOWN ------
linogaliana/oglm documentation built on March 5, 2021, 8:27 p.m.