-
-
Notifications
You must be signed in to change notification settings - Fork 36
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
Simply extracting random effects variances #720
Conversation
ok, two things:
|
I don't think the order of terms should matter too much... |
I fixed the ordering-issue now, and actually improved it. Order might matter, because in your poly-examples, parameters were ordered alphabetically (.C, .L, .Q), which should be .L, .Q and .C (and then .4 and .5). This was previously a wrong behaviour and should now also be fixed. This PR still needs some testing, especially for profiled-CIs, to see if parameters and SE/CI still match. Feel free to play around with some models using |
And we need to check if this also work for other packages, like GLMMadaptive, ordinal:clmm, nlme etc. |
@mattansb @DominiqueMakowski @bwiernik If you look at library(rstanarm)
library(lme4)
data(sleepstudy)
data(cake)
set.seed(123)
m1 <- suppressMessages(stan_lmer(angle ~ temperature + (temperature | recipe) + (temperature | replicate), data = cake))
model_parameters(m1, effects = "all") you see that correlations are not bounded between [-1, 1]. This is something to be fixed in bayestestR, I think, but do you have any idea how to transform the posterior in order to have a proper "point estimate" here? |
I think the values from library(rstanarm)
library(lme4)
data(cake)
set.seed(123)
m1 <- stan_lmer(angle ~ temp + (temp | replicate),
data = cake,
chains = 1)
bayestestR::describe_posterior(m1, effects = "all")
#> ...
#>
#> # Random effects SD/Cor: replicate
#>
#> Parameter | Median | 95% CI | pd | ROPE | % in ROPE | Rhat | ESS
#> ----------------------------------------------------------------------------------------------------
#> (Intercept) | 2.90e-03 | [ 0.00, 0.70] | 100% | [-0.82, 0.82] | 100% | 0.999 | 612.00
#> temp ~ (Intercept) | 1.86e-04 | [-0.01, 0.01] | 59.20% | [-0.82, 0.82] | 100% | 0.999 | 395.00
#> temp | 1.12e-03 | [ 0.00, 0.00] | 100% | [-0.82, 0.82] | 100% | 1.000 | 325.00
#>
#> ...
posteriors <- as.data.frame(m1)
rho <- with(posteriors, {
`Sigma[replicate:temp,(Intercept)]` /
(sqrt(`Sigma[replicate:temp,temp]`) * sqrt(`Sigma[replicate:(Intercept),(Intercept)]`))
})
# Cor
bayestestR::describe_posterior(rho)
#> Summary of Posterior Distribution
#>
#> Parameter | Median | 95% CI | pd | ROPE | % in ROPE
#> -----------------------------------------------------------------------
#> Posterior | 0.19 | [-0.92, 0.95] | 59.20% | [-0.10, 0.10] | 9.05%
# Slopes
a <- with(posteriors, sqrt(`Sigma[replicate:temp,temp]`))
bayestestR::describe_posterior(a)
#> Summary of Posterior Distribution
#>
#> Parameter | Median | 95% CI | pd | ROPE | % in ROPE
#> --------------------------------------------------------------------
#> Posterior | 0.03 | [0.02, 0.05] | 100% | [-0.10, 0.10] | 100%
# Compare to:
lme4::lmer(angle ~ temp + (temp | replicate),
data = cake) |>
lme4::VarCorr()
#> Groups Name Std.Dev. Corr
#> replicate (Intercept) 2.604527
#> temp 0.027073 0.134
#> Residual 4.825927 |
Is this maybe an issue in |
I'm not sure, because - if I recall right - we just summarize the posteriors using mean/median etc., no matter whether fixed or random. insight just returns (roughly speaking) |
How does VarCorr() line up the appropriate parameters? |
What do you mean? How does it extract all parameters, or sorting? |
Re:
VarCorr() lines up the variance and covariance parameters and uses these to compute correlations. Can we copy that logic? |
@IndrajeetPatil Do you know how I correctly include |
Sorry, I couldn't figure this one out. The problem is that you need to specify a subdirectory on a given branch. remotes::install_github("glmmTMB/glmmTMB@ci_tweaks", subdir = "glmmTMB") I am not sure what URL this resolves to, and that's exactly what you will need to include in |
Let's see if StackOverflow can help: https://stackoverflow.com/questions/72671996/how-to-include-subdirectory-in-remotes-field-for-r-package-description |
Codecov Report
@@ Coverage Diff @@
## main #720 +/- ##
==========================================
- Coverage 53.23% 52.91% -0.33%
==========================================
Files 183 183
Lines 12104 12027 -77
==========================================
- Hits 6444 6364 -80
- Misses 5660 5663 +3
Continue to review full report at Codecov.
|
That worked! |
Nice, thanks! :-) |
Close #717