Hello, I have a WinBUGS newbie question I would greatly appreciate some help with:-
Can anyone see why I keep getting a WinBUGS " incompatible copy" error for the following code?
I am trying to run an ordinal regression model from Gelman and Hill. Frustratingly, I can get the more complex multi-level model from Chapt 17 to work, but not this simpler model from Chpt 6!
Thanks,
Duncan
#
# write model to file
sink("Bugs_ordinal_regression_unilevel.txt")
cat("
model {
for (i in 1:n){
y[i] ~ dcat(P[i,])
P[i,1] <- 1 - Q[i,1]
for (i.cut in 2:n.cut){P[i,i.cut] <- Q[i,i.cut-1] - Q[i,i.cut]}
P[i,n.cut+1] <- Q[i,n.cut]
# P[i,n.cut+1] <- 1 - sum(P[i,1:n.cut])
for (i.cut in 1:n.cut){
logit(Q[i,i.cut]) <- Z[i,i.cut] # I changed z to Z
Z[i,i.cut] <- (x[i] - cutoffs[i.cut])/sigma
}
}
# Priors
cutoffs[1] ~ dunif(0,100)
for (i.cut in 2:n.cut){
cutoffs[i.cut] ~ dunif(cutoffs[i.cut-1],100]
}
sigma ~ dlnorm(0,0.0001)I(1,100)
}
",fill=TRUE)
sink()
n <- 20
n.cut <- 2
# Bundle data from truncated data set just for person 401
# > chpt6.data.401
# $x
# [1] 40 4 44 23 99 82 81 75 71 66 79 10 45 67 24 68 20 60 50 13
#
# $y
# [1] 2 1 3 1 3 2 3 3 3 3 3 1 2 2 1 2 1 2 2 1 # 3 levels of the ordinal response, so there should be 2 cutoffs
#
# $n
# [1] 20
#
# $n.cut
# [1] 2
#
# Inits fn
# note that the initialisation for the vector of cut-offs ensures that
# the cut-offs are monotonically increasing.
#
inits <- function(){list(sigma=runif(1,1,100), cutoffs=sort(runif(n.cut,0,100)))}
# Params to estimate
params <- c("sigma","cutoffs")
# MCMC settings
nc <- 3
ni <- 2000
nb <- 500
nt <- 1
require(R2WinBUGS)
out <- bugs(data=chpt6.data.401, inits=inits, parameters.to.save=params,
model.file="Bugs_ordinal_regression_unilevel.txt",
n.thin=nt, n.chains=nc, n.burnin=nb, n.iter=ni, debug=TRUE,
bugs.directory="C:\\WinBUGS14", working.directory = getwd())
# end of code
______________________________________________________________________________
Dr. Duncan Mackay
School of Biological Sciences
Flinders University
GPO Box 2100
Adelaide
S.A. 5001
AUSTRALIA
Phone 61-8-82012627
FAX 61-8-82013015
http://www.flinders.edu.au/people/duncan.mackay
-------------------------------------------------------------------
This list is for discussion of modelling issues and the BUGS software.
For help with crashes and error messages, first mail [log in to unmask]
To mail the BUGS list, mail to [log in to unmask]
Before mailing, please check the archive at www.jiscmail.ac.uk/lists/bugs.html
Please do not mail attachments to the list.
To leave the BUGS list, send LEAVE BUGS to [log in to unmask]
If this fails, mail [log in to unmask], NOT the whole list
|