title: Regression model with all possible two way interaction terms in r
body: <p>I have a data set with 8 variables. I need all possible two way interaction terms along with the seven predictors in each model. So, in my case there will be total 7C2 = 21 models, each of them containing the 7 predictors and a two way interaction term at a time.</p>
  
  <p>I have tried to produce the 21 models using for loop but the code seems to fail at the lm() function when I try to use that inside the for loop. In my problem return is the response variable at the 5-th column of my data.</p>
  
  <pre class="lang-r prettyprint-override"><code>colnames(dt) = c("assets","turnover_ratio","SD","sharpe_ratio","return",
                   "expense_ratio","fund_dummy","risk_dummy")
  vars=colnames(dt)[-5] 
  for (i in vars)  {
    for (j in vars) {
      if (i != j) {
        factor= paste(i,j,sep='*')}
      lm.fit &lt;- lm(paste("return ~", factor), data=dt)
      print(summary(lm.fit))
    }}
  </code></pre>
  
  <p>The error message is given below for the code:</p>
  
  <blockquote>
    <p>Error in paste("return ~", factor) : 
      cannot coerce type 'closure' to vector of type 'character'</p>
  </blockquote>
  
  <p>This is my data set:
  <img src="https://i.stack.imgur.com/TRKFf.png" alt="data set"></p>
  
  <p>The output below should be the desired output and 20 more such models are needed with other possible two way interaction terms. All the 7 predictors should be present in each model. The only thing that should change is the two way interaction term. </p>
  
  <p>This is my desired output among the 21 required: 
  <img src="https://i.stack.imgur.com/46SYd.png" alt="one desired output among the 21 required outputs"></p>