This is a BUGS problem, not an R problem, so would be better asked on the
BUGS list (a practical hint: if it's not working through R, run the code
directly in BUGS: the error reporting is better). Anyway, here BUGS manages
to tell R to tell you what's wrong:
variable n is not defined
And looking at your data, it's right. n is not defined
On 4 December 2012 14:17, Günal Bilek <gunal-34@hotmail.com> wrote:
> Hi,
> I am trying to covert a Winbugs code into R code. Here is the winbugs code
> model{# model’s likelihoodfor (i in 1:n){time[i] ~ dnorm( mu[i], tau ) #
> stochastic componenent# link and linear predictormu[i] <- beta0 + beta1
*
> cases[i] + beta2 * distance[i]}# prior distributionstau ~ dgamma( 0.01,
> 0.01 )beta0 ~ dnorm( 0.0, 1.0E-4)beta1 ~ dnorm( 0.0, 1.0E-4)beta2 ~ dnorm(
> 0.0, 1.0E-4)# definition of sigmas2<-1/taus <-sqrt(s2)# calculation
of the
> sample variancefor (i in 1:n){ c.time[i]<-time[i]-mean(time[]) }sy2
<-
> inprod( c.time[], c.time[] )/(n-1)# calculation of Bayesian version R
> squaredR2B <- 1 - s2/sy2# Expected y for a typical delivery
timetypical.y
> <- beta0 + beta1 * mean(cases[]) + beta2 * mean(distance[])}INITSlist(
> tau=1, beta0=1, beta1=0, beta2=0 )DATA (LIST)list( n=25,time = c(16.68,
> 11.5, 12.03, 14.88, 13.75, 18.11, 8, 17.83,79.24, 21.5, 40.33, 21, 13.5,
> 19.75, 24, 29, 15.35,19, 9.5, 35.1, 17.9, 52.32, 18.75, 19.83,
> 10.75),distance = c(560, 220, 340, 80, 150, 330, 110, 210, 1460,605, 688,
> 215, 255, 462, 448, 776, 200, 132,36, 770, 140, 810, 450, 635, 150),cases
> c( 7, 3, 3, 4, 6, 7, 2, 7, 30, 5, 16, 10, 4, 6, 9,10, 6, 7, 3, 17, 10, 26,
> 9, 8, 4) )
>
> I want to do this in R. So, I copied the model and pasted into a txt file
> named reg. Here is the R code I used
> time <-
>
c(16.68,11.5,12.03,14.88,13.75,18.11,8,17.83,79.24,21.5,40.33,21,13.5,19.75,24,29,15.35,19,9.5,35.1,17.9,52.32,18.75,19.83,10.75)cases
> <- c(7,3,3,4,6,7,2,7,30,5,16,10,4,6,9,10,6,7,3,17,10,26,9,8,4)distance
<-
>
c(560,220,340,80,150,330,110,210,1260,605,688,215,255,462,448,776,200,132,36,770,140,810,450,635,150)
> data <- list("time","cases","distance")
> inits <- function(){list(tau=1,beta1=0,beta2=0,beta3=0)}
> sim <- bugs(data, inits, model.file >
"C:/Users/Gunal/Desktop/dummy/reg.txt",parameters =
c("beta1",
> "beta2","beta3"),n.chains = 3, n.iter =
1000,bugs.directory > "D:/PROGRAMLAR/WinBUGS14/",debug=TRUE)
>
> Winbugs is producing this error page
> display(log)check(C:/Users/Gunal/Desktop/dummy/reg.txt)model is
> syntactically
> correctdata(C:/Users/Gunal/AppData/Local/Temp/RtmpCYxtDZ/data.txt)data
> loadedcompile(3)variable n is not
>
definedinits(1,C:/Users/Gunal/AppData/Local/Temp/RtmpCYxtDZ/inits1.txt)command
> #Bugs:inits cannot be executed (is greyed
> out)inits(2,C:/Users/Gunal/AppData/Local/Temp/RtmpCYxtDZ/inits2.txt)command
> #Bugs:inits cannot be executed (is greyed
> out)inits(3,C:/Users/Gunal/AppData/Local/Temp/RtmpCYxtDZ/inits3.txt)command
> #Bugs:inits cannot be executed (is greyed out)gen.inits()command
> #Bugs:gen.inits cannot be executed (is greyed
> out)thin.updater(1)update(500)command #Bugs:update cannot be executed (is
> greyed out)set(beta1)command #Bugs:set cannot be executed (is greyed
> out)set(beta2)command #Bugs:set cannot be executed (is greyed
> out)set(beta3)command #Bugs:set cannot be executed (is greyed
> out)set(deviance)command #Bugs:set cannot be executed (is greyed
> out)dic.set()command #Bugs:dic.set cannot be executed (is greyed
> out)update(500)command #Bugs:update cannot be executed (is greyed
> out)coda(*,C:/Users/Gunal/AppData/Local/Temp/RtmpCYxtDZ/coda)command
> #Bugs:coda cannot be executed (is greyed out)stats(*)command #Bugs:stats
> cannot be executed (is greyed out)dic.stats()
>
DIChistory(*,C:/Users/Gunal/AppData/Local/Temp/RtmpCYxtDZ/history.odc)command
> #Bugs:history cannot be executed (is greyed
>
out)save(C:/Users/Gunal/AppData/Local/Temp/RtmpCYxtDZ/log.odc)save(C:/Users/Gunal/AppData/Local/Temp/RtmpCYxtDZ/log.txt)
>
> Any help would be greatly appreciated.
> Cheers
> Gunal
> [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
--
Bob O'Hara
Biodiversity and Climate Research Centre
Senckenberganlage 25
D-60325 Frankfurt am Main,
Germany
Tel: +49 69 798 40226
Mobile: +49 1515 888 5440
WWW: http://www.bik-f.de/root/index.php?page_id=219
Blog: http://occamstypewriter.org/boboh/
Journal of Negative Results - EEB: www.jnr-eeb.org
[[alternative HTML version deleted]]