How to create a loop for a regression model?

The recommended way of constructing formulas programmatically is to use Terms (or the term function) like so:

[lm(Term(i) ~ Term(:X1) + Term(:X2), data) for i in list]

this is discussed in the docs here.

10 Likes