tests/testthat/test-predict.R

test_that("prediction for VarLin class", {
  spbayes=BVCfit(X, Y, Z, E, clin)
  pred = predict(spbayes, X.new=X.new, Z.new=Z.new, E.new=E.new, clin.new=clin.new, Y.new=Y.new)
  expect_equal(length(pred$y.pred), length(Y.new))
  expect_true(!is.null(pred$pmse))
  expect_error(predict(spbayes, X.new=X.new, Z.new=Z.new, clin.new=clin.new, Y.new=Y.new))
  expect_error(predict(spbayes, X.new=X.new, Z.new=Z.new, E.new=E.new, Y.new=Y.new))
  expect_error(predict(spbayes, X.new=X.new, Z.new=Z.new, E.new=E.new, clin.new=clin.new[,1], Y.new=Y.new))
})


test_that("prediction for VarOnly method", {
  spbayes=BVCfit(X=X, Y=Y, Z=Z, clin=clin, sparse=FALSE)
  pred = predict(spbayes, X.new=X.new, Z.new=Z.new, clin.new=clin.new, Y.new=Y.new)
  expect_equal(length(pred$y.pred), length(Y.new))
  expect_true(!is.null(pred$pmse))
  expect_silent(predict(spbayes, X.new=X.new, Z.new=Z.new, E.new=E.new, clin.new=clin.new))
  expect_error(predict(spbayes, X.new=X.new, Z.new=Z.new, E.new=E.new, Y.new=Y.new))
})


test_that("prediction for LinOnly method", {
  spbayes=BVCfit(X=X, Y=Y, Z=Z, E=E, clin=clin, VC=FALSE)
  pred = predict(spbayes, X.new=X.new, Z.new=Z.new, E.new=E.new, clin.new=clin.new)
  expect_output(print(pred))
  expect_equal(length(pred$y.pred), length(Y.new))
  expect_true(is.null(pred$pmse))
  expect_error(predict(spbayes, X.new=X.new, Z.new=Z.new, clin.new=clin.new, Y.new=Y.new))
  expect_error(predict(spbayes, X.new=X.new, Z.new=Z.new, E.new=E.new, Y.new=Y.new))
})

Try the spinBayes package in your browser

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

spinBayes documentation built on May 29, 2024, 8:38 a.m.