# Two questions about GLM

**URL:** https://discourse.julialang.org/t/two-questions-about-glm/10376
**Category:** Statistics
**Tags:** glm
**Created:** [April 16, 2018, 9:31pm UTC](https://discourse.julialang.org/t/two-questions-about-glm/10376 "2018-04-16T21:31:25Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![mwsohn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mwsohn/32/2696_2.png) [@mwsohn](https://discourse.julialang.org/u/mwsohn)
#### Post date: [April 16, 2018, 9:31pm UTC](https://discourse.julialang.org/t/two-questions-about-glm/10376/1 "2018-04-16T21:31:25Z")

</div>

I have noticed that I could not use a CategoricalArray as the dependent variable for a logistic regression. When I convert the binary dependent variable into a Float64, then I can estimate the model without any problem.

Question 1: Is there any way that GLM be modified such that it takes a CategoricalArray as the dependent variable?

I think this is a nice service to the users, especially for models that require binary values in the dependent variable.

Question 2: Is there an example of how to use “contrasts” in the GLM model? I have a CategoricalArray with 4 levels and want to use level “2” as the base. I have read the StatsModels documentation on DummyCoding() but could not make it work.

---

<div class="post-metadata">

### Author: ![Nosferican](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nosferican/32/9275_2.png) [@Nosferican](https://discourse.julialang.org/u/Nosferican)
#### Post date: [April 16, 2018, 11:01pm UTC](https://discourse.julialang.org/t/two-questions-about-glm/10376/3 "2018-04-16T23:01:01Z")

</div>

1. Categorical outcome responses lead to a multinomial distribution (multinomial or ordinal depending on whether `isordered` assuming the `LogitLink`). `Distributions.jl` has the multinomial distribution and `StatsFuns.jl` has the softmax function. However, GLM has does not support multinomial or categorical models yet (except for `Binomial` / logit). It is currently a feature request [#206](https://github.com/JuliaStats/GLM.jl/issues/206).
2. For specifying contrasts,

```julia
using DataFrames, GLM
rand(0)
data = DataFrame(y = rand(10), x1 = rand(1:3, 10))
categorical!(data, :x1)
glm(@formula(y ~ x1), data, Normal(), IdentityLink()) # Uses default level
glm(@formula(y ~ x1), data, Normal(), IdentityLink(), contrasts = Dict(:x1 => DummyCoding(base = 2))) # Uses 2 as the base level

```

---

<div class="post-metadata">

### Author: ![mwsohn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mwsohn/32/2696_2.png) [@mwsohn](https://discourse.julialang.org/u/mwsohn)
#### Post date: [April 17, 2018, 12:11am UTC](https://discourse.julialang.org/t/two-questions-about-glm/10376/4 "2018-04-17T00:11:52Z")

</div>

Thank you so much.

---

<div class="post-metadata">

### Author: ![amrods](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amrods/32/2543_2.png) [@amrods](https://discourse.julialang.org/u/amrods)
#### Post date: [September 7, 2021, 5:25am UTC](https://discourse.julialang.org/t/two-questions-about-glm/10376/5 "2021-09-07T05:25:32Z")

</div>

Still no support for multinomial models? in particular ordered logit?

---

<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: [September 7, 2021, 5:55am UTC](https://discourse.julialang.org/t/two-questions-about-glm/10376/6 "2021-09-07T05:55:59Z")

</div>

[https://nosferican.github.io/Econometrics.jl/stable/estimators/#Ordinal-Response-Models-1](https://nosferican.github.io/Econometrics.jl/stable/estimators/#Ordinal-Response-Models-1)
