Page 1 of 1

How can I make cross level interactions?

Posted: Tue Feb 19, 2019 12:08 am
by dcanarteg
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

Re: How can I make cross level interactions?

Posted: Tue Feb 19, 2019 5:18 pm
by ChrisCharlton
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?

Re: How can I make cross level interactions?

Posted: Tue Feb 19, 2019 10:20 pm
by dcanarteg
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

Re: How can I make cross level interactions?

Posted: Wed Feb 20, 2019 9:45 am
by ChrisCharlton
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.