Skip to content

Commit

Permalink
add unitary tests for modelsToJags
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Cazelles committed Dec 4, 2016
1 parent 9edcd2f commit 8a7738b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
8 changes: 4 additions & 4 deletions R/fit.bayesreg.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fit.bayesreg <- function(dat, algorithm = "Binomial", draws = 10000) {
# parameters to track
ParsStage <- c("alpha", "alpha_mu", "ynew", "fit", "fitnew")
#
modfile <- paste0(tempdir(), "/Bayesian/Intercept.jags")
modfile <- paste0(tempdir(), "/Intercept.jags")
interceptToJags(modfile)

This comment has been minimized.

Copy link
@bw4sz

bw4sz Dec 4, 2016

Contributor

What does this do? @KevCaz

#
m1 <- do.call(R2jags::jags.parallel, list(data = modelDat, model.file = modfile,
Expand All @@ -75,7 +75,7 @@ fit.bayesreg <- function(dat, algorithm = "Binomial", draws = 10000) {
ParsStage <- c("alpha", "beta", "alpha_mu", "alpha_sigma", "beta_sigma",
"beta_mu", "ynew", "fit", "fitnew")
#
modfile <- paste0(tempdir(), "/Bayesian/Binomial.jags")
modfile <- paste0(tempdir(), "/Binomial.jags")
binomialToJags(modfile)
m1 <- do.call(R2jags::jags.parallel, list(data = modelDat, parameters.to.save = ParsStage,
model.file = modfile, n.thin = nt, n.iter = ni, n.burnin = nb, n.chains = nc,
Expand All @@ -88,7 +88,7 @@ fit.bayesreg <- function(dat, algorithm = "Binomial", draws = 10000) {
ParsStage <- c("alpha", "beta", "alpha_mu", "alpha_sigma", "beta_sigma",
"beta_mu", "ynew", "fit", "fitnew")
# jags file.
modfile <- paste0(tempdir(), "/Bayesian/Poisson.jags")
modfile <- paste0(tempdir(), "/Poisson.jags")
poissonToJags(modfile)
#
m1 <- do.call(R2jags::jags.parallel(list(data = modelDat, parameters.to.save = ParsStage,
Expand All @@ -102,7 +102,7 @@ fit.bayesreg <- function(dat, algorithm = "Binomial", draws = 10000) {
ParsStage <- c("alpha", "beta", "alpha_mu", "alpha_sigma", "beta_sigma",
"beta_mu", "ynew", "fit", "fitnew")
# jags file.
modfile <- paste0(tempdir(), "/Bayesian/Multinomial.jags")
modfile <- paste0(tempdir(), "/Multinomial.jags")
multinomialToJags(modfile)
#
m1 <- do.call(R2jags::jags.parallel, list(data = modelDat, parameters.to.save = ParsStage,
Expand Down
18 changes: 18 additions & 0 deletions tests/testthat/test-bayes.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
context("Bayesian model")

fl1 <- paste0(tempdir(), "/binjag.jags")
fl2 <- paste0(tempdir(), "/intjag.jags")
fl3 <- paste0(tempdir(), "/muljag.jags")
fl4 <- paste0(tempdir(), "/poijag.jags")
binomialToJags(fl1)
interceptToJags(fl2)
multinomialToJags(fl3)
poissonToJags(fl4)


test_that("generating models as jags files", {
expect_equal(TRUE, file.exists(fl1))
expect_equal(TRUE, file.exists(fl2))
expect_equal(TRUE, file.exists(fl3))
expect_equal(TRUE, file.exists(fl4))
})

0 comments on commit 8a7738b

Please sign in to comment.