## What does the I do in formulas?

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/
GerineLodder
Posts: 42
Joined: Thu Jul 28, 2016 11:33 am

### What does the I do in formulas?

I noticed that in some formulas, there is an I before a new term, for instance:

Code: Select all

``````(mymodel11 <- runMLwiN(logit(a_point, cons, 6) ~ 1 + gcseavnormal[1:5] + gender[1:5] + I(gcseavnormal^2)[1:5] + (1[1:5] | school),
D = "Ordered Multinomial", estoptions = list(nonlinear = c(N = 1, M = 2)), data = alevchem))``````
Do I need to add this "I" every time I include a new variable?
So for instance if I would add an interaction it would be:

Code: Select all

``````(mymodel <- runMLwiN(logit(a_point, cons, 6) ~ 1 + gcseavnormal[1:5] + gender[1:5] + I(gsceavnormal*gender)[1:5] + (1[1:5] | school),
D = "Ordered Multinomial", estoptions = list(nonlinear = c(N = 1, M = 2)), data = alevchem))``````

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

### Re: What does the I do in formulas?

The I() tells R to treat the expression literally (see https://stat.ethz.ch/R-manual/R-devel/l ... /AsIs.html). In the first example that you gave omitting the I() would mean that gcseavnormal^2 would be interpreted as requesting the second order interactions of gcseavnormal, rather than gcseavnormal squared. In your second example gsceavnormal*gender without the I() would result in terms for gcseavnormal, gender and the interaction of the two being added. For details of the R formula specification see https://stat.ethz.ch/R-manual/R-devel/l ... rmula.html.