JuliaStats / MixedModels.jl

A Julia package for fitting (statistical) mixed-effects models
http://juliastats.org/MixedModels.jl/stable
MIT License
407 stars 48 forks source link

no method error in `VarCorr` #143

Closed kleinschmidt closed 6 years ago

kleinschmidt commented 6 years ago
julia> d = DataFrame(y = rand(100), x = rand(100), g = categorical(repeat(1:10, inner=10)));

julia> fit!(LinearMixedModel(@formula(y ~ 1 + x + (1+x|g)), d))
Linear mixed model fit by maximum likelihood
 Formula: y ~ 1 + x + ((1 + x) | g)
   logLik   -2 logLik     AIC        BIC
 -12.963898  25.927796  37.927796  53.558817

Error showing value of type LinearMixedModel{Float64}:
ERROR: MethodError: no method matching LinearAlgebra.Cholesky(::LinearAlgebra.LowerTriangular{Float64,Array{Float64,2}}, ::Char, ::Int64)
Closest candidates are:
  LinearAlgebra.Cholesky(::AbstractArray{T,2}, ::AbstractChar, ::Int32) where T at /build/julia/src/julia/usr/share/julia/stdlib/v1.0/LinearAlgebra/src/cholesky.jl:43
  LinearAlgebra.Cholesky(::LinearAlgebra.LowerTriangular) at /home/dave/.julia/packages/MixedModels/dn0WY/src/simulate.jl:119
  LinearAlgebra.Cholesky(::AbstractArray{T,2}, ::Symbol, ::Int32) where T at /build/julia/src/julia/usr/share/julia/stdlib/v1.0/LinearAlgebra/src/cholesky.jl:41
Stacktrace:
 [1] LinearAlgebra.Cholesky(::LinearAlgebra.LowerTriangular{Float64,Array{Float64,2}}) at /home/dave/.julia/packages/MixedModels/dn0WY/src/simulate.jl:126
 [2] stddevcor(::LinearAlgebra.LowerTriangular{Float64,Array{Float64,2}}) at /home/dave/.julia/packages/MixedModels/dn0WY/src/simulate.jl:114
 [3] stddevcor(::VectorFactorReTerm{Float64,UInt8,2}) at /home/dave/.julia/packages/MixedModels/dn0WY/src/simulate.jl:115
 [4] VarCorr(::LinearMixedModel{Float64}) at /home/dave/.julia/packages/MixedModels/dn0WY/src/types.jl:355
 [5] macro expansion at ./logging.jl:324 [inlined]
 [6] show(::IOContext{REPL.Terminals.TTYTerminal}, ::LinearMixedModel{Float64}) at /home/dave/.julia/packages/MixedModels/dn0WY/src/pls.jl:383
 [7] show(::IOContext{REPL.Terminals.TTYTerminal}, ::MIME{Symbol("text/plain")}, ::LinearMixedModel{Float64}) at ./sysimg.jl:194
 [8] display(::Any) at ./multimedia.jl:287
 [9] #invokelatest#1 at ./essentials.jl:697 [inlined]
 [10] invokelatest at ./essentials.jl:696 [inlined]
 [11] print_response(::IO, ::Any, ::Any, ::Bool, ::Bool, ::Any) at /build/julia/src/julia/usr/share/julia/stdlib/v1.0/REPL/src/REPL.jl:154
 [12] print_response(::REPL.AbstractREPL, ::Any, ::Any, ::Bool, ::Bool) at /build/julia/src/julia/usr/share/julia/stdlib/v1.0/REPL/src/REPL.jl:139
 [13] (::getfield(REPL, Symbol("#do_respond#40")){Bool,getfield(REPL, Symbol("##50#59")){REPL.LineEditREPL,REPL.REPLHistoryProvider},REPL.LineEditREPL,REPL.LineEdit.Prompt})(::Any, ::Any, ::Any) at /build/julia/src/julia/usr/share/julia/stdlib/v1.0/REPL/src/REPL.jl:708

Looks like it's coming from the call to VarCorr.

dmbates commented 6 years ago

What version of MixedModels are you using? I am unable to reproduce this with v1.1.0

julia> d = DataFrame(y = rand(100), x = rand(100), g = categorical(repeat(1:10, inner=10)));

julia> fit!(LinearMixedModel(@formula(y ~ 1 + x + (1+x|g)), d))
Linear mixed model fit by maximum likelihood
 Formula: y ~ 1 + x + ((1 + x) | g)
   logLik   -2 logLik     AIC        BIC
 -19.379665  38.759331  50.759331  66.390352

Variance components:
              Column              Variance                  Std.Dev.        Corr.
 g        (Intercept)  0.0000000000000000000000000000 0.00000000000000000
          x            0.0000000000000000000053969874 0.00000000007346419   NaN
 Residual              0.0862691034959976038587470271 0.29371602526249330
 Number of obs: 100; levels of grouping factors: 10

  Fixed-effects parameters:
              Estimate Std.Error  z value P(>|z|)
(Intercept)   0.479731 0.0528561  9.07617  <1e-18
x            -0.133372  0.101937 -1.30838  0.1907
kleinschmidt commented 6 years ago

Huh, I'm also on 1.0.1:

