Displaying 3 results from an estimated 3 matches for "independent_vars".
2025 Mar 29
1
[External] Creating model formulas programmatically
The general formula is y ~ a + b + c + ...
There is this approach:
formula <- reformulate(independent_vars, response = "y")
model <- lm(formula, data = mydata)
summary(model)
It does not generate a string object, but the formula is still a string even if it is of class formula. Also, in this approach you only get + and if you want interactions or such you will need to code them into indepe...
2025 Mar 30
1
[External] Creating model formulas programmatically
...ay)^2
is still a problem with no solution that I know of but paste/as.formula.
Or Bert's bquote or substitute.
Rui Barradas
?s 23:18 de 29/03/2025, Ebert,Timothy Aaron escreveu:
> The general formula is y ~ a + b + c + ...
>
> There is this approach:
> formula <- reformulate(independent_vars, response = "y")
> model <- lm(formula, data = mydata)
> summary(model)
>
> It does not generate a string object, but the formula is still a string even if it is of class formula. Also, in this approach you only get + and if you want interactions or such you will need to c...
2025 Mar 29
2
[External] Creating model formulas programmatically
Thanks, Rich.
I thought of that, too, but it violates the spirit of my restraints (to
avoid character strings), which I unfortunately did not clearly articulate.
So my apologies for that failure. My concern is that with more complex
model formula, using as.formula, etc. to parse/convert character strings
can get a bit hairy. But in most cases, as here maybe, it may be perfectly
fine. So think of