Binary outcome 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
Llambert
Posts: 2
Joined: Thu Nov 02, 2023 9:13 pm

Binary outcome Multiple membership model

Post by Llambert »

Hello -
I am struggling to specify a binary outcome multiple membership model. I've tried logit(outcome) and binomial(outcome, denom) [denom is a column of ones]. I keep getting an error - any guidance would be much appreciated, including if it's even possible. Thanks!
ChrisCharlton
Posts: 1354
Joined: Mon Oct 19, 2009 10:34 am

Re: Binary outcome Multiple membership model

Post by ChrisCharlton »

I think that you would need to post your full syntax before we can determine what is going wrong. If you haven't already seen we do provide example syntax for bother multiple membership and binary response models at https://www.bristol.ac.uk/cmm/software/ ... /examples/.
Llambert
Posts: 2
Joined: Thu Nov 02, 2023 9:13 pm

Re: Binary outcome Multiple membership model

Post by Llambert »

ChrisCharlton wrote: Wed Nov 08, 2023 2:17 pm I think that you would need to post your full syntax before we can determine what is going wrong. If you haven't already seen we do provide example syntax for bother multiple membership and binary response models at https://www.bristol.ac.uk/cmm/software/ ... /examples/.
R syntax I am using is:

log_model2 <- logit(stay, denom) ~ 1 + s_SATc + tot_exp + (1|tchr1) + (1|s_ID)

MultiMemb <- list(list(
mmvar = list("tchr1", "tchr2", "tchr3", "tchr4", "tchr5", "tchr6", "tchr7", "tchr8"),
weights = list("w1", "w2", "w3", "w4", "w5", "w6", "w7", "w8")), NA)

MMembModel <- runMLwiN(Formula = log_model2,
data = d,
D = 'Binomial',
estoptions = list(EstM = 1, drop.data = FALSE, mm = MultiMemb))

The model is a multiple membership model with a binary outcome. It will run using IGLS, but thinks there are three levels (there's only two). It will not run using MCMC. I would rather use IGLS, as I am more familiar with a frequentist view, but am not opposed to MCMC.

I appreciate any guidance that can be given.
ChrisCharlton
Posts: 1354
Joined: Mon Oct 19, 2009 10:34 am

Re: Binary outcome Multiple membership model

Post by ChrisCharlton »

Thanks for this additional information.

Unfortunately MLwiN does not support fitting multiple membership models with (R)IGLS, other than using the constraint tricks detailed in chapter 19 of the MLwiN User's Guide which are not supported in R2MLwiN.

When specifying discrete response models in R2MLwiN you should only include the higher levels in the model formula. This is because the level-1 variance is fixed for these model types. You can find examples of logit modes in MLwiN user's guide chapter 9 and MCMC guide chapter 10. Examples of multiple membership models can be found in MCMC guide chapter 16.
dtaylor7
Posts: 6
Joined: Tue Dec 12, 2023 5:08 pm

Re: Binary outcome Multiple membership model

Post by dtaylor7 »

Hello,

On the topic of multiple membership binary outcome models, I am currently attempting to fit one. Upon running the runMLwiN command - after around a minute the following error is given.

"Error in foreign::read.dta(chainfile) :
unable to open file: 'No such file or directory"

When using debugmode=TRUE in estoptions, the MLwiN interface instead gives the error:

MCMC error 0142: The 2th MM unit for obs 37667 is a duplicate of the 1th MM unit.

After double checking the data it appears that the 37667th row actually has different values of Reader1 and Reader2, and that Reader1 and Reader2 do not have the same ID at any point in the data. Is there any other explanation for this error? Strangely the same model worked fine yesterday.

My current call is:

mmdat = list(NA,list(mmvar = list("Reader1","Reader2"),weights = list("weight1","weight2")),NA)
finalModelNull = runMLwiN(logit(FinalDecision,cons) ~ 1 + (1 | Centre) + (1 | Reader1),D = "Binomial",estoptions = list(debugmode = TRUE,resi.store=TRUE,mcmcMeth=list(nchains=1),EstM = 1,xc=FALSE,mcmcOptions = list(orth = 1,hcen=2),mm=mmdat),data=dat2)

Thank you very much.
ChrisCharlton
Posts: 1354
Joined: Mon Oct 19, 2009 10:34 am

Re: Binary outcome Multiple membership model

Post by ChrisCharlton »

Are you checking the data from with R or MLwiN? I would suggest turning on debugmode=TRUE again and then browsing the data as it is in MLwiN via the Data window, as it's possible that it isn't being sent correctly from R to MLwiN. The message that you're seeing is only triggered if the software comes across two rows with the same value between two or more of the ID columns.

I also note that you have specified xc=FALSE, however choosing multiple membership in the MLwiN MCMC engine implies that the model is cross-classified, so I don't know if that is confusing things.
dtaylor7
Posts: 6
Joined: Tue Dec 12, 2023 5:08 pm

Re: Binary outcome Multiple membership model

Post by dtaylor7 »

Hi Chris, after checking the data within MLwiN using debugmode the variables at line 37667 did not have the same value, being displayed as 13 and 14, however after clicking "show value labels" they both had the same value of 13.000. I believe I fixed the error by not setting the multiple membership random effects as factors within R, however I am now facing a different error:

"error while obeying batch file
C:/users/.../Local/Temp/RtmpSyZb9N/macrofile_46b07058964 at line number 91:
STAR

duplicate name."

I haven't named any variables 'STAR' within my data as far as I know, do you know what could be causing this?
ChrisCharlton
Posts: 1354
Joined: Mon Oct 19, 2009 10:34 am

Re: Binary outcome Multiple membership model

Post by ChrisCharlton »

Thanks for this extra information. From what you say I think that the problem was that R isn't aware that the different ID columns making up the multiple membership are in any related. When you make a factor variable R will set the underlying value to 1..N where N is the number of unique values and then put a label on each of these. Because it doesn't know of the relationship between them this means that the same original number could be mapped differently in each factor (and if there aren't the same unique values in each this is pretty much guaranteed to happen). You could probably get around this by using the levels option when creating the factor to specify the superset of possible values.

The duplicate name error is generated when MLwiN attempts to assign a name of a column that is already assigned to a different column. STARt is the command to start estimating an (R)IGLS model, so if there error is coming from within this it may be that you have a data column with the same name as something this is trying to create. I can't tell what this is from the error message, but it might be cons as there are certain situations where this is automatically generated by the software. You could test this by the renaming your version.

Looking at your command again I notice that you have both multiple membership turned on and cross-classification turned off. As multiple membership requires cross-classification one of these options will probably be ignored, so you might want to adjust the command to reflect this.
Post Reply