[R] Variable Combinations in Regression
    David Winsemius 
    dwinsemius at comcast.net
       
    Fri Jan  8 23:25:50 CET 2010
    
    
  
On Jan 8, 2010, at 3:26 PM, Richardson, Patrick wrote:
> Let's say I have 8 variables and I want to generate all combinations  
> of those variables (In pairs, threes fours, etc) to run in multiple  
> linear regression. Is there a built-in function to do that in R?
The formula syntax allows that.
y ~ (x1 + x2 + x3 + x4 + x5)^2   for instance,  would give you all 5  
of the main effects and the ten two way interaction estimates. With  
the "exponent set to three you also get the three way interactions  
(although I have never tried this particular level of dredging.)  
Unless you have scientific arguments for higher level interactions,  
they are a major threat to interpretability and validity as well as a  
threat to convergence.
(With 8 variables you are going to experience a combinatorial  
explosion: 28 two-way terms, 56 3-way, 70 4-way and then down the  
other side of Pascal's triangle.)
>
> Or at a minimum, how could I take those variables and generate all  
> possible combinations.
>
> Thank you for any assistance.
>
-- 
David Winsemius, MD
Heritage Laboratories
West Hartford, CT
    
    
More information about the R-help
mailing list