(infer-prior) pkg> status
    Status `~/work/writing/inprep/infer-prior/Project.toml`
  [a93c6f00] + DataFrames v0.14.1
  [1313f7d8] + DataFramesMeta v0.4.0
  [38e38edf] + GLM v1.0.1
  [ff71e718] + MixedModels v1.1.0
  [6f49c342] + RCall v0.12.1
  [3eaba693] + StatsModels v0.3.1
    Status `~/work/writing/inprep/infer-prior/Manifest.toml`
  [dce04be8] + ArgCheck v1.0.0
  [7d9fca2a] + Arpack v0.3.0
  [39de3d68] + AxisArrays v0.3.0
  [9e28174c] + BinDeps v0.8.10
  [b99e7846] + BinaryProvider v0.5.2
  [8e7c35d0] + BlockArrays v0.5.0
  [631607c0] + CMake v1.1.0
  [d5fb7624] + CMakeWrapper v0.2.2
  [324d7699] + CategoricalArrays v0.4.0
  [944b1d66] + CodecZlib v0.5.0
  [861a8166] + Combinatorics v0.7.0
  [34da2185] + Compat v1.3.0
  [8f4d0f93] + Conda v1.1.1
  [9a8bc11e] + DataStreams v0.4.1
  [864edb3b] + DataStructures v0.14.0
  [31c24e10] + Distributions v0.16.4
  [8197267c] + IntervalSets v0.3.0
  [c8e1da08] + IterTools v1.1.1
  [82899510] + IteratorInterfaceExtensions v0.1.1
  [682c06a0] + JSON v0.19.0
  [fdba3010] + MathProgBase v0.7.7
  [e1d29d7a] + Missings v0.3.1
  [76087f3c] + NLopt v0.5.1
  [86f7a689] + NamedArrays v0.9.1
  [bac558e1] + OrderedCollections v1.0.2
  [90014a1f] + PDMats v0.9.5
  [d96e819e] + Parameters v0.10.1
  [f27b6e38] + Polynomials v0.5.1
  [1fd47b50] + QuadGK v2.0.2
  [b3c3ace0] + RangeArrays v0.3.1
  [189a3867] + Reexport v0.2.0
  [ae029012] + Requires v0.5.2
  [79098fc4] + Rmath v0.5.0
  [992d4aef] + Showoff v0.2.1
  [a2af1166] + SortingAlgorithms v0.3.1
  [276daf66] + SpecialFunctions v0.7.1
  [90137ffa] + StaticArrays v0.8.3
  [2913bbd2] + StatsBase v0.25.0
  [4c63d2b9] + StatsFuns v0.7.0
  [3783bdb8] + TableTraits v0.3.1
  [bd369af6] + Tables v0.1.9
  [3bb67fe8] + TranscodingStreams v0.8.1
  [30578b45] + URIParser v0.4.0
  [81def892] + VersionParsing v1.1.3
  [ea10d353] + WeakRefStrings v0.5.3
  [1b915085] + WinReg v0.3.1
  [2a0f44e3] + Base64
  [ade2ca70] + Dates
  [8bb1440f] + DelimitedFiles
  [8ba89e20] + Distributed
  [9fa8497b] + Future
  [b77e0a4c] + InteractiveUtils
  [76f85450] + LibGit2
  [8f399da3] + Libdl
  [37e2e46d] + LinearAlgebra
  [56ddb016] + Logging
  [d6f4376e] + Markdown
  [a63ad114] + Mmap
  [44cfe95a] + Pkg
  [de0858da] + Printf
  [3fa0cd96] + REPL
  [9a3f8284] + Random
  [ea8e919c] + SHA
  [9e88b42a] + Serialization
  [1a1011a3] + SharedArrays
  [6462fe0b] + Sockets
  [2f01184e] + SparseArrays
  [10745b16] + Statistics
  [4607b0f0] + SuiteSparse
  [8dfed614] + Test
  [cf7118a7] + UUIDs
  [4ec0a83e] + Unicode

julia> VERSION
v"1.0.1"
kleinschmidt commented 6 years ago

The only thing I could think of is that I'm on Arch linux using the official package:

infer-prior/models on  master [$?]
➜ pacman -Qi julia
Name            : julia
Version         : 2:1.0.1-2
Description     : High-level, high-performance, dynamic programming language
Architecture    : x86_64
URL             : https://julialang.org/
Licenses        : MIT
Groups          : None
Provides        : None
Depends On      : cblas  fftw  hicolor-icon-theme  libgit2  libunwind  libutf8proc  openblas
                  suitesparse
Optional Deps   : gnuplot: If using the Gaston Package from julia
Required By     : None
Optional For    : None
Conflicts With  : None
Replaces        : None
Installed Size  : 171.77 MiB
Packager        : Eli Schwartz <eschwartz@archlinux.org>
Build Date      : Fri 05 Oct 2018 01:18:11 PM EDT
Install Date    : Tue 09 Oct 2018 02:51:26 PM EDT
Install Reason  : Explicitly installed
Install Script  : No
Validated By    : Signature

I'll try with the julia binaries and see...

kleinschmidt commented 6 years ago

okay with the official binaries it works as expected. very strange.

kleinschmidt commented 6 years ago

slack has concluded that this is caused by the Arch BLAS not being ILP64, so BlasInt is Int32 but size gives Int64 here: https://github.com/dmbates/MixedModels.jl/blob/04e8a5ffb0fbc49d189ef57cbcd3bb4cfb1d1a00/src/simulate.jl#L119

slack has also agreed that this is best fixed upstream even if @dmbates can be blamed for the type piracy :)

nalimilan commented 6 years ago

In the meantime, it wouldn't hurt to convert the value here too, so that the package works on existing Julia releases.