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

fixes dependencies and lower bounded Bayesian tests with -Inf prior #127

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
^renv$
^renv\.lock$
^.*\.Rproj$
^\.Rproj\.user$
^\.travis\.yml$
1 change: 1 addition & 0 deletions .Rprofile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source("renv/activate.R")
45 changes: 32 additions & 13 deletions R/commonequivalencefunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,9 @@ gettextf <- function(fmt, ..., domain = NULL) {

if (is.null(jaspResults[["equivalencePriorPosteriorContainer"]])) {
equivalencePriorPosteriorContainer <- createJaspContainer(title = gettext("Equivalence Prior and Posterior"))
equivalencePriorPosteriorContainer$dependOn(c("priorandposterior", "missingValues", "priorWidth",
"effectSizeStandardized", "equivalenceRegion", "lower", "upper",
"region", "lowerbound", "upperbound", "lower_max", "upper_min", "prior",
"informative", "informativeCauchyLocation", "informativeCauchyScale",
"informativeNormalMean", "informativeNormalStd", "informativeTLocation",
"informativeTScale", "informativeTDf", "priorandposteriorAdditionalInfo"))
equivalencePriorPosteriorContainer$dependOn(c("priorandposterior", "priorandposteriorAdditionalInfo", "missingValues",
,
.equivalencePriorDependencies))
jaspResults[["equivalencePriorPosteriorContainer"]] <- equivalencePriorPosteriorContainer
} else {
equivalencePriorPosteriorContainer <- jaspResults[["equivalencePriorPosteriorContainer"]]
Expand Down Expand Up @@ -512,19 +509,28 @@ gettextf <- function(fmt, ..., domain = NULL) {

# Step 1: Density in the range of the prior
integralEquivalencePrior <- pnorm(options$upperbound, prior.mean, sqrt(prior.variance)) - pnorm(options$lowerbound, prior.mean, sqrt(prior.variance))

errorEquivalencePrior <- 0

integralNonequivalencePrior <- 1 - integralEquivalencePrior

# Step 2: Density in the equivalence range of the posterior
upperbound <- .equivalence_cdf_normal(x = options$upperbound, t, n1, n2, independentSamples,
prior.mean = prior.mean, prior.variance = prior.variance)
if (options$upperbound == Inf) {
upperbound <- list(value = 1, abs.error = 0)
} else {
upperbound <- .equivalence_cdf_normal(x = options$upperbound, t, n1, n2, independentSamples,
prior.mean = prior.mean, prior.variance = prior.variance)
}

if (options$lowerbound == -Inf) {
lowerbound <- list(value = 0, abs.error = 0)
} else {
lowerbound <- .equivalence_cdf_normal(x = options$lowerbound, t, n1, n2, independentSamples,
prior.mean = prior.mean, prior.variance = prior.variance)
}

lowerbound <- .equivalence_cdf_normal(x = options$lowerbound, t, n1, n2, independentSamples,
prior.mean = prior.mean, prior.variance = prior.variance)

errorEquivalencePosterior <- upperbound$abs.error + lowerbound$abs.error
errorEquivalencePosterior <- upperbound$abs.error + lowerbound$abs.error
integralEquivalencePosterior <- upperbound$value - lowerbound$value

# to prevent numerical integration error (value < error)
Expand Down Expand Up @@ -660,7 +666,7 @@ gettextf <- function(fmt, ..., domain = NULL) {

} else if (options[["informativeStandardizedEffectSize"]] == "normal") {

bfObject <- .equivalence_bf_normal(t = tValue,
bfObject <- .equivalence_bf_normal(t = tValue,
n1 = n1,
n2 = n2,
independentSamples = !paired && !is.null(y),
Expand Down Expand Up @@ -1189,3 +1195,16 @@ gettextf <- function(fmt, ..., domain = NULL) {
exitAnalysisIfErrors = TRUE)
}
}

.equivalenceRegionDependencies <- c(
"equivalenceRegion",
"lowerbound", "upperbound",
"lower_max", "upper_min"
)
.equivalencePriorDependencies <- c(
"effectSize", "effectSizeStandardized", "defaultStandardizedEffectSize", "informativeStandardizedEffectSize",
"priorWidth",
"informativeCauchyLocation", "informativeCauchyScale",
"informativeNormalMean", "informativeNormalStd",
"informativeTLocation", "informativeTScale", "informativeTDf"
)
22 changes: 5 additions & 17 deletions R/equivalencebayesianindependentsamplesttest.R
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,7 @@ EquivalenceBayesianIndependentSamplesTTest <- function(jaspResults, dataset, opt

# Save results to state
jaspResults[["stateEquivalenceBayesianIndTTestResults"]] <- createJaspState(results)
jaspResults[["stateEquivalenceBayesianIndTTestResults"]]$dependOn(c("variables", "groupingVariable", "equivalenceRegion", "lower", "upper",
"region", "lowerbound", "upperbound", "lower_max", "upper_min", "prior", "missingValues",
"informative", "informativeCauchyLocation", "informativeCauchyScale",
"informativeNormalMean", "informativeNormalStd", "informativeTLocation",
"informativeTScale", "informativeTDf"))
jaspResults[["stateEquivalenceBayesianIndTTestResults"]]$dependOn(c("variables", "groupingVariable", "missingValues", .equivalenceRegionDependencies, .equivalencePriorDependencies))

return(results)
}
Expand All @@ -138,11 +134,7 @@ EquivalenceBayesianIndependentSamplesTTest <- function(jaspResults, dataset, opt

# Create table
equivalenceBayesianIndTTestTable <- createJaspTable(title = gettext("Equivalence Bayesian Independent Samples T-Test"))
equivalenceBayesianIndTTestTable$dependOn(c("variables", "groupingVariable", "priorWidth",
"effectSizeStandardized", "equivalenceRegion", "lower", "upper", "region", "lowerbound", "upperbound",
"lower_max", "upper_min", "informative", "informativeCauchyLocation", "informativeCauchyScale",
"informativeNormalMean", "informativeNormalStd", "informativeTLocation",
"informativeTScale", "informativeTDf"))
equivalenceBayesianIndTTestTable$dependOn(c("variables", "groupingVariable", "missingValues", .equivalenceRegionDependencies, .equivalencePriorDependencies))

# Add Columns to table
equivalenceBayesianIndTTestTable$addColumnInfo(name = "variable", title = " ", type = "string", combine = TRUE)
Expand All @@ -154,8 +146,8 @@ EquivalenceBayesianIndependentSamplesTTest <- function(jaspResults, dataset, opt

if (ready)
equivalenceBayesianIndTTestTable$setExpectedSize(length(options$variables))
message <- gettextf("I ranges from %1$s to %2$s",

message <- gettextf("I ranges from %1$s to %2$s",
ifelse(options$lowerbound == -Inf, "-\u221E", options$lowerbound),
ifelse(options$upperbound == Inf, "\u221E", options$upperbound))
equivalenceBayesianIndTTestTable$addFootnote(message)
Expand Down Expand Up @@ -290,11 +282,7 @@ EquivalenceBayesianIndependentSamplesTTest <- function(jaspResults, dataset, opt

.massPriorPosteriorIndpTTestTable <- function(jaspResults, dataset, options, equivalenceBayesianIndTTestResults, ready) {
equivalenceMassTable <- createJaspTable(title = gettext("Prior and Posterior Mass Table"))
equivalenceMassTable$dependOn(c("variables", "groupingVariable", "priorWidth", "lower", "upper", "region",
"effectSizeStandardized", "equivalenceRegion", "lowerbound", "upperbound", "lower_max", "upper_min",
"informative", "informativeCauchyLocation", "informativeCauchyScale",
"informativeNormalMean", "informativeNormalStd", "informativeTLocation",
"informativeTScale", "informativeTDf"))
equivalenceMassTable$dependOn(c("variables", "groupingVariable", "missingValues", .equivalenceRegionDependencies, .equivalencePriorDependencies))

equivalenceMassTable$addColumnInfo(name = "variable", title = " ", type = "string", combine = TRUE)
equivalenceMassTable$addColumnInfo(name = "section", title = gettext("Section"), type = "string")
Expand Down
18 changes: 4 additions & 14 deletions R/equivalencebayesianonesamplettest.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,21 +112,15 @@ EquivalenceBayesianOneSampleTTest <- function(jaspResults, dataset, options) {

# Save results to state
jaspResults[["stateEquivalenceBayesianOneTTestResults"]] <- createJaspState(results)
jaspResults[["stateEquivalenceBayesianOneTTestResults"]]$dependOn(c("variables", "mu", "equivalenceRegion", "lower", "upper", "region", "lowerbound", "upperbound", "lower_max", "upper_min",
"priorWidth", "effectSizeStandardized","informative", "informativeCauchyLocation", "informativeCauchyScale",
"informativeNormalMean", "informativeNormalStd", "informativeTLocation",
"informativeTScale", "informativeTDf", "missingValues"))
jaspResults[["stateEquivalenceBayesianOneTTestResults"]]$dependOn(c("variables", "groupingVariable", "missingValues", "mu", .equivalenceRegionDependencies, .equivalencePriorDependencies))
return(results)
}

.equivalenceBayesianOneTTestTableMain <- function(jaspResults, dataset, options, equivalenceBayesianOneTTestResults, ready) {

# Create table
equivalenceBayesianOneTTestTable <- createJaspTable(title = gettext("Equivalence Bayesian One Sample T-Test"))
equivalenceBayesianOneTTestTable$dependOn(c("variables", "mu", "equivalenceRegion", "priorWidth", "lower", "upper", "region", "lowerbound", "upperbound", "lower_max", "upper_min",
"effectSizeStandardized","informative", "informativeCauchyLocation", "informativeCauchyScale",
"informativeNormalMean", "informativeNormalStd", "informativeTLocation",
"informativeTScale", "informativeTDf", "missingValues"))
equivalenceBayesianOneTTestTable$dependOn(c("variables", "groupingVariable", "missingValues", "mu", .equivalenceRegionDependencies, .equivalencePriorDependencies))
equivalenceBayesianOneTTestTable$showSpecifiedColumnsOnly <- TRUE

# Add Columns to table
Expand All @@ -138,7 +132,7 @@ EquivalenceBayesianOneSampleTTest <- function(jaspResults, dataset, options) {
if (ready)
equivalenceBayesianOneTTestTable$setExpectedSize(length(options$variables))

message <- gettextf("I ranges from %1$s to %2$s",
message <- gettextf("I ranges from %1$s to %2$s",
ifelse(options$lowerbound == -Inf, "-\u221E", options$lowerbound),
ifelse(options$upperbound == Inf, "\u221E", options$upperbound))
equivalenceBayesianOneTTestTable$addFootnote(message)
Expand Down Expand Up @@ -241,11 +235,7 @@ EquivalenceBayesianOneSampleTTest <- function(jaspResults, dataset, options) {
.massPriorPosteriorOneTTestTable <- function(jaspResults, dataset, options, equivalenceBayesianOneTTestResults, ready) {

equivalenceMassTable <- createJaspTable(title = gettext("Prior and Posterior Mass Table"))
equivalenceMassTable$dependOn(c("variables", "priorWidth", "mu", "lower", "upper", "region",
"effectSizeStandardized", "equivalenceRegion", "lowerbound", "upperbound", "lower_max", "upper_min",
"informative", "informativeCauchyLocation", "informativeCauchyScale",
"informativeNormalMean", "informativeNormalStd", "informativeTLocation",
"informativeTScale", "informativeTDf"))
equivalenceMassTable$dependOn(c("variables", "mu", "groupingVariable", "missingValues", .equivalenceRegionDependencies, .equivalencePriorDependencies))

equivalenceMassTable$addColumnInfo(name = "variable", title = " ", type = "string", combine = TRUE)
equivalenceMassTable$addColumnInfo(name = "section", title = gettext("Section"), type = "string")
Expand Down
19 changes: 5 additions & 14 deletions R/equivalencebayesianpairedsamplesttest.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,7 @@ EquivalenceBayesianPairedSamplesTTest <- function(jaspResults, dataset, options)

# Save results to state
jaspResults[["stateEquivalenceBayesianPairedTTestResults"]] <- createJaspState(results)
jaspResults[["stateEquivalenceBayesianPairedTTestResults"]]$dependOn(c("pairs", "equivalenceRegion", "missingValues", "lower", "upper", "region", "lowerbound", "upperbound", "lower_max", "upper_min",
"priorWidth", "effectSizeStandardized","informative", "informativeCauchyLocation", "informativeCauchyScale",
"informativeNormalMean", "informativeNormalStd", "informativeTLocation",
"informativeTScale", "informativeTDf"))
jaspResults[["stateEquivalenceBayesianPairedTTestResults"]]$dependOn(c("pairs", "missingValues", .equivalenceRegionDependencies, .equivalencePriorDependencies))
return(results)
}

Expand All @@ -134,10 +131,7 @@ EquivalenceBayesianPairedSamplesTTest <- function(jaspResults, dataset, options)

# Create table
equivalenceBayesianPairedTTestTable <- createJaspTable(title = gettext("Equivalence Bayesian Paired Samples T-Test"))
equivalenceBayesianPairedTTestTable$dependOn(c("pairs", "equivalenceRegion", "lower", "upper", "region", "lowerbound", "upperbound", "lower_max", "upper_min",
"priorWidth", "effectSizeStandardized","informative", "informativeCauchyLocation", "informativeCauchyScale",
"informativeNormalMean", "informativeNormalStd", "informativeTLocation",
"informativeTScale", "informativeTDf"))
equivalenceBayesianPairedTTestTable$dependOn(c("pairs", "missingValues", .equivalenceRegionDependencies, .equivalencePriorDependencies))
equivalenceBayesianPairedTTestTable$showSpecifiedColumnsOnly <- TRUE

# Add Columns to table
Expand All @@ -151,8 +145,8 @@ EquivalenceBayesianPairedSamplesTTest <- function(jaspResults, dataset, options)
if (ready)
equivalenceBayesianPairedTTestTable$setExpectedSize(length(options$pairs))

message <- gettextf("I ranges from %1$s to %2$s",
ifelse(options$lowerbound == -Inf, "-\u221E", options$lowerbound),
message <- gettextf("I ranges from %1$s to %2$s",
ifelse(options$lowerbound == -Inf, "-\u221E", options$lowerbound),
ifelse(options$upperbound == Inf, "\u221E", options$upperbound))
equivalenceBayesianPairedTTestTable$addFootnote(message)

Expand Down Expand Up @@ -268,10 +262,7 @@ EquivalenceBayesianPairedSamplesTTest <- function(jaspResults, dataset, options)

# Create table
equivalenceMassPairedTTestTable <- createJaspTable(title = gettext("Equivalence Mass Table"))
equivalenceMassPairedTTestTable$dependOn(c("pairs", "equivalenceRegion", "priorWidth", "effectSizeStandardized","informative", "lower", "upper", "region",
"informativeCauchyLocation", "informativeCauchyScale", "lowerbound", "upperbound", "lower_max", "upper_min",
"informativeNormalMean", "informativeNormalStd", "informativeTLocation",
"informativeTScale", "informativeTDf"))
equivalenceMassPairedTTestTable$dependOn(c("pairs", "missingValues", .equivalenceRegionDependencies, .equivalencePriorDependencies))
equivalenceMassPairedTTestTable$showSpecifiedColumnsOnly <- TRUE

# Add Columns to table
Expand Down
Loading
Loading