JuliaStats / MixedModels.jl

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

Type inference fails for logdet(m) and pwrss(m) and, hence for objective(m) #770

Closed dmbates closed 3 months ago

dmbates commented 3 months ago

For a LinearMixedModel{T} where {T} I thought there was enough information to infer the type of the value of pwrss and logdet, hence ensuring successful type inference on objective. That is not the case.

julia> using MixedModels

julia> m1 = let f = @formula(yield ~ 1 + (1|batch)),
           d = MixedModels.dataset(:dyestuff)

           fit(MixedModel, f, d)
       end
Linear mixed model fit by maximum likelihood
 yield ~ 1 + (1 | batch)
   logLik   -2 logLik     AIC       AICc        BIC    
  -163.6635   327.3271   333.3271   334.2501   337.5307

Variance components:
            Column    Variance Std.Dev.
batch    (Intercept)  1388.3332 37.2603
Residual              2451.2501 49.5101
 Number of obs: 30; levels of grouping factors: 6

  Fixed-effects parameters:
────────────────────────────────────────────────
              Coef.  Std. Error      z  Pr(>|z|)
────────────────────────────────────────────────
(Intercept)  1527.5     17.6946  86.33    <1e-99
────────────────────────────────────────────────

julia> @code_warntype pwrss(m1)
MethodInstance for MixedModels.pwrss(::LinearMixedModel{Float64})
  from pwrss(m::LinearMixedModel) @ MixedModels ~/.julia/dev/MixedModels/src/linearmixedmodel.jl:898
Arguments
  #self#::Core.Const(MixedModels.pwrss)
  m::LinearMixedModel{Float64}
Body::Any
1 ─ %1 = Base.getproperty(m, :L)::Vector{AbstractMatrix{Float64}}
│   %2 = MixedModels.last(%1)::AbstractMatrix{Float64}
│   %3 = MixedModels.last(%2)::Any
│   %4 = MixedModels.abs2(%3)::Any
└──      return %4