easystats / parameters

:bar_chart: Computation and processing of models' parameters
https://easystats.github.io/parameters/
GNU General Public License v3.0
425 stars 36 forks source link

documenting `return` section for `BayesFactor` objects #297

Closed IndrajeetPatil closed 3 years ago

IndrajeetPatil commented 4 years ago

Although most of the outputs from model_parameters for BayesFactor objects are clear, sometimes it's hard to figure out what some terms correspond to. And the documentation for this function doesn't have any information about this.

For example- the first four rows here correspond to model-average posterior summary

    library(BayesFactor)
    library(magrittr)

    anovaBF(formula = Sepal.Length ~ Species, data = iris) %>%
      parameters::model_parameters(., priors = FALSE, centrality = "mean") %>%
      as.data.frame()
    #>            Parameter        Mean       CI_low    CI_high      pd
    #> 1                 mu  5.84403632  5.775817530  5.9097313 1.00000
    #> 2     Species-setosa -0.82709743 -0.917829717 -0.7252568 1.00000
    #> 3 Species-versicolor  0.09180601  0.002343341  0.1861748 0.93675
    #> 4  Species-virginica  0.73529142  0.640733329  0.8310193 1.00000
    #> 5               sig2  0.27070721  0.218365419  0.3194694 1.00000
    #> 6          g_Species  4.87206772  0.245442872  7.4836032 1.00000
    #>   ROPE_Percentage Effects   Component           BF
    #> 1        0.000000   fixed       extra 1.425293e+28
    #> 2        0.000000   fixed conditional 1.425293e+28
    #> 3        0.547599   fixed conditional 1.425293e+28
    #> 4        0.000000   fixed conditional 1.425293e+28
    #> 5        0.000000   fixed       extra 1.425293e+28
    #> 6        0.000000   fixed       extra 1.425293e+28

and agree with columns from JASP:

image

But, as a user, I may not know that mu corresponds to intercept and don't know what do sig2 and g_Species here refer to.

strengejacke commented 4 years ago

I think this is something for @mattansb. For Bayesian models, model_parameters() is not much more than a wrapper around bayestestR::describe_posterior() + bayestestR::diagnostic_posterior().

mattansb commented 4 years ago

I can do most of these, I think:

Where should these definitions go? insight? parameters?

strengejacke commented 4 years ago

I'd say here: https://easystats.github.io/parameters/reference/model_parameters.BFBayesFactor.html

IndrajeetPatil commented 3 years ago

@mattansb Maybe this is confusion on my part, but is this expected?

# data
set.seed(123)
df <- dplyr::filter(.data = gapminder::gapminder, continent == "Africa")

# one-sample t-test
mod <- BayesFactor::ttestBF(x = df$gdpPercap, mu = 10000) 
#> t is large; approximation invoked.

# median value
median(df$gdpPercap)
#> [1] 1192.138

# raw difference
10000 - median(df$gdpPercap)
#> [1] 8807.862

# extracting details
parameters::model_parameters(mod)
#> Parameter  |   Median |                   89% CI |   pd | % in ROPE |              Prior | Effects |   Component |     BF
#> -------------------------------------------------------------------------------------------------------------------------
#> Difference | 8.01e+06 | [  7.32e+06,   8.78e+06] | 100% |        0% | Cauchy (0 +- 0.71) |   fixed | conditional | > 1000

If the parameter here is the raw difference, I was expecting the estimate to be around ~ 8800, but it is actually 8010000.

mattansb commented 3 years ago

No, this is a gross little bug - fixed!

set.seed(123)

x <- rnorm(100)
mod <- BayesFactor::ttestBF(x = x, mu = 10) 
#> t is large; approximation invoked.

# raw difference
10 - median(x)
#> [1] 9.938244

# extracting details
parameters::model_parameters(mod, test = NULL)
#> Parameter  | Median |        89% CI |              Prior | Effects |   Component |     BF
#> -----------------------------------------------------------------------------------------
#> Difference |   9.91 | [9.78, 10.06] | Cauchy (0 +- 0.71) |   fixed | conditional | > 1000

Created on 2020-09-23 by the reprex package (v0.3.0)

IndrajeetPatil commented 3 years ago

Thanks for fixing this so quickly!

@strengejacke Do you think there will be a new release of insight any time soon? This bug fix is definitely going to lead to some failing tests in my packages and I would like to coordinate my releases accordingly.

strengejacke commented 3 years ago
easystats::on_CRAN()
#> insight     0.4 weeks

And just ~1 week before that update, there was the previous submission, so actually the next release is no planned before end of October.