I have a data frame with colnames A, B, C, D with numeric values. I am trying to generate a linear regression model using variables and trying all the possible combination like A, A+B, A+C, B, B+C ....
I am having trouble generating combinations with data frame.
Data frame
DependentVar A B C D
I am trying to generate something like this:
Combinations of independent variables like:
var <- A,B,C,D,A+B,A+C,A+D,B+C,B+D,C+D,A+B+C,A+B+D and so on..
for (v in var){
models <- lm (DependentVar ~ eval(parse(text=v)), data=data)
r2 <- append(summary(models)$r.squared)
}
Output like dataframe:
Variable combination Model R2
A 0.8
B 0.7
.
.
and so on
Any help will be greatly appreciated!