tests/testthat/test-predict.R

context("predict")

data(obk.long, package = "afex")
df <- obk.long
df$hour <- as.numeric(df$hour)

newdata <- df[1:5,]


test_that("between (compare to lm)", {
  between <- aov_car(value ~ treatment*gender + Error(id), data = df, 
                     fun_aggregate = mean)
  fit.lm <- lm(value ~ treatment*gender, data = between$data$long)
  
  
  expect_equal(predict(between, newdata), predict(fit.lm, newdata))
  expect_is(predict(between, newdata), "numeric")
  expect_is(predict(between, newdata, append = TRUE), "data.frame")
})

test_that("within + factorized numerics", {
  within <- aov_car(value ~ 1 + Error(id/(phase*hour)), data = df)
  
  p1 <- predict(within, newdata = data.frame(phase = "pre", hour = 1))
  p2 <- predict(within, newdata = data.frame(phase = "pre", hour = "1"))
  expect_equal(p1, p2)
  expect_equal(unname(p1), 3.8125)
  expect_error(predict(within, newdata = data.frame(phase = "pre", hour = 6)))
})

Try the afex package in your browser

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

afex documentation built on April 18, 2023, 1:09 a.m.