Suppose I am regressing
y = x1 + x4
where x4 = x2 - x3
In R, there is a function I()
such that I don't have to create a new variable x4 in my data set, but can simply write
y = x1 + I(x2 - x3)
See details here: What does the capital letter "I" in R linear regression formula mean?
Is there a similar way to do this in Python? For instance using statsmodels.formula.api
or the sklearn