# Using all independent variables with @formula in a multiple linear model

**URL:** https://discourse.julialang.org/t/using-all-independent-variables-with-formula-in-a-multiple-linear-model/43691
**Category:** New to Julia
**Tags:** glm
**Created:** [July 26, 2020, 1:22am UTC](https://discourse.julialang.org/t/using-all-independent-variables-with-formula-in-a-multiple-linear-model/43691 "2020-07-26T01:22:04Z")
**Posts on this page:** 1
**Showing post:** 5

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [July 27, 2020, 8:01am UTC](https://discourse.julialang.org/t/using-all-independent-variables-with-formula-in-a-multiple-linear-model/43691/5 "2020-07-27T08:01:35Z")

</div>

To slightly expand on Peter’s answer, what you tried originally was essentially constructing the `Term`s twice, as the `@formula` macro converts its arguments to Terms already. It being a macro, it ultimately has to generate some code that you could have written yourself by hand. To see this:

```julia
julia> using MacroTools

julia> @macroexpand @formula(Y ~ X1 + X2)
:(StatsModels.Term(:Y) ~ StatsModels.Term(:X1) + StatsModels.Term(:X2))

julia> @formula(Y ~ X1 + X2) == (Term(:Y) ~ Term(:X1) + Term(:X2))
true

```

---

_[View the full topic](https://discourse.julialang.org/t/using-all-independent-variables-with-formula-in-a-multiple-linear-model/43691)._
