Using R2MLwiN to write BUGS code

Welcome to the forum for R2MLwiN users. Feel free to post your question about R2MLwiN here. The Centre for Multilevel Modelling take no responsibility for the accuracy of these posts, we are unable to monitor them closely. Do go ahead and post your question and thank you in advance if you find the time to post any answers!

Go to R2MLwiN: Running MLwiN from within R >> http://www.bris.ac.uk/cmm/software/r2mlwin/
Post Reply
MannyGomez
Posts: 17
Joined: Mon Feb 17, 2014 4:55 pm

Using R2MLwiN to write BUGS code

Post by MannyGomez »

Hi,

I'm trying to use R2MLwiN to write some BUGS code of a bivariate mixed model, but I'm getting the error below:

mod<- runMLwiN(Formula ="c(y1, probit(y2,cons)) ~ (0s|cons+treat) + (1s|cons.y1) + (2s|cons)",
D=c("Mixed", "Normal", "Binomial"), levID = c("cluster", "id"), indata = data,
estoptions=list(x64=TRUE, EstM=1, show.file = T,
mcmcMeth = list(burnin = 1000, iterations = 5000, thinning = 1)),
BUGO = c(version = 4, n.chains = 1, debug = T, seed = 12146, bugs = "C:/Program
Files/WinBUGS14/WinBUGS14.exe", OpenBugs = F), MLwiNPath = 'C:/Program Files (x86)/MLwiN v2.29' )


Warning messages:
1: In runMLwiN(Formula = eq.y, D = c("Mixed", "Normal", "Binomial"), :
The Mixed response model is currently not implemented in WinBUGS/OpenBUGS.
2: In file.remove(modelfile) :
cannot remove file 'C:/Users/mgomes/AppData/Local/Temp/RtmpQvWPs1/modelfile_1f386ddd5173.txt', reason 'No such file or directory'
Error in print(summary(chains.bugs.mcmc)) :
error in evaluating the argument 'x' in selecting a method for function 'print': Error in summary(chains.bugs.mcmc) :
error in evaluating the argument 'object' in selecting a method for function 'summary': Error: object 'chains.bugs.mcmc' not found


I was trying to double check whether the mixed model I manually wrote in Winbugs (attached) was matching that produced by R2MLwiN?
Any help would be great.
Thanks,
Manny
Attachments
nbin.pdf
mixed model winbugs
(126.47 KiB) Downloaded 479 times
billb
Posts: 157
Joined: Fri May 21, 2010 1:21 pm

Re: Using R2MLwiN to write BUGS code

Post by billb »

Hi MannyGomez,
There is a reason why we haven't implemented bivariate mixtures in the MLwiN -> BUGS interface. Basically BUGS struggles with covariance matrices that have constraints in them - in the case of the model you have one variance is constrained to 1 and what you have done in this part of your model looks like it will get around that in the simple case of 2 responses (1 binary and 1 normal) although it will result in a different prior. Generalising to several responses and maintaining
a positive definite covariance matrix would be harder
The problem in what you are doing is that u[cluster,2] is now an overdispersion effect on top of the Binomial variation and NOT equivalent to what we do in MLwiN. In MLwiN what we do is generate a latent Normal response y2* which is positive when y2 is 1 and negative when y2 is 0 and this will then be equivalent to the probit link model for y2 as long as the variance of y2* is fixed at 1 and then we can look at correlations between y2* and y1. What you have done is looked at correlations between any overdispersion in the binary response and the normal response - strictly speaking overdispersion in a binary response doesn't make sense so what you are trying is not that sensible.
Hope that helps,
Bill.
billb
Posts: 157
Joined: Fri May 21, 2010 1:21 pm

Re: Using R2MLwiN to write BUGS code

Post by billb »

Hi Manny,
Apologies half asleep when I wrote the earlier reply and read your code too quickly. The u terms in your model are simply higher level terms and so they are fine and clustering here is fine. The question is really whether one can construct a correlation between the 2 responses at level 1 without creating a latent normal variable. You are doing this with a conditional formulation i.e. conditioning on the residuals from response y1 in the equation for response 2 and using the link between regression and correlation to construct a correlation coefficient. I think maybe Peter Congdon possibly suggested this in one of his books and it might be a method that works though I'm not sure it's 100% equivalent as prior might be slightly different.
My suggestion is to compare estimates and see what you get.
Best wishes,
Bill.
MannyGomez
Posts: 17
Joined: Mon Feb 17, 2014 4:55 pm

Re: Using R2MLwiN to write BUGS code

Post by MannyGomez »

Bill,
Many thanks for your detailed response.
I will compare this approach with the latent Normal variable (Albert and Chib, 1993) and I will let you know.
Best,
Manny
Post Reply