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

Initiating enter sequence as 0 success 0 failures for prior prediction table #226

Merged
merged 5 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
7 changes: 1 addition & 6 deletions R/LSbinomialcommon.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@
# data load and summary
.readyBinomialLS <- function(options) {
# are data ready
if (options[["dataInputType"]] == "counts")
readyData <- TRUE
else if (options[["dataInputType"]] == "sequence")
readyData <- length(options[["dataSequenceSuccesses"]]) > 0 || length(options[["dataSequenceFailures"]]) > 0
else if (options[["dataInputType"]] == "variable")
readyData <- length(options[["dataVariableSuccesses"]]) > 0 || length(options[["dataVariableFailures"]]) > 0
readyData <- length(options[["dataInputType"]]) > 0

# are priors ready
readyPriors <- length(options[["models"]]) > 0
Expand Down
53 changes: 20 additions & 33 deletions R/LSbinomialestimation.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,14 @@ LSbinomialestimation <- function(jaspResults, dataset, options, state = NULL)

estimatesContainer[["estimatesTable"]] <- estimatesTable

if (ready["data"] && !ready["models"])
return()
else if (!ready["data"]) {

if ((options[["dataInputType"]] == "variable" && options[["dataVariableSelected"]] != "") ||
(options[["dataInputType"]] == "sequence" && options[["dataSequenceSequenceOfObservations"]] != ""))
estimatesTable$addFootnote(gettext("Please specify successes and failures."))
if ((options[["dataInputType"]] == "variable" && options[["dataVariableSelected"]] != "" && sum(data$nSuccesses, data$nFailures) == 0) ||
(options[["dataInputType"]] == "sequence" && options[["dataSequenceSequenceOfObservations"]] != "" && sum(data$nSuccesses, data$nFailures) == 0))
estimatesTable$addFootnote(gettext("Please specify successes and failures."))

if (ready["data"] && !ready["models"])
return()

} else if (ready["models"]) {
else if (ready["models"]) {

# add rows for each hypothesis
for (i in 1:length(options[["models"]])) {
Expand Down Expand Up @@ -210,7 +207,7 @@ LSbinomialestimation <- function(jaspResults, dataset, options, state = NULL)
}


if (!all(ready))
if (!all(ready) || (ready["models"] && sum(data$nSuccesses, data$nFailures) == 0))
return()
else {
# add models to the first row
Expand Down Expand Up @@ -562,7 +559,7 @@ LSbinomialestimation <- function(jaspResults, dataset, options, state = NULL)
"colorPalette"))
containerIterative[["plotsIterative"]] <- plotsIterative

if (!all(ready))
if (!all(ready) || sum(data$nSuccesses, data$nFailures) == 0)
return()

plotDataLines <- list()
Expand Down Expand Up @@ -731,7 +728,7 @@ LSbinomialestimation <- function(jaspResults, dataset, options, state = NULL)
plotsIterative[[""]] <- createJaspPlot(title = "", width = 530, height = 400, aspectRatio = 0.7)
return()

} else if (!ready["data"] && ready["models"]) {
} else if ((!ready["data"] && ready["models"]) || sum(data$nSuccesses, data$nFailures) == 0) {

for (i in 1:length(options[["models"]])) {
plotsIterative[[options[["models"]][[i]]$name]] <- createJaspPlot(title = options[["models"]][[i]]$name,
Expand Down Expand Up @@ -822,7 +819,7 @@ LSbinomialestimation <- function(jaspResults, dataset, options, state = NULL)
"sequentialAnalysisIntervalEstimatePlotLower", "sequentialAnalysisIntervalEstimatePlotUpper", "colorPalette"))
containerIterativeInterval[["sequentialAnalysisIntervalEstimatePlot"]] <- plotsIterativeInterval

if (!all(ready))
if (!all(ready) || sum(data$nSuccesses, data$nFailures) == 0)
return()


Expand Down Expand Up @@ -895,7 +892,7 @@ LSbinomialestimation <- function(jaspResults, dataset, options, state = NULL)
plotsIterativeInterval[[""]] <- createJaspPlot(title = "", width = 530, height = 400, aspectRatio = 0.7)
return()

} else if (!ready["data"] && ready["models"]) {
} else if ((!ready["data"] && ready["models"]) || sum(data$nSuccesses, data$nFailures) == 0) {

for (i in 1:length(options[["models"]])) {
plotsIterativeInterval[[options[["models"]][[i]]$name]] <- createJaspPlot(title = options[["models"]][[i]]$name,
Expand Down Expand Up @@ -1019,7 +1016,7 @@ LSbinomialestimation <- function(jaspResults, dataset, options, state = NULL)
}
}

if (!all(ready))
if (!all(ready) || (ready["models"] && sum(data$nSuccesses, data$nFailures) == 0))
return()

iterSeq <- 0:length(data[["y"]])
Expand Down Expand Up @@ -1097,7 +1094,7 @@ LSbinomialestimation <- function(jaspResults, dataset, options, state = NULL)
}
}

