How can I make cross level interactions?

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
dcanarteg
Posts: 14
Joined: Tue Feb 05, 2019 9:30 pm

How can I make cross level interactions?

Post by dcanarteg » Tue Feb 19, 2019 12:08 am

I've made lots of progress with my models, but got stuck again because I cannot find how to code cross-level interactions (level 2 * level 1).
Here is my model as I ran it incorrectly assuming the use of asterisks (*)

This is my model

############# Adding Network and Cross-level predictors #####################
m5 = logit(AltAnySupport) ~ 1 + TieFam+ Married + Woman +
EgoTMig + AltFem + AltEth + AltNat + AltResidence + NetPropFemCen + NetPropFamCen +
NetPropIsEthCen + NetPropNatCen + NetPropResidCen + EgoTMig * AltEth + Woman * AltEth +
EgoTMig * TieSameSex + (1 | EgoIdentifier)
(VarCompModel <- runMLwiN(Formula = m5, D = "Binomial", data = MyData,
estoptions = list(EstM = 1)))

After running this model I got this error
>Error in `[.data.frame`(indata, , outvars) : undefined columns selected

So far I've found info here but is for MLWiN in which cross-level interactions are specified as 'ccXtvXprethks' with 'X" indicating multiplication.
https://orca.cf.ac.uk/113202/1/MLwiN%20 ... Models.pdf

Many Thanks

ChrisCharlton
Posts: 1090
Joined: Mon Oct 19, 2009 10:34 am

Re: How can I make cross level interactions?

Post by ChrisCharlton » Tue Feb 19, 2019 5:18 pm

R2MLwiN formulae are based on the standard used in other R estimation commands (https://stat.ethz.ch/R-manual/R-devel/l ... rmula.html).

Asterisk (*) should work, however a*b denotes a + b + a:b rather than just the interaction. You would therefore either use a colon (:) to specify the interaction term or remove the associated main effects from elsewhere in the formula if you want to use an asterisk. I also note that you have the variable TieSameSex in an interaction without a main effect, is this intentional?

dcanarteg
Posts: 14
Joined: Tue Feb 05, 2019 9:30 pm

Re: How can I make cross level interactions?

Post by dcanarteg » Tue Feb 19, 2019 10:20 pm

The "TieSameSex" was a mistake. I edited a bit the formula before submitting to simplify reading but messed it up.

I ran the following model and...

############# Random Intercept # Adding Network and Cross-level predictors #####################
m5 = logit(AltAnySupport) ~ 1 + TieIsFamily + TieSameSex + TieSameAge + EgoMarital + EgoSex +
EgoTMig + AltSex + AltIsRoma + AltNatRomanian + AltResidence + NetPropFemCen + NetPropFamCen +
NetPropIsRomaCen + NetPropNatRomanianCen + NetPropResidCen + EgoTMig:AltIsRoma + EgoSex:AltIsRoma +
EgoTMig:TieSameSex + (1 | EgoIdentifier)
(VarCompModel <- runMLwiN(Formula = m5, D = "Binomial", data = RomaAllData,
estoptions = list(EstM = 1)))

Gave me this error below which I found that is a bug
>Error in `[.data.frame`(indata, , outvars) : undefined columns selected

http://www.bristol.ac.uk/cmm/software/r ... nbugs.html

I reordered the order of the interactions and it worked!! :)

Many Thanks

ChrisCharlton
Posts: 1090
Joined: Mon Oct 19, 2009 10:34 am

Re: How can I make cross level interactions?

Post by ChrisCharlton » Wed Feb 20, 2019 9:45 am

I am glad to hear that you now have something that works. Thanks for reminding me about this bug, it is actually already fixed in the development version which we are currently working on submitting to CRAN. If you wanted to install this you can do so with the following command:

Code: Select all

library(devtools)
install_github("rforge/r2mlwin", subdir="R2MLwiN")
However as we expect this to be on CRAN relatively soon you could potentially wait for this and pick it up from there instead.

Post Reply