Page 1 of 1

What does the I do in formulas?

Posted: Tue Feb 06, 2018 9:40 am
by GerineLodder
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))

Re: What does the I do in formulas?

Posted: Tue Feb 06, 2018 1:35 pm
by ChrisCharlton
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.