test_examples: Test Examples

Description See Also Examples

Description

Test examples to be run manually by package maintainer.

See Also

jaggernaut

Examples

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
## Not run: 

library(testthat)

model1 <- jags_model("
model { 
 bLambda ~ dlnorm(0, 10^-2) 
 for (i in 1:length(x)) { 
   x[i] ~ dpois(bLambda) 
 } 
}",
model_id = "First Model")

model2 <- jags_model("
model { 
 bLambda ~ dlnorm(0, 5^-2) 
 for (i in 1:length(x)) { 
   x[i] ~ dpois(bLambda) 
 } 
}",
model_id = "Second Model")

models <- combine(model1, model2)
data <- data.frame(x = rpois(100,1))

analysis <- jags_analysis (model1, data, mode = "paper")
analysis <- jags_analysis (model1, data, mode = "demo")
analysis <- jags_analysis (model2, data, mode = "demo")
analysis <- jags_analysis (models, data, mode = "demo")

registerDoParallel(2) 
expect_warning(opts_jagr(parallel = TRUE))

expect_warning(analysis <- jags_analysis (model1, data, mode = "demo"))
expect_warning(analysis <- jags_analysis (model2, data, mode = "demo"))
expect_warning(analysis <- jags_analysis (models, data, mode = "demo"))

#' # stop cluster if registered parallel backend in windows
if(.Platform$OS.type == "windows") stopImplicitCluster()

expect_true(is_parallel(analysis))

opts_jagr(parallel = FALSE)
registerDoSEQ()

expect_true(is_parallel(analysis))
expect_error(update(analysis))

analysis <- jags_analysis (model1, data, mode = "demo")

analysis <- update(analysis)

expect_false(is_parallel(analysis))

registerDoParallel(4) 
opts_jagr(parallel = TRUE)

analysis <- update(analysis)

expect_false(is_parallel(analysis))

analysis <- jags_analysis (model1, data, mode = "demo")
analysis <- jags_analysis (model2, data, mode = "demo")
analysis <- jags_analysis (models, data, mode = "demo")

#' # stop cluster if registered parallel backend in windows
if(.Platform$OS.type == "windows") stopImplicitCluster()

opts_jagr(parallel = FALSE)
registerDoSEQ()

registerDoParallel(4) 
opts_jagr(parallel = TRUE)

 
mod <- jags_model("
                  model {
                  alpha ~ dunif(-20, 20)
                  beta1 ~ dunif(-10, 10)
                  beta2 ~ dunif(-10, 10)
                  beta3 ~ dunif(-10, 10)
                  sigma ~ dunif(0, 5)
                 
                  for (i in 1:length(Year)) {
                  eps[i] ~ dnorm(0, sigma^-2)
                  eLogC[i] <- alpha + beta1 * Year[i]
                  + beta2 * Year[i]^2 + beta3 * Year[i]^3
                  log(eC[i]) <- eLogC[i] + eps[i]
                  C[i] ~ dpois(eC[i])
                  }
                  }",
 derived_code = "data{
 for (i in 1:length(Year)) {
 log(prediction[i]) <- alpha + beta1 * Year[i]
 + beta2 * Year[i]^2 + beta3 * Year[i]^3
 }
 }",
  random_effects = list(eps = "Year"),
  select_data = c("C","Year*")
  )
 dat <- jaggernaut::falcon
 dat$C <- dat$Pairs
 an <- jags_analysis (mod, dat, mode = "debug")
 an <- jags_analysis (mod, dat, mode = "test")
 an <- jags_analysis (mod, dat, mode = "demo")
 an <- jags_analysis (mod, dat, mode = "explore")
 an <- jags_analysis (mod, dat, mode = "report")
 expect_warning(an <- jags_analysis (mod, dat, mode = "paper"))
 an <- jags_analysis (mod, dat, niters = 10^3)

# stop cluster if registered parallel backend in windows
if(.Platform$OS.type == "windows") stopImplicitCluster()

opts_jagr(parallel = FALSE)
registerDoSEQ()

registerDoParallel(4) 
opts_jagr(parallel = TRUE)

demo(peregrine, ask= FALSE)
demo(hm, ask = FALSE)
demo(fritillary, ask= FALSE)
demo(pinna, ask = FALSE)
demo(tits, ask = FALSE)
demo(p610, ask = FALSE)

# stop cluster if registered parallel backend in windows
if(.Platform$OS.type == "windows") stopImplicitCluster()

opts_jagr(parallel = FALSE)
registerDoSEQ()

## End(Not run)

poissonconsulting/jaggernaut documentation built on Feb. 18, 2021, 11:10 p.m.