# Bug in StatsModels.modelmatrix()

**URL:** https://discourse.julialang.org/t/bug-in-statsmodels-modelmatrix/69428
**Category:** Data
**Created:** [October 8, 2021, 12:29pm UTC](https://discourse.julialang.org/t/bug-in-statsmodels-modelmatrix/69428 "2021-10-08T12:29:02Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![tomtom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomtom/32/5106_2.png) [@tomtom](https://discourse.julialang.org/u/tomtom)
#### Post date: [October 8, 2021, 1:26pm UTC](https://discourse.julialang.org/t/bug-in-statsmodels-modelmatrix/69428/2 "2021-10-08T13:26:20Z")

</div>

I’m closer to the problem. The term `a & a` and `b & b` got the type `InteractionTerm{ContinuousTerm{Float64}}`, that cannot be handled properly, instead of `InteractionTerm{Tuple{ContinuousTerm{Float64}, ContinuousTerm{Float64}}}`:

```julia
julia> fml2
FormulaTerm
Response:
  y(unknown)
Predictors:
  1
  a(unknown)
  b(unknown)
  a(unknown) & a(unknown)
  a(unknown) & b(unknown)
  b(unknown) & b(unknown)

julia> typeof(sfml2.rhs.terms[1])
InterceptTerm{true}

julia> typeof(sfml2.rhs.terms[2])
ContinuousTerm{Float64}

julia> typeof(sfml2.rhs.terms[3])
ContinuousTerm{Float64}

julia> typeof(sfml2.rhs.terms[4])
InteractionTerm{ContinuousTerm{Float64}}

julia> typeof(sfml2.rhs.terms[5])
InteractionTerm{Tuple{ContinuousTerm{Float64}, ContinuousTerm{Float64}}}

julia> typeof(sfml2.rhs.terms[6])
InteractionTerm{ContinuousTerm{Float64}}

```

so, for the time being we **need to explicitly create the square terms** like:

```julia
fml3 = @formula(y ~ 1 + a + (a ^ 2) + (a & b) + b + (b ^ 2));

julia> modelmatrix(fml3, df)
3×6 Matrix{Float64}:
 1.0 1.0 1.0 2.0 4.0 2.0
 1.0 2.0 4.0 3.0 9.0 6.0
 1.0 3.0 9.0 4.0 16.0 12.0

```

in order the avoid the problem.

---

_[View the full topic](https://discourse.julialang.org/t/bug-in-statsmodels-modelmatrix/69428)._
