[R] R2WinBUGS error

Uwe Ligges ligges at statistik.uni-dortmund.de
Thu Apr 6 08:29:32 CEST 2006


Joseph Retzer wrote:
>  
>  
> Dear R-help,
>   I'm using the R2WinBUGS package and getting an error message:
>  
>          Error in file(file, "r") : unable to open connection
>          In addition: Warning message:
>          cannot open file 'codaIndex.txt', reason 'No such file or
> directory' 


Looks like there was an error in WinBUGS: R cannot access the file, 
because WinBUGS has not written it before.

You can use
   bugs(......, debug = TRUE)
Then WinBUGS stays open and you can look at its error messages in order 
to correct the code/data/inits or whatever....

Uwe Ligges









> 
> I'm using R 2.2.1 and WinBUGS 1.4.1 on a windows machine (XP).  My R code
> and WinBUGS code is given below. The complete WinBUGS program executes
> correctly in WinBUGS however I'm generating some of my inits using WinBUGS
> so I may be making an error there. On the other hand, the error generated in
> R seems to imply it cannot locate a file. I've checked my paths and they are
> correct. Also, my data is loading correctly.
> Many thanks,
> Joe
>  
> #########################################################
>  
> # R code
> # Runs Bayesian Ordered Logit by calling WinBUGS from R
> #     ologit2.txt: WinBUGS commands
>  
> library(R2WinBUGS)
>  
> setwd("c:/docume~1/admini~1/mydocu~1/r_tuto~1")
> load("oldat.Rdata") # R data file containing data frame ol.dat
>                     # with vars: q02, bf23f, bf23b, bf22, bf34a, bf34.1,
> bf34.2
>  
>    q02 <-    ol.dat$q02 
>  bf23f <-  ol.dat$bf23f 
>  bf23b <-  ol.dat$bf23b 
>   bf22 <-   ol.dat$bf22 
>  bf34a <-  ol.dat$bf34a 
> bf34.1 <- ol.dat$bf34.1 
> bf34.2 <- ol.dat$bf34.2 
>  
> N=nrow(ol.dat) 
> Ncut=5  
>  
> data <- list("N", "q02", "bf23f", "bf23b", "bf22", "bf34a", "bf34.1",
> "bf34.2", "Ncut")
>  
> inits <- function()
>         {
>            list(k=c(-5, -4, -3, -2, -1), tau=2, theta=rnorm(7, -1, 100))
>         }
>  
> parameters <- c("k")
>  
> olog.out <- bugs(data, inits, parameters, 
>                  model.file="c:/Documents and Settings/Administrator/My
> Documents/r_tutorial/ologit2.txt",
>                  n.chains = 2, n.iter = 1000,
>                  bugs.directory = "c:/Program Files/WinBUGS14/")
>  
> ########################################################
> # WinBUGS code
>  
> model exec;  
> {
>  # Priors on regression coefficients
>    theta[1] ~  dnorm( -1,1.0) ;   theta[2] ~  dnorm(-1,1.0)   
>    theta[3] ~  dnorm(  1,1.0) ;   theta[4] ~  dnorm(-1,1.0)   
>    theta[5] ~  dnorm( -1,1.0) ;   theta[6] ~  dnorm( 1,1.0)   
>    theta[7] ~  dnorm( -1,1.0)                  
>              
>  # Priors on latent variable cutpoints  
>    k[1] ~ dnorm(0, 0.1)I(    , k[2]);  k[2] ~ dnorm(0, 0.1)I(k[1], k[3])
>    k[3] ~ dnorm(0, 0.1)I(k[2], k[4]);  k[4] ~ dnorm(0, 0.1)I(k[3], k[5])
>    k[5] ~ dnorm(0, 0.1)I(k[4],     )
>  
>  # Prior on precision
>    tau ~ dgamma(0.001, 0.001)
>  
>  # Some defs
>    sigma <- sqrt(1 / tau);             log.sigma <- log(sigma);    
>  
>  for (i in 1 : N) 
>    {
>     # Prior on 
>      b[i] ~ dnorm(0.0, tau)
>  
>     # Model Mean
>      mu[i] <- theta[1] + theta[2]*bf22[i] + theta[3]*bf23b[i] +
> theta[4]*bf23f[i] + theta[5]*bf34a[i] + theta[6]*bf34.1[i] +
> theta[7]*bf34.2[i]
>  
>      for (j in 1 : Ncut) 
>        { 
>           # Logit Model
>           # cumulative probability of lower response than j
>            logit(Q[i, j]) <-  -(k[j] + mu[i] + b[i])
>        }
>  
>    # probability that response = j
>      p[i,1] <- max( min(1 - Q[i,1], 1), 0)
>  
>      for (j in 2 : Ncut) 
>          { 
>             p[i,j] <- max( min(Q[i,j-1] - Q[i,j],1), 0) 
>          }
>  
>      p[i,(Ncut+1)] <- max( min(Q[i,Ncut], 1), 0)
>      q02[i] ~ dcat(p[i, ])
>    }
> }
> 
>  
> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html




More information about the R-help mailing list