# StatsModels R-like formula for a general quadratic model

**URL:** <https://discourse.julialang.org/t/statsmodels-r-like-formula-for-a-general-quadratic-model/64441>\
**Category:** Statistics\
**Created:** [July 10, 2021, 11:29pm UTC](https://discourse.julialang.org/t/statsmodels-r-like-formula-for-a-general-quadratic-model/64441 "2021-07-10T23:29:14Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![joergbuchwald](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joergbuchwald/32/13112_2.png) [@joergbuchwald](https://discourse.julialang.org/u/joergbuchwald)\
**Post date:** [July 11, 2021, 6:39pm UTC](https://discourse.julialang.org/t/statsmodels-r-like-formula-for-a-general-quadratic-model/64441/6 "2021-07-11T18:39:53Z")

</div>

> [@nilshg](#):
>
> `sum(length(x) == 1 ? term(only(x)) : (&)(term.(x)...) for x ∈ combinations([:a, :b, :c]))`

Based on your solution, the problem can be solved by

```julia
a = sum(InteractionTerm(term.((only(x),only(x)))) for x ∈ combinations([:a, :b, :c],1))
b = sum((&)(term.(x)...) for x ∈ combinations([:a, :b, :c],2))
c = sum(term(only(x)) for x ∈ combinations([:a, :b, :c],1))
formula = Term(:y) ~ a + b +c + ConstantTerm(1)

```

Although an even shorter form would be nice indeed.

---

_[View the full topic](https://discourse.julialang.org/t/statsmodels-r-like-formula-for-a-general-quadratic-model/64441)._
