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

get_variance() returns NULL when modeling variance in brms #924

Open
matschmitz opened this issue Sep 2, 2024 · 4 comments
Open

get_variance() returns NULL when modeling variance in brms #924

matschmitz opened this issue Sep 2, 2024 · 4 comments
Labels
Bug 🐛 Something isn't working Consistency 🍏 🍎 Expected output across functions or API design could be more similar

Comments

@matschmitz
Copy link

The get_variance() function returns NULL when used with brms models that include a formula for modeling variance (e.g., sigma ~ cyl).

library(brms)
library(insight) #v0. 20.4

m <- brm(bf(mpg ~ hp + (1 | cyl), sigma ~ cyl),
         data = mtcars, seed = 123)
get_variance(m)  # Unexpectedly returns NULL
@mattansb
Copy link
Member

mattansb commented Sep 2, 2024

When sigma is modeled, there is no longer a sigma parameter - but a group of parameters that, given a set of $X$s can give a conditional sigma (in your example, conditional on cyl).

You can get those parameter with get_parameters():

get_parameters(m, parameters = "b_sigma") |> head()
#>   b_sigma_Intercept b_sigma_cyl
#> 1          2.022491 -0.11308296
#> 2          1.888756 -0.10069295
#> 3          1.572057 -0.04198636
#> 4          1.871757 -0.12676263
#> 5          2.527588 -0.20649596
#> 6          2.125739 -0.13128921

@matschmitz
Copy link
Author

Is there a way to compute the total sigma in those cases? Maybe by adding up all conditional sigmas?

@matschmitz
Copy link
Author

Also, get_variance_reaidual(m) returns

var.residual
           1

Which seems to be incorrect.

@mattansb
Copy link
Member

mattansb commented Sep 3, 2024

Is there a way to compute the total sigma in those cases?

What is total sigma?

Also, get_variance_reaidual(m) returns

var.residual
           1

Which seems to be incorrect.

Yes, this should return NULL or fail somehow.

@strengejacke strengejacke added Bug 🐛 Something isn't working Consistency 🍏 🍎 Expected output across functions or API design could be more similar labels Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🐛 Something isn't working Consistency 🍏 🍎 Expected output across functions or API design could be more similar
Projects
None yet
Development

No branches or pull requests

3 participants