library(nimble)
pumpCode <- nimbleCode({
for (i in 1:N){
theta[i] ~ dgamma(exp(alpha), exp(beta))
lambda[i] <- theta[i] * t[i]
#x[i] ~ dpois(4.0) # does not work
x[i] ~ dpois(0*lambda[i]+4.0)
}
#alpha ~ dexp(1.0)
#beta ~ dgamma(0.1, 1.0)
alpha ~ dnorm(0.0,1.0)
beta ~ dnorm(0.0, 1.0)
})
pumpConsts <- list(N = 10, t = c(94.3, 15.7, 62.9, 126, 5.24, 31.4, 1.05, 1.05, 2.1, 10.5))
pumpData <- list(x = c(5, 1, 5, 14, 3, 19, 1, 1, 4, 22))
pumpInits <- list(alpha = 0.1, beta = 0.1, theta = rep(0.1, pumpConsts$N))
pump <- nimbleModel(code = pumpCode, name = "pump", constants = pumpConsts,
data = pumpData, inits = pumpInits, buildDerivs = TRUE)
pumpLaplace <- buildLaplace(pump,c('alpha','beta'))
CpumpLaplace <- compileNimble(pumpLaplace, project = pump)
CpumpLaplace$calcLaplace(c(1,1))
CpumpLaplace$calcLaplace(c(0,0))
CpumpLaplace$calcLaplace(c(0,1))
CpumpLaplace$calcLaplace(c(1,0))
Results equal -64.38562 with c(0,0) and c(0,1) and -63.88024 with c(1,1) and c(1,0). Do these results make sense ? I am aware that I probably push the system at its margins since the logLikelhood no longer depends on the parameters...
Thank in advance for enlightening me on what happens here.
All the best,
Frédéric
--
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/6cd3df58-7898-4d4e-bee5-aa74ef6aba80n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nimble-users/6a40a57e-e9fe-4bf2-a56c-3e84623aca7cn%40googlegroups.com.
library(nimble)
pumpCode <- nimbleCode({
for (i in 1:N){
theta[i] ~ dnorm(alpha,exp(beta))
lambda[i] <- theta[i] * t[i]
#x[i] ~ dpois(4.0) # does not work
x[i] ~ dpois(0*lambda[i]+4.0)
}
#alpha ~ dexp(1.0)
#beta ~ dgamma(0.1, 1.0)
alpha ~ dnorm(0.0,1.0)
beta ~ dnorm(0.0, 1.0)
})
pumpConsts <- list(N = 10, t = c(94.3, 15.7, 62.9, 126, 5.24, 31.4, 1.05, 1.05, 2.1, 10.5))
pumpData <- list(x = c(5, 1, 5, 14, 3, 19, 1, 1, 4, 22))
pumpInits <- list(alpha = 0.1, beta = 0.1, theta = rep(0.1, pumpConsts$N))
pump <- nimbleModel(code = pumpCode, name = "pump", constants = pumpConsts,
data = pumpData, inits = pumpInits, buildDerivs = TRUE)
pumpLaplace <- buildLaplace(pump, paramNodes = c('alpha','beta'), randomEffectsNodes = "theta", calcNodes = "theta",
control = list(check = FALSE))
CpumpLaplace <- compileNimble(pumpLaplace, project = compileNimble(pump))
CpumpLaplace$calcLaplace(c(1,1))
CpumpLaplace$calcLaplace(c(0,0))
CpumpLaplace$calcLaplace(c(0,1))
CpumpLaplace$calcLaplace(c(1,0))
library(nimble)
pumpCode <- nimbleCode({
for (i in 1:N){
theta[i] ~ dnorm(alpha,exp(beta))
lambda[i] <- theta[i] * t[i]
#x[i] ~ dpois(4.0) # does not work
x[i] ~ dpois(0*lambda[i]+4.0)
x2[i] ~ dpois(4.0)
}
#alpha ~ dexp(1.0)
#beta ~ dgamma(0.1, 1.0)
alpha ~ dnorm(0.0,1.0)
beta ~ dnorm(0.0, 1.0)
})
pumpConsts <- list(N = 10, t = c(94.3, 15.7, 62.9, 126, 5.24, 31.4, 1.05, 1.05, 2.1, 10.5))
pumpData <- list(x = c(5, 1, 5, 14, 3, 19, 1, 1, 4, 22), x2 = c(5, 1, 5, 14, 3, 19, 1, 1, 4, 22))
pumpInits <- list(alpha = 0.1, beta = 0.1, theta = rep(0.1, pumpConsts$N))
pump <- nimbleModel(code = pumpCode, name = "pump", constants = pumpConsts,
data = pumpData, inits = pumpInits, buildDerivs = TRUE)
pumpLaplace <- buildLaplace(pump, randomEffectsNodes = "theta")
CpumpLaplace <- compileNimble(pumpLaplace, project = compileNimble(pump))
CpumpLaplace$calcLaplace(c(1,1))
# -63.57501 (not OK)
library(nimble)
pumpCode <- nimbleCode({
for (i in 1:N){
theta[i] ~ dnorm(alpha,exp(beta))
lambda[i] <- theta[i] * t[i]
#x[i] ~ dpois(4.0) # does not work
x[i] ~ dpois(0*lambda[i]+4.0)
x2[i] ~ dpois(0*lambda[i]+4.0)
}
#alpha ~ dexp(1.0)
#beta ~ dgamma(0.1, 1.0)
alpha ~ dnorm(0.0,1.0)
beta ~ dnorm(0.0, 1.0)
})
pumpConsts <- list(N = 10, t = c(94.3, 15.7, 62.9, 126, 5.24, 31.4, 1.05, 1.05, 2.1, 10.5))
pumpData <- list(x = c(5, 1, 5, 14, 3, 19, 1, 1, 4, 22), x2 = c(5, 1, 5, 14, 3, 19, 1, 1, 4, 22))
pumpInits <- list(alpha = 0.1, beta = 0.1, theta = rep(0.1, pumpConsts$N))
pump <- nimbleModel(code = pumpCode, name = "pump", constants = pumpConsts,
data = pumpData, inits = pumpInits, buildDerivs = TRUE)
pumpLaplace <- buildLaplace(pump, randomEffectsNodes = "theta")
CpumpLaplace <- compileNimble(pumpLaplace, project = compileNimble(pump))
CpumpLaplace$calcLaplace(c(1,1))
#-127.15 (OK)
(ii) my second problem - which either is specific to Windows are to version 1.0.1 of Nimble - is that when I modify the modelCode in the same R session and run different buildLaplace calls I get either problems with the compileNimble phase or R crashes. For example with the code above ran in only one R session, R crashes (maybe not systematically). If I do the above code without the last $calcLaplace, R does not crash but then the CompileNimble call returns these following strange messages:
Compiling
[Note] This may take a minute.
[Note] Use 'showCompilerOutput = TRUE' to see C++ compilation details.
Error, could not find name
Name = lifted_d0_times_lambda_oBi_cB_plus_4_L5
Available Name 1 = alpha
Error, could not find name
Name = lifted_d0_times_lambda_oBi_cB_plus_4_L5
Available Name 1 = alpha
Compiling
[Note] This may take a minute.
[Note] Use 'showCompilerOutput = TRUE' to see C++ compilation details.
Error, could not find name
Name = lifted_d0_times_lambda_oBi_cB_plus_4_L5
Available Name 1 = alpha
Error, could not find name
Name = lifted_d0_times_lambda_oBi_cB_plus_4_L5
Available Name 1 = alpha
Error, could not find name
Name = lifted_d0_times_lambda_oBi_cB_plus_4_L5
Available Name 1 = alpha
Error, could not find name
Name = lifted_d0_times_lambda_oBi_cB_plus_4_L5
Available Name 1 = alpha
Error, could not find name
Name = lifted_d0_times_lambda_oBi_cB_plus_4_L5
Available Name 1 = alpha
Error, could not find name
Name = lifted_d0_times_lambda_oBi_cB_plus_4_L5
Available Name 1 = alpha
Error, could not find name
Name = lifted_d0_times_lambda_oBi_cB_plus_4_L5
Available Name 1 = alpha
Error, could not find name
Name = lifted_d0_times_lambda_oBi_cB_plus_4_L5
Available Name 1 = alpha
Error, could not find name
Name = lifted_d0_times_lambda_oBi_cB_plus_4_L5
Available Name 1 = alpha
Error, could not find name
Name = lifted_d0_times_lambda_oBi_cB_plus_4_L5
Available Name 1 = alpha
Error, could not find name
Name = lifted_d0_times_lambda_oBi_cB_plus_4_L5
Available Name 1 = alpha
Error, could not find name
Name = lifted_d0_times_lambda_oBi_cB_plus_4_L5
Available Name 1 = alpha
Error, could not find name
Name = lifted_d0_times_lambda_oBi_cB_plus_4_L5
Available Name 1 = alpha
Error, could not find name
Name = lifted_d0_times_lambda_oBi_cB_plus_4_L5
Available Name 1 = alpha
Error, could not find name
Name = lifted_d0_times_lambda_oBi_cB_plus_4_L5
Available Name 1 = alpha
Error, could not find name
Name = lifted_d0_times_lambda_oBi_cB_plus_4_L5
Available Name 1 = alpha
Error, could not find name
Name = lifted_d0_times_lambda_oBi_cB_plus_4_L5
Available Name 1 = alpha
Error, could not find name
Name = lifted_d0_times_lambda_oBi_cB_plus_4_L5
Available Name 1 = alpha
Error, could not find name
Name = lifted_d0_times_lambda_oBi_cB_plus_4_L5
Available Name 1 = alpha
Error, could not find name
Name = lifted_d0_times_lambda_oBi_cB_plus_4_L5
Available Name 1 = alpha
>
library(nimble)
pumpCode <- nimbleCode({
for (i in 1:N){
theta[i] ~ dnorm(alpha,exp(beta))
lambda[i] <- theta[i] * t[i]*exp(meanplot[1])
#x[i] ~ dpois(4.0) # does not work
x[i] ~ dpois(0*lambda[i]+4.0)
x2[i] ~ dpois(4.0*exp(gamma))
}
#alpha ~ dexp(1.0)
#beta ~ dgamma(0.1, 1.0)
alpha ~ dnorm(0.0,1.0)
beta ~ dnorm(0.0, 1.0)
gamma ~ dnorm(0.0, 1.0)
for (i in 1:N)
{meanplot[i]~dnorm(0,1)
}
})
pumpConsts <- list(N = 10, t = c(94.3, 15.7, 62.9, 126, 5.24, 31.4, 1.05, 1.05, 2.1, 10.5))
pumpData <- list(x = c(5, 1, 5, 14, 3, 19, 1, 1, 4, 22), x2 = c(5, 1, 5, 14, 3, 19, 1, 1, 4, 22))
pumpInits <- list(alpha = 0.1, beta = 0.1, theta = rep(0.1, pumpConsts$N))
pump <- nimbleModel(code = pumpCode, name = "pump", constants = pumpConsts,
data = pumpData, inits = pumpInits, buildDerivs = TRUE)
pumpLaplace <- buildLaplace(pump, randomEffectsNodes = "theta")
CpumpLaplace <- compileNimble(pumpLaplace, project = compileNimble(pump))
CpumpLaplace$getNodeNamesVec(returnParams = TRUE)
# [1] "alpha" "beta" "meanplot[1]" (OK)
CpumpLaplace$calcLaplace(c(1,1,0))
#-63.57501
library(nimble)
pumpCode <- nimbleCode({
for (i in 1:N){
theta[i] ~ dnorm(alpha,exp(beta))
lambda[i] <- theta[i] * t[i]*exp(meanplot[1])
#x[i] ~ dpois(4.0) # does not work
x[i] ~ dpois(0*lambda[i]+4.0)
x2[i] ~ dpois(4.0*exp(gamma+meanplot[i]))
}
#alpha ~ dexp(1.0)
#beta ~ dgamma(0.1, 1.0)
alpha ~ dnorm(0.0,1.0)
beta ~ dnorm(0.0, 1.0)
gamma ~ dnorm(0.0, 1.0)
for (i in 1:N)
{meanplot[i]~dnorm(0,1)
}
})
pumpConsts <- list(N = 10, t = c(94.3, 15.7, 62.9, 126, 5.24, 31.4, 1.05, 1.05, 2.1, 10.5))
pumpData <- list(x = c(5, 1, 5, 14, 3, 19, 1, 1, 4, 22), x2 = c(5, 1, 5, 14, 3, 19, 1, 1, 4, 22))
pumpInits <- list(alpha = 0.1, beta = 0.1, theta = rep(0.1, pumpConsts$N))
pump <- nimbleModel(code = pumpCode, name = "pump", constants = pumpConsts,
data = pumpData, inits = pumpInits, buildDerivs = TRUE)
pumpLaplace <- buildLaplace(pump, randomEffectsNodes = "theta")
CpumpLaplace <- compileNimble(pumpLaplace, project = compileNimble(pump))
CpumpLaplace$getNodeNamesVec(returnParams = TRUE)
# [1] "alpha" "beta" "meanplot[1]" (OK)
CpumpLaplace$calcLaplace(c(1,1,0))
# -Inf (not OK)
library(nimble)
pumpCode <- nimbleCode({
for (i in 1:N){
theta[i] ~ dnorm(alpha,exp(beta))
lambda[i] <- theta[i] * t[i]*exp(meanplot[1])
#x[i] ~ dpois(4.0) # does not work
x[i] ~ dpois(0*lambda[i]+4.0)
x2[i] ~ dpois(4.0*exp(alpha))
}
#alpha ~ dexp(1.0)
#beta ~ dgamma(0.1, 1.0)
alpha ~ dnorm(0.0,1.0)
beta ~ dnorm(0.0, 1.0)
gamma ~ dnorm(0.0, 1.0)
for (i in 1:N)
{meanplot[i]~dnorm(0,1)
}
})
pumpConsts <- list(N = 10, t = c(94.3, 15.7, 62.9, 126, 5.24, 31.4, 1.05, 1.05, 2.1, 10.5))
pumpData <- list(x = c(5, 1, 5, 14, 3, 19, 1, 1, 4, 22), x2 = c(5, 1, 5, 14, 3, 19, 1, 1, 4, 22))
pumpInits <- list(alpha = 0.1, beta = 0.1, theta = rep(0.1, pumpConsts$N))
pump <- nimbleModel(code = pumpCode, name = "pump", constants = pumpConsts,
data = pumpData, inits = pumpInits, buildDerivs = TRUE)
pumpLaplace <- buildLaplace(pump, randomEffectsNodes = "theta")
CpumpLaplace <- compileNimble(pumpLaplace, project = compileNimble(pump))
CpumpLaplace$getNodeNamesVec(returnParams = TRUE)
# [1] "alpha" "beta" "meanplot[1]" (OK)
CpumpLaplace$calcLaplace(c(1,1,0))
# [1] -120.8813
#equal to sum(log(dpois(c(5, 1, 5, 14, 3, 19, 1, 1, 4, 22),4.0*exp(1))))+sum(log(dpois(c(5, 1, 5, 14, 3, 19, 1, 1, 4, 22),4)))
#so both the likelihood of x & x2 are here taken into account
library(nimble)
pumpCode <- nimbleCode({
for (i in 1:N){
theta[i] ~ dnorm(alpha,exp(beta))
lambda[i] <- theta[i] * t[i]*exp(meanplot[1])
#x[i] ~ dpois(4.0) # does not work
x[i] ~ dpois(0*lambda[i]+4.0)
x2[i] ~ dpois(4.0*exp(gamma+alpha))
}
#alpha ~ dexp(1.0)
#beta ~ dgamma(0.1, 1.0)
alpha ~ dnorm(0.0,1.0)
beta ~ dnorm(0.0, 1.0)
gamma ~ dnorm(0.0, 1.0)
for (i in 1:N)
{meanplot[i]~dnorm(0,1)
}
})
pumpConsts <- list(N = 10, t = c(94.3, 15.7, 62.9, 126, 5.24, 31.4, 1.05, 1.05, 2.1, 10.5))
pumpData <- list(x = c(5, 1, 5, 14, 3, 19, 1, 1, 4, 22), x2 = c(5, 1, 5, 14, 3, 19, 1, 1, 4, 22))
pumpInits <- list(alpha = 0.1, beta = 0.1, theta = rep(0.1, pumpConsts$N))
pump <- nimbleModel(code = pumpCode, name = "pump", constants = pumpConsts,
data = pumpData, inits = pumpInits, buildDerivs = TRUE)
pumpLaplace <- buildLaplace(pump, randomEffectsNodes = "theta")
CpumpLaplace <- compileNimble(pumpLaplace, project = compileNimble(pump))
CpumpLaplace$getNodeNamesVec(returnParams = TRUE)
# [1] "alpha" "beta" "meanplot[1]" (OK)
CpumpLaplace$calcLaplace(c(1,1,0))
# [1] -Inf
These three problems do not summarize all the issues I am around with buildLaplace. I am trying to find a replicable example for the other ones.
Sincerely,
Frédéric
library(nimble)
pumpCode <- nimbleCode({
for (i in 1:2){ theta[i] ~ dnorm(alpha,exp(beta))}
for (j in 1:5) { thetab[j] ~ dnorm(0,1)}
for (i in 1:2){
for (j in 1:5) {
lambda[5*(i-1)+j] <- exp(theta[i]) * t[i]*exp(thetab[j])
#x[i] ~ dpois(4.0) # does not work
x[5*(i-1)+j] ~ dpois(0*lambda[5*(i-1)+j]+4.0)
}}
#alpha ~ dexp(1.0)
#beta ~ dgamma(0.1, 1.0)
alpha ~ dnorm(0.0,1.0)
beta ~ dnorm(0.0, 1.0)
})
pumpConsts <- list(N = 10, t = c(94.3, 15.7, 62.9, 126, 5.24, 31.4, 1.05, 1.05, 2.1, 10.5))
pumpData <- list(x = c(5, 1, 5, 14, 3, 19, 1, 1, 4, 22))
pumpInits <- list(alpha = 0.1, beta = 0.1, theta = rep(0.1, pumpConsts$N))
pump <- nimbleModel(code = pumpCode, name = "pump", constants = pumpConsts,
data = pumpData, inits = pumpInits, buildDerivs = TRUE)
pumpLaplace <- buildLaplace(pump, randomEffectsNodes = "theta")
CpumpLaplace <- compileNimble(pumpLaplace, project = compileNimble(pump))
CpumpLaplace$calcLaplace(c(1,1,0,0,0,0,0))
# -63.57501 (OK)
library(nimble)
pumpCode <- nimbleCode({
for (i in 1:2){ theta[i] ~ dnorm(alpha,exp(beta))}
for (j in 1:5) { thetab[j] ~ dnorm(0,1)}
for (i in 1:1){
for (j in 1:5) {
lambda[5*(i-1)+j] <- exp(theta[i]) * t[i]*exp(thetab[j])
#x[i] ~ dpois(4.0) # does not work
x[5*(i-1)+j] ~ dpois(0*lambda[5*(i-1)+j]+4.0)
}}
#alpha ~ dexp(1.0)
#beta ~ dgamma(0.1, 1.0)
alpha ~ dnorm(0.0,1.0)
beta ~ dnorm(0.0, 1.0)
})
pumpConsts <- list(N = 10, t = c(94.3, 15.7, 62.9, 126, 5.24, 31.4, 1.05, 1.05, 2.1, 10.5))
pumpData <- list(x = c(5, 1, 5, 14, 3, 19, 1, 1, 4, 22))
pumpInits <- list(alpha = 0.1, beta = 0.1, theta = rep(0.1, pumpConsts$N))
pump <- nimbleModel(code = pumpCode, name = "pump", constants = pumpConsts,
data = pumpData, inits = pumpInits, buildDerivs = TRUE)
pumpLaplace <- buildLaplace(pump, randomEffectsNodes = "theta")
CpumpLaplace <- compileNimble(pumpLaplace, project = compileNimble(pump))
CpumpLaplace$calcLaplace(c(1,1,0,0,0,0,0))
# Inf
Sincerely,
Frédéric
To view this discussion on the web visit https://groups.google.com/d/msgid/nimble-users/996fd121-b2c5-49bb-911d-b034a60eca5dn%40googlegroups.com.