Error when attempting to estimate a multiple membership model

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
DanMSwan
Posts: 4
Joined: Thu Nov 17, 2016 5:47 pm

Error when attempting to estimate a multiple membership model

Post by DanMSwan »

Following the format of the vignette for multiple membership data, I ran this code:


mm <- list(list(
mmvar = list("MM_s1", "MM_s2", "MM_s3"),
weights = list("w1", "w2", "w3")),NA)

Funcet <- S6Read ~ 1 + S3Read + wFL + (1|MM_s1)

uncentlm <- runMLwiN(Formula = Funcent, data = mlwin_dat,
estoptions = list(EstM = 1, drop.data= FALSE, mm = mm))

When I run that code, I get the attached error in MLwiN
mlwin error.png
mlwin error.png (8.35 KiB) Viewed 6488 times
The error doesn't make a lot of sense to me - since I'm drawing on an R dataframe for the data, all of the variables vectors should be of the same length. Can you give me any insight? I can't find any information on how the MULM command functions so I don't know what that means (although I assume it's saying the multiple membership is at level 2, has 3 membership classifications, and the weights start at the variable w1, but I'm not sure).

Any thoughts?
DanMSwan
Posts: 4
Joined: Thu Nov 17, 2016 5:47 pm

Re: Error when attempting to estimate a multiple membership model

Post by DanMSwan »

And just in case it comes up, my membership/weight columns are sequential so that should not be an issue.

> names(mlwin_dat)
[1] "ID" "MM_s1" "MM_s2" "MM_s3" "S6Read"
[6] "S3Read" "wFL" "S3Read_gm" "S3Read_clus" "wcMean"
[11] "w1" "w2" "w3" "intercept"
ChrisCharlton
Posts: 1353
Joined: Mon Oct 19, 2009 10:34 am

Re: Error when attempting to estimate a multiple membership model

Post by ChrisCharlton »

I am not sure what would be causing this error. Could you add debugmode=TRUE to your estoptions so that MLwiN pauses before fitting the model, and then take a look at the "names" window to make sure that the lengths look right there and that the columns are still consecutive?
DanMSwan
Posts: 4
Joined: Thu Nov 17, 2016 5:47 pm

Re: Error when attempting to estimate a multiple membership model

Post by DanMSwan »

It's all the same length and still sequential.

In fact, if I run through the process manually i.e. estimate an IGLS model for starting values then switch to MCMC and set the classification to multiple membership the model estimates just fine.

Something has occurred to me in the interim - some of the clusters numbers don't appear until the second or third set of clusters. Could that be causing problems?
ChrisCharlton
Posts: 1353
Joined: Mon Oct 19, 2009 10:34 am

Re: Error when attempting to estimate a multiple membership model

Post by ChrisCharlton »

I don't think that this has anything to do with the ID values as the error message that you are getting is related to a check that simply compares the length of each of the multiple membership IDs, plus the corresponding level ID to ensure that they are the same length. Looking again at what you posted before I do notice a couple of things.

Firstly you are assigning the formula to a variable called Funcet, however the formula you pass to R2MLwiN is Funcent (notice the extra n), so it would be worth making sure that the formula being used is what you expect.

Secondly the formula has only one level ID, so MM_s1 will be used as a level-1 ID and there will be no level-2 ID (see http://www.bristol.ac.uk/cmm/media/r2ml ... CGuide16.R for examples of multiple membership). This might explain what you are seeing as MLwiN will be comparing the length of an empty column with the multiple membership columns. This does not however explain why it works if you run the model manually.
DanMSwan
Posts: 4
Joined: Thu Nov 17, 2016 5:47 pm

Re: Error when attempting to estimate a multiple membership model

Post by DanMSwan »

The first part is because I'm having to remote desktop into a computer that is not the computer I am posting from to use MLwiN. I did encounter the issue of the model typo and fixed it in the code on the remote desktop (but not the copy on this computer).

I think I probably breezed through the text around the example a little too quickly. Do I need to specify the level 1 random component in the model command ala (1|ID) assuming that I have some variable called ID that represents individuals?

EDIT: That is indeed the problem! Thanks for your help with this. Everything works beautifully now.
ChrisCharlton
Posts: 1353
Joined: Mon Oct 19, 2009 10:34 am

Re: Error when attempting to estimate a multiple membership model

Post by ChrisCharlton »

I'm glad to hear that you now have it working. Yes, you do need to specify a level-1 ID for normal response models (although this can just be a sequence of 1..number of observations). This is because you might want to specify complex level-1 variation (see http://www.bristol.ac.uk/cmm/media/r2ml ... CGuide09.R). For non-normal response types you shouldn't specify a level-1 ID when using R2MLwiN.
Post Reply