# Residuals from LinearMixed Models (Julia 0.6.3)

**URL:** <https://discourse.julialang.org/t/residuals-from-linearmixed-models-julia-0-6-3/12103>\
**Category:** General Usage\
**Tags:** question\
**Created:** [July 2, 2018, 6:28pm UTC](https://discourse.julialang.org/t/residuals-from-linearmixed-models-julia-0-6-3/12103 "2018-07-02T18:28:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Harish\_Kumar](https://avatars.discourse-cdn.com/v4/letter/h/4bbf92/32.png) [@Harish\_Kumar](https://discourse.julialang.org/u/Harish_Kumar)\
**Post date:** [July 2, 2018, 6:28pm UTC](https://discourse.julialang.org/t/residuals-from-linearmixed-models-julia-0-6-3/12103/1 "2018-07-02T18:28:29Z")

</div>

I am in the process of migrating the Julia .3.2 version to 0.6.3 … We had a function/variable in 0.3.2 “resid” to extract the residual from the model. Do we have any equivalent function in 0.6.3?

lmm= fit!(LinearMixedModel(@formula(A~ 1 + B+ C+ ( ( 0 + B) | byVar) + ( ( 0 + C) | byVar) ),df),true)  
lmm.resid?

Regards,  
Harish

---

<div class="post-metadata">

**Author:** ![dmbates](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmbates/32/44_2.png) [@dmbates](https://discourse.julialang.org/u/dmbates)\
**Post date:** [July 2, 2018, 9:11pm UTC](https://discourse.julialang.org/t/residuals-from-linearmixed-models-julia-0-6-3/12103/2 "2018-07-02T21:11:25Z")

</div>

It is best to use the generic extractor functions from the `StatsBase`

```julia
julia> m1 = fit(LinearMixedModel, @formula(Y ~ 1 + (1|G)), dat[:Dyestuff])
Linear mixed model fit by maximum likelihood
 Formula: Y ~ 1 + (1 | G)
   logLik -2 logLik AIC BIC
 -163.66353 327.32706 333.32706 337.53065

Variance components:
              Column Variance Std.Dev.
 G (Intercept) 1388.3332 37.260344
 Residual 2451.2500 49.510100
 Number of obs: 30; levels of grouping factors: 6

  Fixed-effects parameters:
             Estimate Std.Error z value P(>|z|)
(Intercept) 1527.5 17.6946 86.326 <1e-99

julia> StatsBase.residuals(m1)
30-element Array{Float64,1}:
  34.1282
 -70.8718
 -70.8718
   9.12822
  69.1282
  12.1305
  27.1305
 -37.8695
  32.1305
 -32.8695
  40.5253
  -4.47467
  50.5253
 -44.4747
   5.52533
 -60.6986
 -65.6986
  89.3014
 -40.6986
  39.3014
  13.9202
  48.9202
 -66.0798
  53.9202
  43.9202
  34.9943
 -30.0057
 -35.0057
  -5.00566
 -40.0057

```

If you depend upon a field name by using, e.g., `lmm.resid`, then everything falls apart when the internal representation changes, which, in my packages, it does frequently. My favorite Oscar Wilde quote is

> Consistency is the last refuge of the unimaginative.

For the next release (not the one from earlier today), I’ll reexport the `residuals` name so you don’t need to use `using StatsBase` or `StatsBase.residuals`.

---

<div class="post-metadata">

**Author:** ![Harish\_Kumar](https://avatars.discourse-cdn.com/v4/letter/h/4bbf92/32.png) [@Harish\_Kumar](https://discourse.julialang.org/u/Harish_Kumar)\
**Post date:** [July 2, 2018, 10:06pm UTC](https://discourse.julialang.org/t/residuals-from-linearmixed-models-julia-0-6-3/12103/3 "2018-07-02T22:06:16Z")

</div>

> [@dmbates](#):
>
> , I’ll reexport the `resi`

Thank you.;
