@@ -3231,92 +3231,6 @@ test_that('an error is given when trying to assign a sampler to partially observ
32313231 expect_error(configureMCMC(model , print = FALSE ), info = " model with dmvt given a sampler for every node" )
32323232})
32333233
3234- test_that(' trying to give a sampler to an observed node does not yield an error from configureMCMC' , {
3235- code <- nimbleCode({ for (i in 1 : N ){
3236- theta [i ] ~ dgamma(alpha ,beta )
3237- lambda [i ] <- theta [i ]* t [i ]
3238- x [i ] ~ dpois(lambda [i ])
3239- }
3240- alpha ~ dexp(1.0 )
3241- beta ~ dgamma(0.1 ,1.0 )
3242- y [1 : 5 ]~ dmvt(mu [1 : 5 ], Sigma [1 : 5 ,1 : 5 ], df = 10 )
3243- })
3244- Consts <- list (N = 10 , t = c(94.3 , 15.7 , 62.9 , 126 , 5.24 , 31.4 , 1.05 , 1.05 , 2.1 , 10.5 ))
3245- Data <- list (x = c(5 , 1 , 5 , 14 , 3 , 19 , 1 , 1 , 4 , 22 ), y = c(rep(NA ,3 ),4 ,5 ))
3246-
3247- model <- nimbleModel(code = code , name = " model" , constants = Consts , data = Data )
3248-
3249- expect_error(configureMCMC(model , nodes = ' alpha' , print = FALSE ), NA , info = " observed node in model given a sampler" )
3250- })
3251-
3252- test_that(' partial_mvn sampler was not given to non dmnorm dist' , {
3253- code <- nimbleCode({ for (i in 1 : N ){
3254- theta [i ] ~ dgamma(alpha ,beta )
3255- lambda [i ] <- theta [i ]* t [i ]
3256- x [i ] ~ dpois(lambda [i ])
3257- }
3258- alpha ~ dexp(1.0 )
3259- beta ~ dgamma(0.1 ,1.0 )
3260- })
3261- Consts <- list (N = 10 , t = c(94.3 , 15.7 , 62.9 , 126 , 5.24 , 31.4 , 1.05 , 1.05 , 2.1 , 10.5 ))
3262- Data <- list (x = c(5 , 1 , 5 , 14 , 3 , 19 , 1 , 1 , 4 , 22 ))
3263-
3264- model <- nimbleModel(code = code , name = " model" , constants = Consts , data = Data )
3265-
3266- conf <- configureMCMC(model )
3267-
3268- expect_true(! any(sapply(conf $ getSamplers(), function (sc ) sc $ name )== ' partial_mvn' ), info = " partial_mvn sampler assigned as sampler to non dmnorm distribution" )
3269- })
3270-
3271- test_that(' partial_mvn sampler was not given to non dmnorm distribution from model that has dmnorm distribution' , {
3272- code <- nimbleCode({ for (i in 1 : N ){
3273- theta [i ] ~ dnorm(alpha ,beta )
3274- lambda [i ] <- theta [i ]* t [i ]
3275- x [i ] ~ dexp(lambda [i ])
3276- }
3277- alpha ~ dpois(1.0 )
3278- beta ~ dunif(0.1 ,1.0 )
3279- y [1 : 10 ]~ dmnorm(mu [1 : 10 ], Sigma [1 : 10 ,1 : 10 ])
3280- })
3281- consts <- list (N = 10 , t = c(94.3 , 15.7 , 62.9 , 126 , 5.24 , 31.4 , 1.05 , 1.05 , 2.1 , 10.5 ))
3282- data <- list (x = c(5 , 1 , 5 , 14 , 3 , 19 , 1 , 1 , 4 , 22 ), y = c(rep(NA ,3 ),4 : 10 ))
3283-
3284- model <- nimbleModel(code = code , name = " model" , constants = consts , data = data )
3285-
3286- conf <- configureMCMC(model )
3287-
3288- expect_true(! any(sapply(conf $ getSamplers(), function (sc ) sc $ name )[head(seq_along(sapply(conf $ getSamplers(), function (sc ) sc $ name )), - 1 )]== ' partial_mvn' ), info = " partial_mvn sampler assigned as sampler to non dmnorm node in model with dmnorm" )
3289- })
3290-
3291- test_that(' Values change at same rows for unobserved parts of partially observed node when multivariateNodesAsScalars = FALSE' , {
3292- Code <- nimbleCode({ for (i in 1 : N ){
3293- theta [i ] ~ dgamma(alpha ,beta )
3294- lambda [i ] <- theta [i ]* t [i ]
3295- x [i ] ~ dpois(lambda [i ])
3296- }
3297- alpha ~ dexp(1.0 )
3298- beta ~ dgamma(0.1 ,1.0 )
3299- y [1 : 5 ]~ dmnorm(mu [1 : 5 ], Sigma [1 : 5 ,1 : 5 ])
3300- })
3301- Consts <- list (N = 10 , t = c(94.3 , 15.7 , 62.9 , 126 , 5.24 , 31.4 , 1.05 , 1.05 , 2.1 , 10.5 ))
3302- Data <- list (x = c(5 , 1 , 5 , 14 , 3 , 19 , 1 , 1 , 4 , 22 ), y = c(rep(NA ,3 ),4 ,5 ))
3303- Inits <- list (alpha = 1 , beta = 1 , theta = rep(0.1 , Consts $ N ), mu = 1 : 5 , Sigma = diag(5 ), y = c(rep(1 ,3 ),rep(NA ,2 )))
3304- model <- nimbleModel(code = Code , name = " model" , constants = Consts , data = Data , inits = Inits )
3305-
3306- Cmodel <- compileNimble(model )
3307-
3308- conf <- configureMCMC(model , nodes = ' y[1:5]' , multivariateNodesAsScalars = FALSE )
3309- conf $ addMonitors(" y" )
3310-
3311- modelMCMC <- buildMCMC(conf )
3312- CmodelMCMC <- compileNimble(modelMCMC , project = model )
3313- modrun <- runMCMC(CmodelMCMC , niter = 100 , setSeed = 0 )
3314-
3315- onezro <- apply(modrun [,3 : 5 ], 2 , diff )!= 0
3316-
3317- expect_true(all(apply(onezro , 1 , function (x ) all(x ) || all(! x ))), info = " Values of MCMC sampled nodes change at same time as other nodes" )
3318- })
3319-
33203234test_that(' partial_mvn_pp sampler with scalar cases' , {
33213235 code <- nimbleCode({
33223236 alpha ~ dexp(1.0 )
@@ -3336,9 +3250,9 @@ test_that('partial_mvn_pp sampler with scalar cases', {
33363250 cmodel <- compileNimble(model )
33373251 cmcmc <- compileNimble(mcmc , project = model )
33383252
3339- expect_success (out <- runMCMC(mcmc , 5 ))
3340- expect_success (cout <- runMCMC(cmcmc , 5 ))
3341-
3253+ expect_no_error (out <- runMCMC(mcmc , 5 ))
3254+ expect_no_error (cout <- runMCMC(cmcmc , 5 ))
3255+
33423256 # # Condition on univariate
33433257 Data <- list (y = c(rep(NA , 4 ), 0 ))
33443258 model <- nimbleModel(code = code , name = " model" , data = Data , constants = Const , inits = list (y = rep(1 ,5 )))
@@ -3350,8 +3264,8 @@ test_that('partial_mvn_pp sampler with scalar cases', {
33503264 cmodel <- compileNimble(model )
33513265 cmcmc <- compileNimble(mcmc , project = model )
33523266
3353- expect_success (out <- runMCMC(mcmc , 5 ))
3354- expect_success (cout <- runMCMC(cmcmc , 5 ))
3267+ expect_no_error (out <- runMCMC(mcmc , 5 ))
3268+ expect_no_error (cout <- runMCMC(cmcmc , 5 ))
33553269
33563270})
33573271
0 commit comments