Skip to content

Commit

Permalink
Update BFF (#6)
Browse files Browse the repository at this point in the history
* Update description and README

* add documentation

* disable prior and posterior distribution (still not implemented in the BFF package)

* update renv

* fixes from the package update

* add proper sidedness labels
  • Loading branch information
FBartos authored Nov 18, 2024
1 parent 9d6b466 commit 146b28e
Show file tree
Hide file tree
Showing 19 changed files with 727 additions and 301 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Imports:
Suggests:
testthat
Remotes:
rshudde/BFF@revisions,
jasp-stats/jaspBase,
jasp-stats/jaspGraphs
RoxygenNote: 7.3.2
38 changes: 19 additions & 19 deletions R/bffCommon.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ bffAnalysis <- function(jaspResults, dataset, options, test) {
if (.bffReady(options))
.bffFitBFF(jaspResults, dataset, options)

# saveRDS(options, file = "C:/JASP/options.RDS")
# saveRDS(dataset, file = "C:/JASP/dataset.RDS")
# default summary table
.bffSummaryTable(jaspResults, dataset, options)

Expand All @@ -34,9 +32,9 @@ bffAnalysis <- function(jaspResults, dataset, options, test) {
if (options[["plotBayesFactorFunction"]])
.bffBayesFactorFunctionPlot(jaspResults, dataset, options)

# prior and posterior plot
if (FALSE && options[["plotPriorAndPosterior"]])
.bffPriorAndPosteriorPlot(jaspResults, dataset, options)
# # prior and posterior plot
# if (FALSE && options[["plotPriorAndPosterior"]])
# .bffPriorAndPosteriorPlot(jaspResults, dataset, options)
}


Expand All @@ -51,10 +49,10 @@ bffAnalysis <- function(jaspResults, dataset, options, test) {
"ISTT" = c("tStatistic", "sampleSizeGroup1", "sampleSizeGroup2"),
# "correlation" = c("tStatistic", "sampleSize"),
"regression" = c("tStatistic", "sampleSize", "predictors"),
"ANOVA" = c("fStatistic", "degreesOfFreedom1", "degreesOfFreedom2"),
"ANOVA" = c("fStatistic", "sampleSize", "degreesOfFreedom1", "degreesOfFreedom2"),
#"binomial" = c("zStatistic", "sampleSize"),
#"AB" = c("chiqsrStatistic", "degreesOfFreedom"),
"Chi2" = c("chi2Statistic", "sampleSize")
"Chi2" = c("chi2Statistic", "sampleSize", "degreesOfFreedom")
)

return(c(dependenciesGlobal, dependenciesTest))
Expand Down Expand Up @@ -131,6 +129,7 @@ bffAnalysis <- function(jaspResults, dataset, options, test) {
else if (options[["test"]] == "ANOVA")
fit <- try(BFF::f_test_BFF(
f_stat = options[["fStatistic"]],
n = , options[["sampleSize"]],
df1 = options[["degreesOfFreedom1"]],
df2 = options[["degreesOfFreedom2"]],
r = options[["priorDispersionR"]],
Expand All @@ -152,6 +151,7 @@ bffAnalysis <- function(jaspResults, dataset, options, test) {
fit <- try(BFF::chi2_test_BFF(
chi2_stat = options[["chi2Statistic"]],
n = options[["sampleSize"]],
df = options[["degreesOfFreedom"]],
r = options[["priorDispersionR"]],
omega = if (fixedOmega) options[["bayesFactorWithPriorModeValue"]] else NULL))

Expand Down Expand Up @@ -190,10 +190,10 @@ bffAnalysis <- function(jaspResults, dataset, options, test) {
"ISTT" = options[["sampleSizeGroup1"]] != 0 && options[["sampleSizeGroup2"]] != 0,
# "correlation" = options[["sampleSize"]] != 0,
"regression" = options[["sampleSize"]] != 0 && options[["predictors"]] != 0,
"ANOVA" = options[["degreesOfFreedom1"]] != 0 && options[["degreesOfFreedom2"]] != 0,
"ANOVA" = options[["sampleSize"]] != 0 && options[["degreesOfFreedom1"]] != 0 && options[["degreesOfFreedom2"]] != 0,
# "binomial" = options[["sampleSize"]] != 0,
# "AB" = options[["degreesOfFreedom"]] != 0,
"Chi2" = options[["sampleSize"]] != 0
"Chi2" = options[["sampleSize"]] != 0 && options[["degreesOfFreedom"]] != 0
)
}
.bffReadDataset <- function(dataset, options) {
Expand All @@ -211,10 +211,10 @@ bffAnalysis <- function(jaspResults, dataset, options, test) {
"ISTT" = c(options[["tStatistic"]], options[["sampleSizeGroup1"]] , options[["sampleSizeGroup2"]]),
# "correlation" = c(options[["tStatistic"]], options[["sampleSize"]]),
"regression" = c(options[["tStatistic"]], options[["sampleSize"]], options[["predictors"]]),
"ANOVA" = c(options[["fStatistic"]], options[["degreesOfFreedom1"]], options[["degreesOfFreedom2"]]),
"ANOVA" = c(options[["fStatistic"]], options[["sampleSize"]], options[["degreesOfFreedom1"]], options[["degreesOfFreedom2"]]),
# "binomial" = c(options[["zStatistic"]], options[["sampleSize"]]),
# "AB" = c(options[["chi2Statistic"]], options[["degreesOfFreedom"]]),
"Chi2" = c(options[["chi2Statistic"]], options[["sampleSize"]])
"Chi2" = c(options[["chi2Statistic"]], options[["sampleSize"]], options[["degreesOfFreedom"]])
)
)

Expand All @@ -233,10 +233,10 @@ bffAnalysis <- function(jaspResults, dataset, options, test) {
"ISTT" = c(options[["sampleSizeGroup1"]] , options[["sampleSizeGroup2"]]),
# "correlation" = c(options[["sampleSize"]]),
"regression" = c(options[["sampleSize"]], options[["predictors"]]),
"ANOVA" = c(options[["fStatistic"]], options[["degreesOfFreedom1"]], options[["degreesOfFreedom2"]]),
"ANOVA" = c(options[["fStatistic"]], options[["sampleSize"]], options[["degreesOfFreedom1"]], options[["degreesOfFreedom2"]]),
# "binomial" = c(options[["sampleSize"]]),
# "AB" = c(options[["chi2Statistic"]], options[["degreesOfFreedom"]])
"Chi2" = c(options[["chi2Statistic"]], options[["sampleSize"]])
"Chi2" = c(options[["chi2Statistic"]], options[["sampleSize"]], options[["degreesOfFreedom"]])
),
exitAnalysisIfErrors = TRUE
)
Expand All @@ -251,10 +251,10 @@ bffAnalysis <- function(jaspResults, dataset, options, test) {
"ISTT" = c(options[["tStatistic"]], options[["sampleSizeGroup1"]] , options[["sampleSizeGroup2"]]),
# "correlation" = c(options[["tStatistic"]], options[["sampleSize"]]),
"regression" = c(options[["tStatistic"]], options[["degreesOfFreedom"]]),
"ANOVA" = c(options[["fStatistic"]], options[["degreesOfFreedom1"]], options[["degreesOfFreedom2"]]),
"ANOVA" = c(options[["fStatistic"]], options[["sampleSize"]], options[["degreesOfFreedom1"]], options[["degreesOfFreedom2"]]),
# "binomial" = c(options[["zStatistic"]], options[["sampleSize"]]),
# "AB" = c(options[["chi2Statistic"]], options[["degreesOfFreedom"]]),
"Chi2" = c(options[["chi2Statistic"]], options[["sampleSize"]])
"Chi2" = c(options[["chi2Statistic"]], options[["sampleSize"]], options[["degreesOfFreedom"]])
),
exitAnalysisIfErrors = TRUE
)
Expand Down Expand Up @@ -378,8 +378,8 @@ bffAnalysis <- function(jaspResults, dataset, options, test) {

summaryTable$addRows(list(
# n = nrow(dataset),
bf = .recodeBFtype(bfOld = fit[["log_bf"]], newBFtype = options[["bayesFactorType"]], oldBFtype = "LogBF10"),
priorMode = fit[["omega"]]
bf = .recodeBFtype(bfOld = fit[["log_bf_h1"]], newBFtype = options[["bayesFactorType"]], oldBFtype = "LogBF10"),
priorMode = fit[["omega_h1"]]
))

summaryTable$addFootnote(gettextf("Prior mode corresponds to %1$s.", .bffEffectSizeInformation(options)))
Expand Down Expand Up @@ -431,7 +431,7 @@ bffAnalysis <- function(jaspResults, dataset, options, test) {

omegaTable$addRows(list(
# n = nrow(dataset),
bf = .recodeBFtype(bfOld = fit[["log_bf"]], newBFtype = options[["bayesFactorType"]], oldBFtype = "LogBF10"),
bf = .recodeBFtype(bfOld = fit[["log_bf_h1"]], newBFtype = options[["bayesFactorType"]], oldBFtype = "LogBF10"),
priorMode = options[["bayesFactorWithPriorModeValue"]]
))

Expand Down Expand Up @@ -490,7 +490,7 @@ bffAnalysis <- function(jaspResults, dataset, options, test) {

maxBF10 <- exp(max(fit$BFF$log_bf))
if (options[["bayesFactorWithPriorMode"]])
BF10user <- exp(fitOmega$log_bf)
BF10user <- exp(fitOmega$log_bf_h1)

if (options[["bayesFactorType"]] == "BF01") {
dfLines$y <- -dfLines$y
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
# jaspModuleTemplate
# The Bayes Factor Functions module

The module employs Bayes factor functions (BFFs; Johnson, Pramanik and Shudde, 2023) to streamline hypothesis testing by directly comparing competing hypotheses using standardized effect sizes. This approach simplifies the calculation of Bayes factors from common test statistics, provides clear and intuitive summaries of experimental results without relying on arbitrary significance thresholds.

## References
Johnson, V. E., Pramanik, S., & Shudde, R. (2023). Bayes factor functions for reporting outcomes of hypothesis tests. *Proceedings of the National Academy of Sciences, 120*(8), e2217331120.

## R Packages
- BFF
9 changes: 5 additions & 4 deletions inst/Description.qml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ import JASP.Module 1.0
Description
{
name : "jaspBFF"
title : qsTr("BFF (beta)")
title : qsTr("Bayes Factor Functions")
description : qsTr("This module offers Bayes factor functions.")
version : "0.19.2"
version : "0.19.2"
author : "JASP Team"
maintainer : "JASP Team <[email protected]>"
website : "https://jasp-stats.org"
license : "GPL (>= 2)"
icon : "analysis-bayes-factor-functions.svg"
preloadData: true // no data actually needed for this module
requiresData: false

/*
GroupTitle
{
title: qsTr("Z-Tests")
Expand All @@ -31,7 +32,7 @@ Description
title: qsTr("Independent Samples Z-Test")
func: "bffIndependentSamplesZTest"
}

*/
GroupTitle
{
title: qsTr("T-Tests")
Expand Down
Empty file removed inst/help/.gitkeep
Empty file.
12 changes: 12 additions & 0 deletions inst/help/bffANOVA.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Bayes Factor Functions
===

The module employs Bayes factor functions (BFFs; Johnson, Pramanik and Shudde, 2023) to streamline hypothesis testing by directly comparing competing hypotheses using standardized effect sizes. This approach simplifies the calculation of Bayes factors from common test statistics, provides clear and intuitive summaries of experimental results without relying on arbitrary significance thresholds.

### References
---
- Johnson, V. E., Pramanik, S., & Shudde, R. (2023). Bayes factor functions for reporting outcomes of hypothesis tests. *Proceedings of the National Academy of Sciences, 120*(8), e2217331120.

### R Packages
---
- BFF
12 changes: 12 additions & 0 deletions inst/help/bffChi2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Bayes Factor Functions
===

The module employs Bayes factor functions (BFFs; Johnson, Pramanik and Shudde, 2023) to streamline hypothesis testing by directly comparing competing hypotheses using standardized effect sizes. This approach simplifies the calculation of Bayes factors from common test statistics, provides clear and intuitive summaries of experimental results without relying on arbitrary significance thresholds.

### References
---
- Johnson, V. E., Pramanik, S., & Shudde, R. (2023). Bayes factor functions for reporting outcomes of hypothesis tests. *Proceedings of the National Academy of Sciences, 120*(8), e2217331120.

### R Packages
---
- BFF
12 changes: 12 additions & 0 deletions inst/help/bffIndependentSamplesTTest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Bayes Factor Functions
===

The module employs Bayes factor functions (BFFs; Johnson, Pramanik and Shudde, 2023) to streamline hypothesis testing by directly comparing competing hypotheses using standardized effect sizes. This approach simplifies the calculation of Bayes factors from common test statistics, provides clear and intuitive summaries of experimental results without relying on arbitrary significance thresholds.

### References
---
- Johnson, V. E., Pramanik, S., & Shudde, R. (2023). Bayes factor functions for reporting outcomes of hypothesis tests. *Proceedings of the National Academy of Sciences, 120*(8), e2217331120.

### R Packages
---
- BFF
12 changes: 12 additions & 0 deletions inst/help/bffIndependentSamplesZTest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Bayes Factor Functions
===

The module employs Bayes factor functions (BFFs; Johnson, Pramanik and Shudde, 2023) to streamline hypothesis testing by directly comparing competing hypotheses using standardized effect sizes. This approach simplifies the calculation of Bayes factors from common test statistics, provides clear and intuitive summaries of experimental results without relying on arbitrary significance thresholds.

### References
---
- Johnson, V. E., Pramanik, S., & Shudde, R. (2023). Bayes factor functions for reporting outcomes of hypothesis tests. *Proceedings of the National Academy of Sciences, 120*(8), e2217331120.

### R Packages
---
- BFF
12 changes: 12 additions & 0 deletions inst/help/bffOneSampleTTest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Bayes Factor Functions
===

The module employs Bayes factor functions (BFFs; Johnson, Pramanik and Shudde, 2023) to streamline hypothesis testing by directly comparing competing hypotheses using standardized effect sizes. This approach simplifies the calculation of Bayes factors from common test statistics, provides clear and intuitive summaries of experimental results without relying on arbitrary significance thresholds.

### References
---
- Johnson, V. E., Pramanik, S., & Shudde, R. (2023). Bayes factor functions for reporting outcomes of hypothesis tests. *Proceedings of the National Academy of Sciences, 120*(8), e2217331120.

### R Packages
---
- BFF
12 changes: 12 additions & 0 deletions inst/help/bffOneSampleZTest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Bayes Factor Functions
===

The module employs Bayes factor functions (BFFs; Johnson, Pramanik and Shudde, 2023) to streamline hypothesis testing by directly comparing competing hypotheses using standardized effect sizes. This approach simplifies the calculation of Bayes factors from common test statistics, provides clear and intuitive summaries of experimental results without relying on arbitrary significance thresholds.

### References
---
- Johnson, V. E., Pramanik, S., & Shudde, R. (2023). Bayes factor functions for reporting outcomes of hypothesis tests. *Proceedings of the National Academy of Sciences, 120*(8), e2217331120.

### R Packages
---
- BFF
12 changes: 12 additions & 0 deletions inst/help/bffRegression.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Bayes Factor Functions
===

The module employs Bayes factor functions (BFFs; Johnson, Pramanik and Shudde, 2023) to streamline hypothesis testing by directly comparing competing hypotheses using standardized effect sizes. This approach simplifies the calculation of Bayes factors from common test statistics, provides clear and intuitive summaries of experimental results without relying on arbitrary significance thresholds.

### References
---
- Johnson, V. E., Pramanik, S., & Shudde, R. (2023). Bayes factor functions for reporting outcomes of hypothesis tests. *Proceedings of the National Academy of Sciences, 120*(8), e2217331120.

### R Packages
---
- BFF
6 changes: 6 additions & 0 deletions inst/qml/bffANOVA.qml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ Form {
negativeValues: true
}

IntegerField
{
name: "sampleSize"
label: qsTr("Sample size")
}

IntegerField
{
name: "degreesOfFreedom1"
Expand Down
6 changes: 6 additions & 0 deletions inst/qml/bffChi2.qml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ Form {
name: "sampleSize"
label: qsTr("Sample size")
}

IntegerField
{
name: "degreesOfFreedom"
label: qsTr("Degrees of freedom")
}
}

/*VariablesForm
Expand Down
2 changes: 1 addition & 1 deletion inst/qml/bffOneSampleTTest.qml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ Form {
}
}*/

BFF.Analysis{}
BFF.Analysis{oneSampleTest: true}
BFF.Priors{}
}
2 changes: 1 addition & 1 deletion inst/qml/bffOneSampleZTest.qml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ Form {
}
}*/

BFF.Analysis{}
BFF.Analysis{oneSampleTest: true}
BFF.Priors{}
}
12 changes: 7 additions & 5 deletions inst/qml/qml_components/Analysis.qml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import JASP 1.0

Section
{
property bool directionalTest: true
property bool directionalTest: true
property bool oneSampleTest: false

expanded: true
title: qsTr("Analysis")
Expand All @@ -35,9 +36,9 @@ Section
name: "alternativeHypothesis"
title: qsTr("Alternative Hypothesis")
visible: directionalTest
RadioButton { value: "equal"; label: qsTr("Group 1 ≠ Group 2"); checked: true }
RadioButton { value: "greater"; label: qsTr("Group 1 > Group 2")}
RadioButton { value: "less"; label: qsTr("Group 1 < Group 2")}
RadioButton { value: "equal"; label: oneSampleTest ? qsTr("Group 1 ≠ 0") : qsTr("Group 1 ≠ Group 2"); checked: true }
RadioButton { value: "greater"; label: oneSampleTest ? qsTr("Group 1 > 0") : qsTr("Group 1 > Group 2")}
RadioButton { value: "less"; label: oneSampleTest ? qsTr("Group 1 < 0") : qsTr("Group 1 < Group 2")}
}

BayesFactorType { }
Expand Down Expand Up @@ -75,7 +76,7 @@ Section
checked: true
}
}

/* Disabled till implemented in the BFF package
CheckBox
{
name: "plotPriorAndPosterior"
Expand All @@ -88,5 +89,6 @@ Section
checked: true
}
}
*/
}
}
Loading

0 comments on commit 146b28e

Please sign in to comment.