0

I have a model of a few independent variables and one dependent one. I need to know how can I see if the addition of the interaction terms of two independent variable affect the dependent variable. I will also need to know how to put the interaction term in the model and how to decide if it actually affects it or not. Thanks

codewario
  • 19,553
  • 20
  • 90
  • 159
Ali H
  • 21
  • 1
  • 1
  • 5
  • If you can produce a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) -- what kind of model, what have you tried etc, this question may not get closed. – mnel Aug 15 '12 at 23:29

1 Answers1

1

You should look on cross validated

They have answered many questions like this.

But quickly:

say you have 6 independent variables x1,x2,...,x6

You believe all 6 independent vars have an effect on y, the dependent variable. You are interested in the interaction between two dependent variables,say x1 and x2.

Run one model with and one without the interaction term. The model without the interaction:

lm1=lm(y~x1+x2+x3+x4+x5+x6)

Then run the model with the interaction term

lm2=m(y~x1+x2+x3+x4+x5+x6 + x1:x2)

test to see if the larger model is significantly better fitting.

anova(lm1,lm2)

That gives something like:

Model 1: y ~ x1 + x2 + x3 ... 
Model 2: y ~ x1 + x2 + x3 + ... x1:x2
  Res.Df    RSS Df Sum of Sq      F    Pr(>F)    
1     96 235.79                                  
2     95 118.52  1    117.28 94.007 7.384e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

So the F is bigger than 2 we can reject the null that there is no effect of the interaction conditioned on the effects of x1, x2 and x3.

Community
  • 1
  • 1
Seth
  • 4,745
  • 23
  • 27
  • Thanks for your answer, I have a data already and through backward elimination i have gotten rid of a few independent variables , i am suppose to decide that an interaction term between 2 of the ind variables left affects the dependent one. Would this work in that situation. Thanks again – Ali H Aug 15 '12 at 23:39
  • I think you are describing the case just like this except you do not have an x3, so yes, this would work in that situation. – Seth Aug 15 '12 at 23:59
  • I forgot to mention i have six of them left and I am suppose to see if the interaction works with two of them, Can u explain the F bit again thanks – Ali H Aug 16 '12 at 00:06
  • When the F statistic gets bigger the p-value gets lower. The F statistic is a likelihood ratio statistic. I edited the answer to have more independent variables in it. Do you need a book on regression? – Seth Aug 16 '12 at 00:24
  • If you run the models I show and the anova gives a F smaller than about 2 and the Pr(>F) is bigger than 0.05, then you do not have evidence that the interaction coefficient is different than zero. – Seth Aug 16 '12 at 01:56
  • So if i have f =.671 then i cant say that the interaction affects the dependent – Ali H Aug 16 '12 at 01:59
  • Why not use AIC ? Built multiple model and compare them , select the model with the lowest AIC. But first, look at the intuition behind the variable ? Which variable do you expect to be interacting ? – Nico Coallier May 16 '17 at 17:51