# How to get a GLM where formula is programmatically generated

**URL:** <https://discourse.julialang.org/t/how-to-get-a-glm-where-formula-is-programmatically-generated/43519>\
**Category:** New to Julia\
**Tags:** dataframes, glm\
**Created:** [July 22, 2020, 9:41pm UTC](https://discourse.julialang.org/t/how-to-get-a-glm-where-formula-is-programmatically-generated/43519 "2020-07-22T21:41:24Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![dave.f.kleinschmidt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dave.f.kleinschmidt/32/55_2.png) [@dave.f.kleinschmidt](https://discourse.julialang.org/u/dave.f.kleinschmidt)\
**Post date:** [August 16, 2020, 4:08pm UTC](https://discourse.julialang.org/t/how-to-get-a-glm-where-formula-is-programmatically-generated/43519/3 "2020-08-16T16:08:57Z")

</div>

Cameron is exactly right. These two forms are exactly equivalent:

```julia
julia> using StatsModels

julia> (Term(:y) ~ Term(:x1) + Term(:x2)) == @formula(y ~ x1 + x2)
true

```

As @nilshg pointed out in [this post](https://discourse.julialang.org/t/using-all-independent-variables-with-formula-in-a-multiple-linear-model/43691/5), this is actually the expression that’s generated by the formula macro:

```julia
julia> @macroexpand @formula(y ~ x1 + x2)
:(StatsModels.Term(:y) ~ StatsModels.Term(:x1) + StatsModels.Term(:x2))

```

---

_[View the full topic](https://discourse.julialang.org/t/how-to-get-a-glm-where-formula-is-programmatically-generated/43519)._
