yoo
yoo

Reputation: 511

interaction term in multilevel analysis using lmer() function

level 1 variable:

income - continuous 

level 2 variable:

state's general whether: three leveled categorical variable: hot/moderate/cool

         used effect coded, and generate two variables because it has three levels.
        (weather_ef1, weather_ef2)  


enrolled in university - binary : yes/no  ( effect coded. yes = -1, no =1) 

DV: math score

grouping variable: household

model 1: (fixed slope)

Dv is predicted by income, enrollment, and the interaction between enrollment and income. in this case,

lmer(y~ 1 + income + enrollment +income*enrollment+ (1|householdID), data=data)
lmer(y~ 1 + income + enrollment +income:enrollment+ (1|householdID), data=data)

: is it for interaction? or * is it for interaction?

further, do I have to do factor(enrollment)? or is it okay because it is already effect coded?

model 2: (fixed slope)

DV is predicted by income, weather, and interaction between income and weather

lmer( y ~ 1 + income  + weather_ef1 + weather_ef2 + weather_ef1*income
 + weather_ef2*income +(1|houshold_id), data) 

lmer ( y ~ l + income + weather_ef1+ weather_ef2 + weather_ef1:income 
+ weather_ef2:income  + (1|houshold_id), data)

Still confusing * is right or: is right.

I think the effect code variables are already effect coded, so I don't have to do use the factor(weather_ef1) things.

Upvotes: 1

Views: 1024

Answers (1)

George Savva
George Savva

Reputation: 5336

From the documentation (use ?formula):

The * operator denotes factor crossing: a*b interpreted as a+b+a:b.

In other words a*b adds the main effects of a and b and their interaction. So in your model when you use income*enrollment this is the same as income + enrollment +income:enrollment. The two versions you described for each model should give identical results. You could just have used:

lmer(y~ 1 + income*enrollment+ (1|householdID), data=data)

which also describes the same model.

If your variables are effect coded then you don't need to use factor but be careful about the interpretation of the effects.

Upvotes: 1

Related Questions