Search code examples
rregressioninteraction

R - interactions between independent variable and polynomial term


I am interested in interacting an independent variable (sex) with a numerical independent variable of duration (working hours).

I am unsure what is the correct way to right down the equation.

y = sex * working_hours + I(working_hours^2) 

or do I need to interact both terms

y = sex * working_hours + sex * I(working_hours^2)  

I am interested in doing a mixed model here

lmer(y ~ sex * working_hours + I(working_hours^2) + (1 | id), data = df)

or

lmer(y ~ sex * working_hours + sex * I(working_hours^2) + (1 | id), data = df)

Thanks.


Solution

  • The right formula to use depends what you're trying to achieve.

    y = sex * working_hours + I(working_hours^2) will allow the linear part of the relationship between y and working hours to vary by sex, while the quadratic part of the relationship will be the same for both sexes. Put another way, if you plotted the fitted lines for each sex, the 'curvyness' of the relationship would be the same, but the 'tilt' of the curve would differ.

    y = sex * working_hours + sex * I(working_hours^2) will allow both the linear and quadratic parts of the relationship to vary by sex. If you plotted the fitted lines for each sex, both the 'tilt' and 'curvyness' of the relationship would differ between the sexes.

    To my way of thinking, the latter makes more sense - why would we assume the quadratic part of the relationship should be the same between the sexes if we're allowing the linear part to vary?