if (!all(ready))
if (!all(ready) || (ready["models"] && sum(data$nSuccesses, data$nFailures) == 0))
return()

iterSeq <- 0:length(data[["y"]])
Expand Down Expand Up @@ -1150,17 +1147,14 @@ LSbinomialestimation <- function(jaspResults, dataset, options, state = NULL)

containerPredictions[["predictionsTable"]] <- predictionsTable

if (ready["data"] && !ready["models"])
return()
else if (!ready["data"]) {

if ((options[["dataInputType"]] == "variable" && options[["dataVariableSelected"]] != "") ||
(options[["dataInputType"]] == "sequence" && options[["dataSequenceSequenceOfObservations"]] != ""))
predictionsTable$addFootnote(gettext("Please specify successes and failures."))
if ((options[["dataInputType"]] == "variable" && options[["dataVariableSelected"]] != "" && sum(data$nSuccesses, data$nFailures) == 0) ||
(options[["dataInputType"]] == "sequence" && options[["dataSequenceSequenceOfObservations"]] != "" && sum(data$nSuccesses, data$nFailures) == 0))
predictionsTable$addFootnote(gettext("Please specify successes and failures."))

if (ready["data"] && !ready["models"])
return()

} else {
else {

# add rows for each hypothesis
for (i in 1:length(options[["models"]])) {
Expand Down Expand Up @@ -1413,6 +1407,9 @@ LSbinomialestimation <- function(jaspResults, dataset, options, state = NULL)
tablePredictions$addColumns(0:options[["posteriorPredictionNumberOfFutureTrials"]])
}

if ((options[["dataInputType"]] == "variable" && options[["dataVariableSelected"]] != "" && sum(data$nSuccesses, data$nFailures) == 0) ||
(options[["dataInputType"]] == "sequence" && options[["dataSequenceSequenceOfObservations"]] != "" && sum(data$nSuccesses, data$nFailures) == 0))
tablePredictions$addFootnote(gettext("Please specify successes and failures."))

if (ready["models"]) {
for (i in seq_along(options[["models"]])) {
Expand All @@ -1422,16 +1419,6 @@ LSbinomialestimation <- function(jaspResults, dataset, options, state = NULL)
return()


if (!ready["data"]) {

if ((options[["dataInputType"]] == "variable" && options[["dataVariableSelected"]] != "") ||
(options[["dataInputType"]] == "sequence" && options[["dataSequenceSequenceOfObservations"]] != ""))
tablePredictions$addFootnote(gettext("Please specify successes and failures."))

return()
}


tempPred <- NULL

for (i in 1:length(options[["models"]])) {
Expand Down
50 changes: 22 additions & 28 deletions R/LSbinomialtesting.R
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,14 @@ LSbinomialtesting <- function(jaspResults, dataset, options, state = NULL) {

testsContainer[["testsTable"]] <- testsTable

if ((options[["dataInputType"]] == "variable" && options[["dataVariableSelected"]] != "" && sum(data$nSuccesses, data$nFailures) == 0) ||
(options[["dataInputType"]] == "sequence" && options[["dataSequenceSequenceOfObservations"]] != "" && sum(data$nSuccesses, data$nFailures) == 0))
testsTable$addFootnote(gettext("Please specify successes and failures."))

if (ready["data"] && !ready["models"])
return()
else if (!ready["data"]) {

if ((options[["dataInputType"]] == "variable" && options[["dataVariableSelected"]] != "") ||
(options[["dataInputType"]] == "sequence" && options[["dataSequenceSequenceOfObservations"]] != ""))
testsTable$addFootnote(gettext("Please specify successes and failures."))

return()
} else if (ready["models"]) {
else if (ready["models"]) {

tempResults <- .testBinomialLS(data, options[["models"]])
marglikIssue <- FALSE
Expand Down Expand Up @@ -555,7 +553,7 @@ LSbinomialtesting <- function(jaspResults, dataset, options, state = NULL) {
containerPlots[[paste0("priorPredictivePerformanceDistributionPlot",type)]] <- plotsPredictions


if (!all(ready) || (data[["nSuccesses"]] == 0 && data[["nFailures"]] == 0))
if (!all(ready) || (sum(data$nSuccesses, data$nFailures) == 0 && type == "Prior"))
return()
else {

Expand Down Expand Up @@ -765,7 +763,7 @@ LSbinomialtesting <- function(jaspResults, dataset, options, state = NULL) {
plotsPredictionsIndividual[[""]] <- createJaspPlot(title = "", width = 530, height = 400, aspectRatio = 0.7)
return()

} else if ((!ready["data"] && ready["models"]) || (data[["nSuccesses"]] == 0 & data[["nFailures"]] == 0)) {
} else if ((!ready["data"] && ready["models"]) || (sum(data$nSuccesses, data$nFailures) == 0 && type == "Prior")) {

for (i in 1:length(options[["models"]])) {
plotsPredictionsIndividual[[options[["models"]][[i]]$name]] <- createJaspPlot(title = options[["models"]][[i]]$name,
Expand Down Expand Up @@ -943,25 +941,24 @@ LSbinomialtesting <- function(jaspResults, dataset, options, state = NULL) {
}


if (type != "Prior") {

if ((options[["dataInputType"]] == "variable" && options[["dataVariableSelected"]] != "" && sum(data$nSuccesses, data$nFailures) == 0) ||
(options[["dataInputType"]] == "sequence" && options[["dataSequenceSequenceOfObservations"]] != "" && sum(data$nSuccesses, data$nFailures) == 0))
tablePredictions$addFootnote(gettext("Please specify successes and failures."))
}

if (ready["models"]) {
if (options[[ifelse (type == "Prior", "priorPredictivePerformanceDistributionPlotType", "posteriorPredictionDistributionPlotType")]] %in% c("joint", "conditional")) {
for (i in seq_along(options[["models"]])) {
tablePredictions$addColumnInfo(name = paste0("hyp_", i), title = gettextf("P(Successes|%s)", options[["models"]][[i]]$name), type = "number")
}
} else if (options[[ifelse (type == "Prior", "priorPredictivePerformanceDistributionPlotType", "posteriorPredictionDistributionPlotType")]] == "marginal")
tablePredictions$addColumnInfo(name = "marginal", title = gettextf("P(Successes)"), type = "number")
} else
return()


if (!ready["data"] && type != "Prior") {

if ((options[["dataInputType"]] == "variable" && options[["dataVariableSelected"]] != "") ||
(options[["dataInputType"]] == "sequence" && options[["dataSequenceSequenceOfObservations"]] != ""))
tablePredictions$addFootnote(gettext("Please specify successes and failures."))
}

if (!ready["models"] || (ready["models"] && type == "Prior" && sum(data$nSuccesses, data$nFailures) == 0))
return()
}


tempResults <- .testBinomialLS(tempData, options[["models"]])
Expand Down Expand Up @@ -1195,7 +1192,7 @@ LSbinomialtesting <- function(jaspResults, dataset, options, state = NULL) {
}


if (!all(ready))
if (!all(ready) || (ready["models"] && sum(data$nSuccesses, data$nFailures) == 0))
return()

if (options[["sequentialAnalysisPredictivePerformancePlotType"]] == "BF") {
Expand Down Expand Up @@ -1475,17 +1472,14 @@ LSbinomialtesting <- function(jaspResults, dataset, options, state = NULL) {

containerPredictions[["predictionsTable"]] <- predictionsTable

if (ready["data"] && !ready["models"])
return()
else if (!ready["data"]) {

if ((options[["dataInputType"]] == "variable" && options[["dataVariableSelected"]] != "") ||
(options[["dataInputType"]] == "sequence" && options[["dataSequenceSequenceOfObservations"]] != ""))
predictionsTable$addFootnote(gettext("Please specify successes and failures."))
if ((options[["dataInputType"]] == "variable" && options[["dataVariableSelected"]] != "" && sum(data$nSuccesses, data$nFailures) == 0) ||
(options[["dataInputType"]] == "sequence" && options[["dataSequenceSequenceOfObservations"]] != "" && sum(data$nSuccesses, data$nFailures) == 0))
predictionsTable$addFootnote(gettext("Please specify successes and failures."))

if (ready["data"] && !ready["models"])
return()

} else {
else {

tempTests <- .testBinomialLS(data, options[["models"]])
tempMeans <- NULL
Expand Down
Loading