# Julia equivalent of the R function \`model.matrix\`

**URL:** <https://discourse.julialang.org/t/julia-equivalent-of-the-r-function-model-matrix/49325>\
**Category:** General Usage\
**Tags:** statistics\
**Created:** [October 30, 2020, 7:46pm UTC](https://discourse.julialang.org/t/julia-equivalent-of-the-r-function-model-matrix/49325 "2020-10-30T19:46:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![stla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stla/32/20382_2.png) [@stla](https://discourse.julialang.org/u/stla)\
**Post date:** [October 30, 2020, 7:46pm UTC](https://discourse.julialang.org/t/julia-equivalent-of-the-r-function-model-matrix/49325/1 "2020-10-30T19:46:37Z")

</div>

Hello,

Is there a Julia function equivalent to the R function `model.matrix`? This R function returns the design matrix of a linear regression model. For example `model.matrix(~ group + treatment + group:treatment, data = dat)` returns the design matrix of the linear regression model with main effects `group` and `treatment` and with the interaction between `group` and `treatment`, looking in the `dat` dataframe to find these variables.

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [October 30, 2020, 8:01pm UTC](https://discourse.julialang.org/t/julia-equivalent-of-the-r-function-model-matrix/49325/2 "2020-10-30T20:01:51Z")

</div>

Yes. I believe it is called `modelmatrix` 😉

It’s in the StatsModels.jl package

---

<div class="post-metadata">

**Author:** ![stla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stla/32/20382_2.png) [@stla](https://discourse.julialang.org/u/stla)\
**Post date:** [October 31, 2020, 7:08pm UTC](https://discourse.julialang.org/t/julia-equivalent-of-the-r-function-model-matrix/49325/3 "2020-10-31T19:08:16Z")

</div>

Ok, thanks. Will try soon.
