Deviance for families with dispersion parameter

Open
#206 0 comments 0 reactions 0 assignees View on GitHub

@palday is already working on this.

Since Feb 26, 2020.

  • #291 by @palday — open
  • #914 by @palday — open

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
32/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
julia
Domain
data

Research direction

Start in generalizedlinearmixedmodel.jl around line 301, the location shown in the loglikelihood stack trace, and trace how GLMM deviance and loglikelihood are computed for Gamma families. Compare the Julia and R outputs in the issue; done means the family dispersion parameter is included consistently and the affected calculations handle the reported Gamma case.

Written by the indexing model from the issue text.

Description

bug

Currently, the dispersion parameter for families with one isn't taken into account when calculating the deviance for GLMMs. For example, in Julia we have:

julia> lexdec_glmm_gamma
Generalized Linear Mixed Model fit by maximum likelihood (nAGQ = 1)
  rt_raw ~ 1 + Class + NativeLanguage + Class & NativeLanguage + (1 | Subject) + (1 | Word)
  Distribution: Gamma{Float64}
  Link: IdentityLink()

  Deviance: 91.9052

Variance components:
             Column    Variance Std.Dev. 
 Word    (Intercept)     0.0000  0.00000
 Subject (Intercept)  1508.7803 38.84302
 Number of obs: 1659; levels of grouping factors: 79, 21

Fixed-effects parameters:
──────────────────────────────────────────────────────────────────────────────
                                       Estimate  Std.Error    z value  P(>|z|)
──────────────────────────────────────────────────────────────────────────────
(Intercept)                           563.552      6.69785  84.1393     <1e-99
Class: plant                            6.43673    9.20547   0.699229   0.4844
NativeLanguage: Other                 114.543     11.2587   10.1737     <1e-23
Class: plant & NativeLanguage: Other  -29.3668    15.495    -1.89524    0.0581
──────────────────────────────────────────────────────────────────────────────

julia> loglikelihood(lexdec_glmm_gamma)
ERROR: MethodError: no method matching Gamma{Float64}(::Float64)
Closest candidates are:
  Gamma{Float64}(::Any, ::Any) where T at /home/XXX/.julia/packages/Distributions/Vcqls/src/univariate/continuous/gamma.jl:30
Stacktrace:
 [1] loglikelihood(::GeneralizedLinearMixedModel{Float64}) at /home/XXX/Work/MixedModels.jl/src/generalizedlinearmixedmodel.jl:301
 [2] top-level scope at none:0

But in R we have:

R> summary(lexdec_glmm_gamma)
Generalized linear mixed model fit by maximum likelihood (Laplace
  Approximation) [glmerMod]
 Family: Gamma  ( identity )
Formula: rt_raw ~ 1 + Class * NativeLanguage + (1 | Subject) + (1 | Word)
   Data: lexdec

     AIC      BIC   logLik deviance df.resid 
 20339.4  20377.3 -10162.7  20325.4     1652 

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-1.7910 -0.5810 -0.1798  0.3265  8.2691 

Random effects:
 Groups   Name        Variance  Std.Dev.
 Word     (Intercept) 1.533e+03 39.1482 
 Subject  (Intercept) 1.915e+03 43.7595 
 Residual             4.142e-02  0.2035 
Number of obs: 1659, groups:  Word, 79; Subject, 21

Fixed effects:
                               Estimate Std. Error t value Pr(>|z|)    
(Intercept)                     588.839     11.955  49.255   <2e-16 ***
Classplant                        4.894     11.218   0.436   0.6627    
NativeLanguageOther             115.619     13.578   8.515   <2e-16 ***
Classplant:NativeLanguageOther  -28.138      9.379  -3.000   0.0027 ** 
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Correlation of Fixed Effects:
            (Intr) Clsspl NtvLnO
Classplant  -0.109              
NtvLnggOthr -0.044 -0.071       
Clsspln:NLO  0.039 -0.085  0.034

R> deviance(lexdec_glmm_gamma)
[1] 52.56222
R> -2 * logLik(lexdec_glmm_gamma)
'log Lik.' 20325.38 (df=7)

See also lme4/lme4#375.

Dominant language
Julia
Stars
455
Forks
51
Avg merge
3d 15h
Merged PRs (30d)
4

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from JuliaStats/MixedModels.jl

All issues in JuliaStats/MixedModels.jl

Similar issues

More Julia issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.