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

consistent outputs across Bayesian and frequentist tests #630

Closed
IndrajeetPatil opened this issue Nov 7, 2021 · 4 comments
Closed

consistent outputs across Bayesian and frequentist tests #630

IndrajeetPatil opened this issue Nov 7, 2021 · 4 comments
Labels
Consistency 🍏 🍎 Expected output across functions could be more similar

Comments

@IndrajeetPatil
Copy link
Member

Basically, we need to have one-row dataframe summaries for BFBayesFactor objects, the same way we have them for htest objects.

t-test

library(BayesFactor)
library(parameters)
data(raceDolls)

# Bayesian
ttestBF(mtcars$wt, mu = 3) |> parameters(cohens_d = TRUE)
#> # Fixed Effects
#> 
#> Parameter  | Median | Cohen's d |        95% CI |     pd | % in ROPE |              Prior |    BF |          Method
#> -------------------------------------------------------------------------------------------------------------------
#> Difference |   0.20 |           | [-0.16, 0.56] | 87.10% |    24.26% | Cauchy (0 +- 0.71) | 0.387 | Bayesian t-test
#>            |        |      0.19 | [-0.15, 0.53] |        |           |                    |       | Bayesian t-test

# frequentist 
t.test(mtcars$wt, mu = 3) |> parameters(standardized_d = TRUE)
#> One Sample t-test
#> 
#> Parameter |   mu | Difference |       95% CI | t(31) | Cohen's d |      d 95% CI |     p
#> ----------------------------------------------------------------------------------------
#> mtcars$wt | 3.00 |       0.22 | [2.86, 3.57] |  1.26 |      0.22 | [-0.13, 0.58] | 0.218
#> 
#> Alternative hypothesis: true mean is not equal to 3

contingency table

# Bayesian
contingencyTableBF(raceDolls, sampleType = "indepMulti", fixedMargin = "cols") |>
  parameters(cramers_v = TRUE)
#> Warning: Could not estimate a good default ROPE range. Using 'c(-0.1, 0.1)'.
#> # Fixed Effects
#> 
#> Parameter | Cramer's V |       95% CI |                            Prior |   BF |                              Method
#> ---------------------------------------------------------------------------------------------------------------------
#> Ratio     |            |              | Independent multinomial (0 +- 1) | 1.81 | Bayesian contingency table analysis
#>           |       0.16 | [0.01, 0.29] |                                  |      | Bayesian contingency table analysis

# frequentist 
chisq.test(raceDolls) |>
  parameters(cramers_v = TRUE)
#> Pearson's Chi-squared test with Yates' continuity correction
#> 
#> Chi2(1) | Cramer's V | Cramers 95% CI |     p
#> ---------------------------------------------
#> 3.86    |       0.17 |   [0.03, 1.00] | 0.050

Created on 2021-11-07 by the reprex package (v2.0.1)

@IndrajeetPatil IndrajeetPatil added the Consistency 🍏 🍎 Expected output across functions could be more similar label Nov 7, 2021
@IndrajeetPatil
Copy link
Member Author

Another improvement we can do is display the Method column for Bayesian outputs as a table title, instead of "Fixed Effects", the same way we do it for frequentist outputs.

@strengejacke
Copy link
Member

library(BayesFactor)
#> Loading required package: coda
#> Loading required package: Matrix
#> ************
#> Welcome to BayesFactor 0.9.12-4.2. If you have questions, please contact Richard Morey ([email protected]).
#> 
#> Type BFManual() to open the manual.
#> ************
library(parameters)
data(raceDolls)

# Bayesian
ttestBF(mtcars$wt, mu = 3) |> parameters(cohens_d = TRUE)
#> # Fixed Effects
#> 
#> Parameter  | Median |        95% CI | Cohen's d |         d  CI |     pd | % in ROPE |              Prior |    BF |          Method
#> -----------------------------------------------------------------------------------------------------------------------------------
#> Difference |   0.20 | [-0.18, 0.54] |      0.19 | [-0.16, 0.54] | 85.72% |    24.78% | Cauchy (0 +- 0.71) | 0.387 | Bayesian t-test

# frequentist 
t.test(mtcars$wt, mu = 3) |> parameters(standardized_d = TRUE)
#> One Sample t-test
#> 
#> Parameter |   mu | Difference |       95% CI | t(31) | Cohen's d |      d 95% CI |     p
#> ----------------------------------------------------------------------------------------
#> mtcars$wt | 3.00 |       0.22 | [2.86, 3.57] |  1.26 |      0.22 | [-0.13, 0.58] | 0.218
#> 
#> Alternative hypothesis: true mean is not equal to 3

# Bayesian
contingencyTableBF(raceDolls, sampleType = "indepMulti", fixedMargin = "cols") |>
  parameters(cramers_v = TRUE)
#> Warning: Could not estimate a good default ROPE range. Using 'c(-0.1, 0.1)'.
#> # Fixed Effects
#> 
#> Parameter | Cramer's V |  Cramers  CI |                            Prior |   BF |                              Method
#> ---------------------------------------------------------------------------------------------------------------------
#> Ratio     |       0.16 | [0.01, 0.29] | Independent multinomial (0 +- 1) | 1.81 | Bayesian contingency table analysis

# frequentist 
chisq.test(raceDolls) |>
  parameters(cramers_v = TRUE)
#> Pearson's Chi-squared test with Yates' continuity correction
#> 
#> Chi2(1) | Cramer's V | Cramers 95% CI |     p
#> ---------------------------------------------
#> 3.86    |       0.17 |   [0.03, 1.00] | 0.050

Created on 2021-11-07 by the reprex package (v2.0.1)

@IndrajeetPatil
Copy link
Member Author

Thanks! 🤩

This is another minor inconsistency we can get rid of:

Another improvement we can do is display the Method column for Bayesian outputs as a table title, instead of "Fixed Effects", the same way we do it for frequentist outputs.

@IndrajeetPatil IndrajeetPatil reopened this Nov 7, 2021
@IndrajeetPatil
Copy link
Member Author

Also, CI column is NA:

library(BayesFactor)
library(parameters)
library(statsExpressions)
data(raceDolls)
options(tibble.width = Inf)

contingencyTableBF(raceDolls, sampleType = "indepMulti", fixedMargin = "cols") |>
  parameters(cramers_v = TRUE) |>
  as.data.frame()

#>   Parameter Median CI CI_low CI_high Cramers_v Cramers_CI_low Cramers_CI_high
#> 1     Ratio     NA NA     NA      NA 0.1663267     0.01151098       0.2932553
#>   pd ROPE_Percentage      Prior_Distribution Prior_Location Prior_Scale
#> 1 NA              NA independent multinomial              0           1
#>         BF                              Method
#> 1 1.814856 Bayesian contingency table analysis

Created on 2021-11-07 by the reprex package (v2.0.1)

This is present in {effectsize} output:

library(BayesFactor)
library(effectsize)
data(raceDolls)

contingencyTableBF(raceDolls, sampleType = "indepMulti", fixedMargin = "cols") |>
  effectsize() |>
  as.data.frame()
#>   Cramers_v   CI     CI_low   CI_high
#> 1 0.1620444 0.95 0.01022901 0.2918251

Created on 2021-11-07 by the reprex package (v2.0.1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Consistency 🍏 🍎 Expected output across functions could be more similar
Projects
None yet
Development

No branches or pull requests

2 participants