# How can we extract the individual random slopes from a MixedModel.jl fit?

**URL:** <https://discourse.julialang.org/t/how-can-we-extract-the-individual-random-slopes-from-a-mixedmodel-jl-fit/21780>\
**Category:** Statistics\
**Created:** [March 12, 2019, 12:58pm UTC](https://discourse.julialang.org/t/how-can-we-extract-the-individual-random-slopes-from-a-mixedmodel-jl-fit/21780 "2019-03-12T12:58:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![arnaudmgh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/arnaudmgh/32/7134_2.png) [@arnaudmgh](https://discourse.julialang.org/u/arnaudmgh)\
**Post date:** [March 12, 2019, 12:58pm UTC](https://discourse.julialang.org/t/how-can-we-extract-the-individual-random-slopes-from-a-mixedmodel-jl-fit/21780/1 "2019-03-12T12:58:20Z")

</div>

In `R` package `lme4`, the function `coef` seems to return slopes for each level of the factor, but in Julia `coef` returns only fixed effects. (see [r - Extracting slopes for cases from a mixed effects model (lme4) - Cross Validated](https://stats.stackexchange.com/questions/122009/extracting-slopes-for-cases-from-a-mixed-effects-model-lme4)).

Is there a way to get the individual slopes like in R?

```julia
using RData, MixedModels
const dat = Dict(Symbol(k)=>v for (k,v) in
    load(joinpath(dirname(pathof(MixedModels)), "..", "test", "dat.rda")));
sleepstudy = deepcopy(dat[:sleepstudy])
names!(sleepstudy, [:Reaction, :Days, :Subject])
fm1 = fit(LinearMixedModel, @formula(Reaction ~ Days + (Days|Subject)), sleepstudy)

coef(fm1)
# 2-element Array{Float64,1}:
# 251.40510484848375
# 10.467285959596053

```

```julia

```

---

<div class="post-metadata">

**Author:** ![ianfiske](https://avatars.discourse-cdn.com/v4/letter/i/58f4c7/32.png) [@ianfiske](https://discourse.julialang.org/u/ianfiske)\
**Post date:** [March 12, 2019, 2:47pm UTC](https://discourse.julialang.org/t/how-can-we-extract-the-individual-random-slopes-from-a-mixedmodel-jl-fit/21780/2 "2019-03-12T14:47:51Z")

</div>

From [http://dmbates.github.io/MixedModels.jl/stable/constructors/#Conditional-modes-of-the-random-effects-1](http://dmbates.github.io/MixedModels.jl/stable/constructors/#Conditional-modes-of-the-random-effects-1), looks like the `ranef` function gives you conditional modes of the random effects.

---

<div class="post-metadata">

**Author:** ![arnaudmgh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/arnaudmgh/32/7134_2.png) [@arnaudmgh](https://discourse.julialang.org/u/arnaudmgh)\
**Post date:** [March 12, 2019, 5:36pm UTC](https://discourse.julialang.org/t/how-can-we-extract-the-individual-random-slopes-from-a-mixedmodel-jl-fit/21780/3 "2019-03-12T17:36:46Z")

</div>

awesome, just what I needed - thanks!
