tests/testthat/test-writeJagsModel.R

context("writeJagsModel")

craps <- HydeNetwork(~ d1 + d2 + diceSum | d1*d2
                     + firstRollOutcome | diceSum)  %>%
  setNode(d1, nodeType="dcat",
          pi = vectorProbs(p = rep(1/6,6), d1),
          validate = FALSE) %>%
  setNode(d2, nodeType="dcat",
          pi = vectorProbs(p = rep(1/6,6), d2),
          validate = FALSE) %>%
  setNode(diceSum, nodeType = "determ",
          define = fromFormula(),
          nodeFormula = diceSum ~ di1 + di2) %>%
  setNode(firstRollOutcome, nodeType = "determ",
          define = fromFormula(),
          nodeFormula = firstRollOutcome ~ 
            ifelse(diceSum < 4 | diceSum > 11, -1,
                   ifelse(diceSum == 7 | diceSum == 11, 1,0)))

test_that("writeJagsModel - determ",
{
  #* Because of how `writeJagsModel` processes the network object 
  #* it needs to be used within `writeNetworkModel`, which is 
  #* intended anyway since it is an unexported function
  expect_output(writeNetworkModel(craps, TRUE))
})

test_that("writeJagsModel - dcat with pi defined by user",
{
  expect_output(writeNetworkModel(craps, TRUE))
})

test_that("writeJagsModel - dpois",
{
  carNet <- HydeNetwork(~gear | mpg + am,
                        data = mtcars) %>%
  setNode(gear, nodeType = "dpois", nodeFitter = "glm",
            fitterArgs = list(family = poisson),
            lambda = fromData())
  expect_output(writeNetworkModel(carNet, TRUE))
})

Try the HydeNet package in your browser

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

HydeNet documentation built on July 8, 2020, 5:15 p.m.