easystats / easystats/performance
r2 failing for `nlme::lme()`
Open
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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