1
$\begingroup$

I have two two-level categorical variables, IV1 and IV2. I want to fit a linear model in R and find out the simple effect of IV1 on the DV at each level of IV2, separately. I'm not interested in the overall effect of IV1.

Is it correct to sum-code IV1, dummy-code IV2, and fit this model:

lm(DV ~ IV1 * IV2, data=dat)

Then interpret the main effect of IV1 as the effect of IV1 on DV at the reference level of IV2.

$\endgroup$
1
$\begingroup$

If the sum-code for IV1 is coded as you explained then you need to tweak your code to tell R that IV1 and IV2 is categorical

lm(DV ~ factor(IV1) * factor(IV2), data=dat) 

then if there is a significant interaction you can not interpret the main effects of IV1 and IV2 solely. So you interpret the main effect for IV1 as the effect of IV1 on the DV for a FIXED level of IV2 (so at the default reference level for R so if dummy coded then when IV2 is 0). Then you would add the interaction effect to the main effect for IV1 to find the effect of IV1 on the DV at FIXED level of IV2 =1.

$\endgroup$
  • $\begingroup$ The column IV1 is stored as a factor, and I'm using contrasts(dat$IV1) <- contr.sum(2) / 2, so it should properly interpret IV1 as a factor. Is the interpretation of the main effect in the model output different if both variables are dummy-coded (factors)? $\endgroup$ – user2034412 Jul 17 '15 at 19:22
  • $\begingroup$ Well it doesn't hurt anything to wrap the factor function around it. Yes it would be different in regards to how many levels there are of IV1 there are. $\endgroup$ – Lauren Goodwin Jul 17 '15 at 19:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.