# Possible reasons that MixedModels would not create the property "sigmas"?

**URL:** <https://discourse.julialang.org/t/possible-reasons-that-mixedmodels-would-not-create-the-property-sigmas/34073>\
**Category:** Statistics\
**Tags:** question\
**Created:** [February 2, 2020, 5:28am UTC](https://discourse.julialang.org/t/possible-reasons-that-mixedmodels-would-not-create-the-property-sigmas/34073 "2020-02-02T05:28:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kai](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@kai](https://discourse.julialang.org/u/kai)\
**Post date:** [February 2, 2020, 5:28am UTC](https://discourse.julialang.org/t/possible-reasons-that-mixedmodels-would-not-create-the-property-sigmas/34073/1 "2020-02-02T05:28:26Z")

</div>

I want to fit a linear mixed model inside my function and extract estimates of random effect standard deviations (`sigmas` from a `LinearMixedModel` object).

So I wrote the following function, and it runs perfectly in REPL or ipynb.

However, if I put this function (exactly the same function) into my package and run it through the `test` command for packages, the property `sigmas` no longer shows up in the list of property names. I checked that the model was fit successfully, and other properties such as `beta` and `sigma` were all present, but somehow `sigmas` were not.

I just cannot understand why. Any help is appreciated. Thanks!

```julia
using StatsModels, MixedModels, JuliaDB, DataFrames
function testlmm(
    file::String,
    f::FormulaTerm,
    id_name::String
)
    lhs_name = [string(x) for x in StatsModels.termvars(f.lhs)]
    rhs_name = [string(x) for x in StatsModels.termvars(f.rhs)]

    ftable = JuliaDB.loadtable(
        file, 
        datacols = filter(x -> x != nothing, vcat(lhs_name, rhs_name))
    )
    
    df = DataFrame(ftable)

    categorical!(df, Symbol(id_name))

    lmm = LinearMixedModel(f, df)

    print(propertynames(lmm, true), "\n")
    
    MixedModels.fit!(lmm)
    
    print(propertynames(lmm, true), "\n")
end

# I saved the sleep study dataset as a csv
test("sleepstudy.csv", @formula(Reaction ~ 1 + Days + (Days | Subject)), "Subject") 

```

---

<div class="post-metadata">

**Author:** ![dave.f.kleinschmidt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dave.f.kleinschmidt/32/55_2.png) [@dave.f.kleinschmidt](https://discourse.julialang.org/u/dave.f.kleinschmidt)\
**Post date:** [February 3, 2020, 5:20pm UTC](https://discourse.julialang.org/t/possible-reasons-that-mixedmodels-would-not-create-the-property-sigmas/34073/2 "2020-02-03T17:20:00Z")

</div>

Are you sure that the same version of MixedModels.jl is being used in REPL/jupyter and in your package’s tests? Tests run in their own “sandbox” environment and so the versions could be different.

---

<div class="post-metadata">

**Author:** ![kai](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@kai](https://discourse.julialang.org/u/kai)\
**Post date:** [February 3, 2020, 6:14pm UTC](https://discourse.julialang.org/t/possible-reasons-that-mixedmodels-would-not-create-the-property-sigmas/34073/3 "2020-02-03T18:14:52Z")

</div>

Thanks for the suggestion.

In REPL, I have

```julia
>pkgs = Pkg.installed();
>pkgs["MixedModels"]
v"2.1.2"

```

From the `Manifest.toml` file of my package, I have

```julia
[[MixedModels]]
deps = ["BlockArrays", "CategoricalArrays", "Distributions", "GLM", "LinearAlgebra", "NLopt", "NamedArrays", "Printf", "ProgressMeter", "Random", "Showoff", "SparseArrays", "StaticArrays", "Statistics", "StatsBase", "StatsFuns", "StatsModels", "Tables", "TypedTables"]
git-tree-sha1 = "a11e7c98d13cfefa3bfbdb87b057004cb0c1b9b3"
uuid = "ff71e718-51f3-5ec2-a782-8ffcbfa3c316"
version = "2.1.2"

```

So it seems like they are both using v2.1.2.

Here is what I get by running `propertynames(lmm)` in REPL:

```julia
(:formula, :sqrtwts, :A, :L, :optsum, :θ, :theta, :β, :beta, :λ, :lambda, :stderror, :σ, :sigma, :σs, :sigmas, :b, :u, :lowerbd, :X, :y, :rePCA, :reterms, :feterms, :objective, :pvalues)

```

Here is what I get by running `propertynames(lmm)` in package:

```julia
(:formula, :sqrtwts, :A, :L, :optsum, :θ, :theta, :β, :beta, :λ, :lambda, :stderror, :σ, :sigma, :b, :u, :lowerbd, :X, :y, :rePCA, :reterms, :feterms, :objective, :pvalues)

```

---

<div class="post-metadata">

**Author:** ![kai](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@kai](https://discourse.julialang.org/u/kai)\
**Post date:** [February 5, 2020, 10:04pm UTC](https://discourse.julialang.org/t/possible-reasons-that-mixedmodels-would-not-create-the-property-sigmas/34073/4 "2020-02-05T22:04:51Z")

</div>

It turns out that it was a version problem. After removing the `MixedModels` entries from `Project.toml` and `Manifest.toml`, and re-added `MixedModels` as a dependency, the package passed test.

---

<div class="post-metadata">

**Author:** ![dave.f.kleinschmidt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dave.f.kleinschmidt/32/55_2.png) [@dave.f.kleinschmidt](https://discourse.julialang.org/u/dave.f.kleinschmidt)\
**Post date:** [February 16, 2020, 10:11pm UTC](https://discourse.julialang.org/t/possible-reasons-that-mixedmodels-would-not-create-the-property-sigmas/34073/5 "2020-02-16T22:11:53Z")

</div>

Good, glad that fixed it. Note that the tests can have their own versions of things installed if there’s a Project.toml/Manifest.toml in the tests/ directory. Or, if you have a local Manifest.toml with an old version, but it’s not committed to git, then you might get a newer/different version when you run the tests on CI (which installs everything from scratch).
