# ALL SYNTAX GIVEN BELOW IS EQUIVALENT
# Use a modified WinBUGS text file with manual inits and manual data and a seperate monitor block (requires least modification from a WinBUGS file). For compatibility with WinBUGS, the use of list() to enclose data and initial values is allowed and ignored, however all seperate variables in the data and inits blocks must be seperated with a line break (commas or semicolons before linebreaks are ignored). 'data{' and 'inits{' must also be added to WinBUGS textfiles so that the function can seperate data from initial values. See also the differences in JAGS versus WinBUGS syntax in the JAGS help file.
# Contents of a textfile 'mymodel.bug':
model{
for(i in 1:N){
Count[i] ~ dpois(mean)
}
mean ~ dgamma(0.01, 100)
}
data{
list(Count <- c(1,2,3,4,5,6,7,8,9,10),
N <- 10)
}
inits{
list(
mean <- 1)
}
inits{
list(
mean <- 100)
}
monitor{
mean
}
# end text file
read.winbugs('pathtofile/mymodel.bug')
# Use internal character variable, define monitors in the model, use autodata and manual initial values:
string <- "
model{
for(i in 1:N){
Count[i] ~ dpois(mean) #data# Count, N
}
mean ~ dgamma(0.01, 100)
#monitor# mean
}
inits{
mean <- 1
}
inits{
mean <- 100
}
"
read.winbugs(string)
# Use autoinits and a mixture of manual and autodata:
string <- "
model{
for(i in 1:N){
Count[i] ~ dpois(mean) #data# Count
}
mean ~ dgamma(0.01, 100)
#monitor# mean
#inits# mean
}
data{
N <- 10
}
"
read.winbugs(string)
Run the code above in your browser using DataLab