Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] estimate_grouplevel() #429

Merged
merged 20 commits into from
Mar 2, 2025
Merged

[fix] estimate_grouplevel() #429

merged 20 commits into from
Mar 2, 2025

Conversation

DominiqueMakowski
Copy link
Member

@DominiqueMakowski DominiqueMakowski commented Mar 1, 2025

  • Example in docstrings mentions outdated deviation=TRUE argument
  • Function throws some error with glmmTMB it seems
  • Better clean up of names for brms
  • Add the indices="all" and group="all" filtering capabilities (available in reshape_grouplevel()) as part of the main function too No need anymore, can just filter the output
  • type argument doesn't work for brms (better addressed in Add option to pull coef() instead of ranef() for random effects parameters#1067)

@DominiqueMakowski
Copy link
Member Author

DominiqueMakowski commented Mar 1, 2025

One main improvement is to sanitize the brms naming to be closer to standard outputs, but it requires some regex

  data <- iris
  data$Group <- as.factor(rep(c("G1", "G2", "G3"), each = 50))

  model <- glmmTMB::glmmTMB(Sepal.Width ~ Petal.Width + (Petal.Width | Group), data = data)

  modelbased::estimate_grouplevel(model)
#> Group | Level | Parameter   | Coefficient |   SE |        95% CI |   Component
#> ------------------------------------------------------------------------------
#> Group | G1    | (Intercept) |        1.08 | 0.47 | [ 0.15, 2.00] | conditional
#> Group | G1    | Petal.Width |   -5.19e-03 | 0.29 | [-0.58, 0.57] | conditional
#> Group | G2    | (Intercept) |       -0.40 | 0.57 | [-1.51, 0.71] | conditional
#> Group | G2    | Petal.Width |        0.01 | 0.29 | [-0.56, 0.59] | conditional
#> Group | G3    | (Intercept) |       -0.68 | 0.55 | [-1.75, 0.40] | conditional
#> Group | G3    | Petal.Width |   -9.56e-03 | 0.21 | [-0.42, 0.40] | conditional

  model <- brms::brm(Sepal.Width ~ Petal.Width + (Petal.Width | Group), data = data, refresh=0)

  modelbased::estimate_grouplevel(model)
#> Group | Level                   | Parameter                        
#> -------------------------------------------------------------------
#> Group | (Intercept)             | sd_Group__Intercept              
#> Group | Group.G1                | r_Group[G1,Intercept]            
#> Group | Group.G1                | r_Group[G1,Petal.Width]          
#> Group | Group.G2                | r_Group[G2,Intercept]            
#> Group | Group.G2                | r_Group[G2,Petal.Width]          
#> Group | Group.G3                | r_Group[G3,Intercept]            
#> Group | Group.G3                | r_Group[G3,Petal.Width]          
#> Group | Intercept ~ Petal.Width | cor_Group__Intercept__Petal.Width
#> Group | Petal.Width             | sd_Group__Petal.Width            
#> 
#> Group | Component   |   Median |        95% CI
#> ----------------------------------------------
#> Group | conditional |     1.38 | [ 0.53, 4.47]
#> Group | conditional |     1.12 | [-0.70, 3.30]
#> Group | conditional | 4.85e-03 | [-0.81, 0.85]
#> Group | conditional |    -0.51 | [-2.40, 1.60]
#> Group | conditional |     0.06 | [-0.54, 0.86]
#> Group | conditional |    -0.47 | [-2.40, 1.66]
#> Group | conditional |    -0.09 | [-0.91, 0.51]
#> Group | conditional |    -0.04 | [-0.94, 0.93]
#> Group | conditional |     0.35 | [ 0.02, 1.59]

Created on 2025-03-01 with reprex v2.1.1

@DominiqueMakowski DominiqueMakowski linked an issue Mar 1, 2025 that may be closed by this pull request
5 tasks
@strengejacke
Copy link
Member

I can review this PR tomorrow or on Monday, if you like. Will be away now.

@strengejacke
Copy link
Member

Looks good! (though I can't judge all the regex stuff, hehe...)
Do we have an example that we can use for testing?

@DominiqueMakowski
Copy link
Member Author

I added some models (commented off) in the test that I think are good for testing (lme4, glmmTMB & brms)

@strengejacke

This comment was marked as outdated.

@strengejacke

This comment was marked as outdated.

@strengejacke
Copy link
Member

Ok, examples should work now

@DominiqueMakowski DominiqueMakowski merged commit 8dacdc5 into main Mar 2, 2025
20 of 25 checks passed
@DominiqueMakowski DominiqueMakowski deleted the grouplevel_fixes branch March 2, 2025 18:18
@strengejacke
Copy link
Member

Do you want to open another PR for the type options once it's working in parameters?

@DominiqueMakowski
Copy link
Member Author

yeah, I was eager to merge something today ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

estimate_grouplevel(): improvements for 1.0? BLUPs, random effects etc
2 participants