Hello all!
I am trying to use nimbleRcall for the first time and am having trouble with the example given in help("nimbleRcall").
I have simplified the example given in the documentation below to illustrate the point easier. My understanding of the code is that z should hold x+2 for every iteration, but in some cases (highlighted) it does not. Please let me know if there is something simple that I am missing! I would like to understand this more closely before moving onto more complicated uses of the function.
Thank you so much for the help!
Jimmy
library(nimble)
add2 <- function(x) {
x + 2
}
nimble_add2 <- nimbleRcall(
prototype = function(
x = double(0)
){},
returnType = double(0),
Rfun = 'add2')
demoCode <- nimbleCode({
x ~ dnorm(0,1)
z <- nimble_add2(x)
})
demoModel <- nimbleModel(demoCode, inits = list(x = 1),
check = FALSE, calculate = FALSE)
mcmcConf <- configureMCMC(demoModel, monitors = c("x", "z"))
Rmcmc <- buildMCMC(mcmcConf)
Cmcmc <- compileNimble(demoModel)
Cmcmc <- compileNimble(Rmcmc, project = demoModel)
set.seed(1)
Cmcmc$run(niter = 10, nburnin = 0)
as.matrix(Cmcmc$mvSamples)
x z
[1,] -0.6264538 1.373546
[2,] 0.1836433 2.183643
[3,] -0.8356286 1.164371
[4,] 1.5952808 3.595281
[5,] 0.3295078 2.329508
[6,] -0.8204684 1.179532
[7,] 0.4874291 2.487429
[8,] 0.7383247 2.738325
[9,] 0.5757814 2.575781
[10,] -0.3053884 1.694612
--
You received this message because you are subscribed to the Google Groups "nimble-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nimble-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nimble-users/ca755d86-14a6-47bb-beeb-b5b8df641623n%40googlegroups.com.