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!

I am trying to fit a three level poisson model. WHen I just do it as two level model it runs fine, but when I add the third level in, i get an error message saying 'variables cannot be made random at level one in poisson models' but I have not included any random level 1 variables. Here is my code:

I have tried to sort the data using levID = c("zone", "household", "id") but when i include that in the model I still get the error about level 1 random and also another error saying 'syntax has been superseded, see help for guidance'.

Can anyone give me some pointers on where I am going wrong here?

Other than having < instead of <- in your second line, which shouldn't have an effect on the model, I can't see anything wrong with your specification. Can you check that example 11.3 in chapter 11 of the MCMC guide replication examples on https://www.bristol.ac.uk/cmm/software/ ... /examples/ works for you as this should be an equivalent model?

The option levID doesn't sort the data but is related to an older version of the function syntax so you shouldn't need to use that. If you did want to change options related to the data sorting then these are sort.force and sort.ignore. These will either sort the data for you based on what the function thinks the hierarchy is, or suppress any checks on how it is sorted.

Thanks very much for your reply, that was a mistake in my first post i do have a <- instead. I have tried the example data and code and that worked absolutely fine, but mine still does not. I have tried a simple version of the model with this code

and i get the error - "data is not sorted according to the model hierarchy". I have tried the same code with versions of sort.force and sort.ignore and neither work and I get the error again saying "variables cannot be made random at level one in Poisson models" and an additional error saying "this syntax has been superseded see help for guidance on converting it" and also "number of items to replace is not a multiple of replacement length"

If you look at the code for the runMLwiN function at https://github.com/r-forge/r2mlwin/blob ... runMLwiN.R you will see that the first message comes from line 601 and is only triggered if the levID option has been set. By default this is NULL and your syntax doesn't appear to set the option so I'm not sure why this is happening. One thing I do notice about your most recent code is that you are missing an closing bracket, but this might have just been missed when you did the copy/paste.

Do you have version of some data that has this same problem that you are able to share so that I can debug this in more detail?

Yes this was happening before I tried using levID anyway. Unfortunately the dataset is in a server with secure access so I cannot take any of the data out. As it is working with the example I wonder if it is something to do with my data. It is already in long format but I haven't done any sorting of any kind, does this need to be done?

I've had success with running a two level model in this way by using the group_by function in R, but the trouble is I don't know how to do that for a three level model so this has left me stuck

To get the right answers the data will need to be sorted (or you could potentially turn on the xc option as you are using MCMC). This should be as simple as:

Setting sort.force to TRUE is supposed to do this for you within the function.

If you set sort.ignore to TRUE then this will stop the check being run, so a model should fit but you will probably see the number of higher-level units reported is wrong with corresponding incorrect model results.

You could potentially try generating a fake dataset with a structure similar to yours and testing with that to see whether it works, which might indicate whether there is a particular aspect causing the problem.