easystats / bayestestR

:ghost: Utilities for analyzing Bayesian models and posterior distributions
https://easystats.github.io/bayestestR/
GNU General Public License v3.0
563 stars 55 forks source link

Add `rvar_col` argument to all `*.data.frame()` methods #666

Closed mattansb closed 1 month ago

mattansb commented 1 month ago

Fixes #604

grid <- data.frame(
  A = letters[1:2],
  B = c(2, 3),
  val = posterior::rvar(array(rnorm(1200), dim = c(600, 2)))
)

# Pull rvar column:
bayestestR::p_direction(grid$val)
#> Probability of Direction
#> 
#> Parameter |     pd
#> ------------------
#> x[1]      | 53.50%
#> x[2]      | 52.67%

# Or pass the data frame and tell the function what column has rvars:
bayestestR::p_direction(grid, rvar_col = "val")
#>   A B          val        pd
#> 1 a 2 0.062 ± 0.99 0.5350000
#> 2 b 3 0.037 ± 1.00 0.5266667

# Original behavior is maintained when not specifying rvar_col:
bayestestR::p_direction(grid)
#> Probability of Direction
#> 
#> Parameter |   pd
#> ----------------
#> B         | 100%
strengejacke commented 1 month ago

Could you also add a test?

strengejacke commented 1 month ago

And update the rd-file, see failing tests

mattansb commented 1 month ago

This is just a proof of concept. If we'd agree we want this, I'd make a much more extensive PR.

strengejacke commented 1 month ago

@easystats/core-team WDYT? I'd say we can implement this...

strengejacke commented 1 month ago

@mattansb I don't know how to integrate this PR into my PR, so I just copied your code over to #668. We may close this PR then.

mattansb commented 1 month ago

Oh, I wouldn't do that (it is very "raw")... Maybe just leave it to me for this PR, I'll get working on it soon (it needs to be made more efficient anyway) and make all the global changes needed.

strengejacke commented 1 month ago

Maybe just for this particular change in p_direction()? Since I'm already working on it, and it's related to the issue from Brenton. You could extend to other functions later... I guess we will else run into conflicts when we leave this PR open, because we have different modifications made to the p_direction.data.frame() method in both our PRs.

mattansb commented 1 month ago

I'm not worried about conflicts - this whole branch was just a quick and dirty proof of concept. I shouldn't have made a PR. Let's delete it.

You can integrate the changes if you want, but I will be completely overwrite those later on.

strengejacke commented 1 month ago

Yes, that's ok!