r - Why am I getting "Error in handleRes(res) : NA" when running bugs() with syntactically correct model? -
i'm trying run bayes model through r using r2winbugs , brugs running error cannot solve. i've checked model syntactically correct, , output when try running (example below):
model syntactically correct data loaded model compiled initializing chain 1: model initialized model initialized sampling has been started ... error in handleres(res) : na in addition: warning message: running command '"c:/users/user/documents/r/win-library/3.0/brugs/exec/bugshelper.exe" "c:/users/user/appdata/local/temp/rtmpwweqim" "c:/users/user/appdata/local/temp/rtmpwweqim/trash" "file32f44e4c5ab7.bug" "c:/users/user/appdata/local/temp/rtmpwweqim/cmds.txt" "1"' had status 144 session info:
> sessioninfo() r version 3.0.2 (2013-09-25) platform: x86_64-w64-mingw32/x64 (64-bit) rstudio 0.99.441 windows 7
here example though wasn't sure how attach data, if you'd full dataset, can copy here, please let me know.
library(brugs) library(r2winbugs) library(data.table) > dat date mth inc ind response 1: jan-10 1 1 0 100.0000 2: jan-10 1 2 0 103.1304 3: jan-10 1 3 0 106.2609 4: jan-10 1 4 0 109.3913 5: jan-10 1 5 0 112.5217 --- 572: dec-10 12 44 1 1887.4783 573: dec-10 12 45 1 1890.6087 574: dec-10 12 46 1 1893.7391 575: dec-10 12 47 1 1896.8696 576: dec-10 12 48 1 1900.0000 # set data values individual vectors n <- nrow(dat) periods <- length(unique(dat$date)) real_response <- dat$response tt <- dat$mth p <- dat$inc ind <- dat$ind x_dat <- list("real_response"=real_response,"p"=p,"n"=n,"tt"=tt,"periods"=periods, "ind"=ind) createmodel <- function(){ for(k in 1:n) { p2[k] <- p[k]*30+ind[k]*speed } for(i in 1:n) { real_response[i] ~ dnorm(real_responsehat[i],t_response[i]) t_response[i] <- pow(var_response[i],-1) var_response[i] <- pow(sigma,2)* mu_target * (1 - exp(-pow((p[i]/theta), omega[tt[i]]))) real_responsehat[i] <- target[tt[i]] * (1 - exp(-pow((p2[i]/theta), omega[tt[i]]))) } sigma ~ dgamma(0.5,0.001) theta ~ dgamma(0.5,0.001) for(j in 1:periods){ newmu[j] <- mu_target*pow((1+adj_factor), j) target[j] ~ dnorm(newmu[j],t_target) omega[j] ~ dgamma(s1,s2) } speed ~ dcat(p[]) for(j in 1:15){ p[j] <- 1/15 } adj_factor ~ dnorm(2, 1.2) t_target <- pow(s_target,-2) s_target ~ dgamma(0.5,0.0001) s1 ~ dgamma(1.5,.5) s2 ~ dgamma(1.5,.5) mu_target ~ dnorm(1000,0.0001) } mod <- file.path(paste(getwd(), "\\stackex_model.txt", sep="")) writemodel(createmodel, mod) modelcheck(mod) # file.show(mod) ## inits <- function() { list("target" = rep(1000,periods), "sigma" = 5, "theta" = 15, "omega" = rep(0.5,periods),"mu_target"=1000,"s_target"=60, "s1"=1.5, "s2"=1, "speed"=3, "adj_factor"=2) } parms <- c("target", "sigma", "theta", "omega","mu_target","s_target","s1","s2", "speed", "adj_factor") system.time(bmod <- bugs(data=x_dat, inits=inits, parameters.to.save=parms, n.iter=100, n.chains=1, n.burnin=50, n.thin=1, model.file=mod, debug=true, codapkg=false, bugs.directory="c:/program files (x86)/openbugs/openbugs323", program="openbugs")) i'm continuing try , debug problem if anyone's seen before or has clue what's happening i'd appreciate it.
also, iterations , thinning set low de-bugging easier. plan increase these (and parallelize) once know model runs.
changing to R 32 solves the problem for me
ReplyDelete