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

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!

using StatsModels, MixedModels, JuliaDB, DataFrames
function testlmm(
    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(
        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")
    print(propertynames(lmm, true), "\n")

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

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.

Thanks for the suggestion.

In REPL, I have

>pkgs = Pkg.installed();

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

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:

(: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:

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

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.

1 Like

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).