easystats / easystats/performance

r2 failing for `nlme::lme()`

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

Nobody has claimed this yet.

Bug :bug:
Dominant language
R
Stars
1.2k
Forks
109
Avg merge
6h 34m
Merged PRs (30d)
8

Description

library(nlme)

nlme::lme(Reaction ~ 1, random = ~ 1 | Subject, data = lme4::sleepstudy) |> 
  performance::r2()
#> Warning: Can't compute random effect variances. Some variance components equal
#>   zero. Your model may suffer from singularity (see '?lme4::isSingular'
#>   and '?performance::check_singularity').
#>   Solution: Respecify random structure! You may also decrease the
#>   'tolerance' level to enforce the calculation of random effect variances.
#> Random effect variances not available. Returned R2 does not account for random effects.
#> # R2 for Mixed Models
#> 
#>   Conditional R2: NA
#>      Marginal R2: 0.000

nlme::lme(Reaction ~ Days, random = ~ 1 | Subject, data = lme4::sleepstudy) |>  
  performance::r2()
#> Warning: Can't compute random effect variances. Some variance components equal
#>   zero. Your model may suffer from singularity (see '?lme4::isSingular'
#>   and '?performance::check_singularity').
#>   Solution: Respecify random structure! You may also decrease the
#>   'tolerance' level to enforce the calculation of random effect variances.
#> Random effect variances not available. Returned R2 does not account for random effects.
#> # R2 for Mixed Models
#> 
#>   Conditional R2: NA
#>      Marginal R2: 0.486

Compare the same models to lme4 which don't fail and give different results:

lme4::lmer(Reaction ~ (1 | Subject), data = lme4::sleepstudy) |> 
  performance::r2()
#> # R2 for Mixed Models
#> 
#>   Conditional R2: 0.395
#>      Marginal R2: 0.000

lme4::lmer(Reaction ~ Days + (1 | Subject), data = lme4::sleepstudy) |> 
  performance::r2()
#> # R2 for Mixed Models
#> 
#>   Conditional R2: 0.704
#>      Marginal R2: 0.280

Created on 2022-06-26 by the reprex package (v2.0.1)

Contributor guide

Open the 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.

Research direction

Start by reproducing the two nlme::lme() examples through performance::r2(), then compare them with the corresponding lme4::lmer() results shown in the issue. Trace the performance::r2() handling for nlme mixed models and identify why random-effect variances are unavailable; done means the nlme results calculate conditional and marginal R2 without the reported warning and agree with the expected model behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.