Skip to content

Commit 4428f31

Browse files
authored
Initiating enter sequence as 0 success 0 failures for prior prediction table (#226)
* Update LSbinomialtesting.R .tablePredictions2LS now assumes 0 successes and 0 failures in case no data sequence is specified, so the analysis does not crash. * Fixing empty tables and 0s, 0f initiation Deleting the length > 0 line for sequence/variable initiates "Enter sequence" and "Select variable" as 0 successes, 0 failures. * Prior prediction table, updating table & footnotes 1) Prior prediction table remains empty until data is specified. 2) Updating table does not show 1 observation anymore, in case no data is specified. (Binomial testing & estimation) 3) Footnotes that ask you to specify the success and failure key are displayed again in case a sequence is specified but not the keys. (Binomial testing & estimation) * Fixing tables and figures 1) Empty figures for sequential analysis in case no data is specified (Binomial Estimation). 2) If no data is specified, prior prediction table and plots remain empty, while posterior prediction table and plots do not (Binomial Testing). * Fix rows in prior predictions table Predictions table in the Prior Predictive Performance section now has no rows if no data is specified.
1 parent 53472e5 commit 4428f31

File tree

3 files changed

+45
-68
lines changed

3 files changed

+45
-68
lines changed

R/LSbinomialcommon.R

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,7 @@
1818
# data load and summary
1919
.readyBinomialLS <- function(options) {
2020
# are data ready
21-
if (options[["dataInputType"]] == "counts")
22-
readyData <- TRUE
23-
else if (options[["dataInputType"]] == "sequence")
24-
readyData <- length(options[["dataSequenceSuccesses"]]) > 0 || length(options[["dataSequenceFailures"]]) > 0
25-
else if (options[["dataInputType"]] == "variable")
26-
readyData <- length(options[["dataVariableSuccesses"]]) > 0 || length(options[["dataVariableFailures"]]) > 0
21+
readyData <- length(options[["dataInputType"]]) > 0
2722

2823
# are priors ready
2924
readyPriors <- length(options[["models"]]) > 0

R/LSbinomialestimation.R

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -128,17 +128,14 @@ LSbinomialestimation <- function(jaspResults, dataset, options, state = NULL)
128128

129129
estimatesContainer[["estimatesTable"]] <- estimatesTable
130130

131-
if (ready["data"] && !ready["models"])
132-
return()
133-
else if (!ready["data"]) {
134-
135-
if ((options[["dataInputType"]] == "variable" && options[["dataVariableSelected"]] != "") ||
136-
(options[["dataInputType"]] == "sequence" && options[["dataSequenceSequenceOfObservations"]] != ""))
137-
estimatesTable$addFootnote(gettext("Please specify successes and failures."))
131+
if ((options[["dataInputType"]] == "variable" && options[["dataVariableSelected"]] != "" && sum(data$nSuccesses, data$nFailures) == 0) ||
132+
(options[["dataInputType"]] == "sequence" && options[["dataSequenceSequenceOfObservations"]] != "" && sum(data$nSuccesses, data$nFailures) == 0))
133+
estimatesTable$addFootnote(gettext("Please specify successes and failures."))
138134

135+
if (ready["data"] && !ready["models"])
139136
return()
140137

141-
} else if (ready["models"]) {
138+
else if (ready["models"]) {
142139

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

212209

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

565-
if (!all(ready))
562+
if (!all(ready) || sum(data$nSuccesses, data$nFailures) == 0)
566563
return()
567564

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

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

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

825-
if (!all(ready))
822+
if (!all(ready) || sum(data$nSuccesses, data$nFailures) == 0)
826823
return()
827824

828825

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

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

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

1022-
if (!all(ready))
1019+
if (!all(ready) || (ready["models"] && sum(data$nSuccesses, data$nFailures) == 0))
10231020
return()
10241021

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

1100-
if (!all(ready))
1097+
if (!all(ready) || (ready["models"] && sum(data$nSuccesses, data$nFailures) == 0))
11011098
return()
11021099

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

11511148
containerPredictions[["predictionsTable"]] <- predictionsTable
11521149

1153-
if (ready["data"] && !ready["models"])
1154-
return()
1155-
else if (!ready["data"]) {
1156-
1157-
if ((options[["dataInputType"]] == "variable" && options[["dataVariableSelected"]] != "") ||
1158-
(options[["dataInputType"]] == "sequence" && options[["dataSequenceSequenceOfObservations"]] != ""))
1159-
predictionsTable$addFootnote(gettext("Please specify successes and failures."))
1150+
if ((options[["dataInputType"]] == "variable" && options[["dataVariableSelected"]] != "" && sum(data$nSuccesses, data$nFailures) == 0) ||
1151+
(options[["dataInputType"]] == "sequence" && options[["dataSequenceSequenceOfObservations"]] != "" && sum(data$nSuccesses, data$nFailures) == 0))
1152+
predictionsTable$addFootnote(gettext("Please specify successes and failures."))
11601153

1154+
if (ready["data"] && !ready["models"])
11611155
return()
11621156

1163-
} else {
1157+
else {
11641158

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

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

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

14241421

1425-
if (!ready["data"]) {
1426-
1427-
if ((options[["dataInputType"]] == "variable" && options[["dataVariableSelected"]] != "") ||
1428-
(options[["dataInputType"]] == "sequence" && options[["dataSequenceSequenceOfObservations"]] != ""))
1429-
tablePredictions$addFootnote(gettext("Please specify successes and failures."))
1430-
1431-
return()
1432-
}
1433-
1434-
14351422
tempPred <- NULL
14361423

14371424
for (i in 1:length(options[["models"]])) {

R/LSbinomialtesting.R

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,14 @@ LSbinomialtesting <- function(jaspResults, dataset, options, state = NULL) {
151151

152152
testsContainer[["testsTable"]] <- testsTable
153153

154+
if ((options[["dataInputType"]] == "variable" && options[["dataVariableSelected"]] != "" && sum(data$nSuccesses, data$nFailures) == 0) ||
155+
(options[["dataInputType"]] == "sequence" && options[["dataSequenceSequenceOfObservations"]] != "" && sum(data$nSuccesses, data$nFailures) == 0))
156+
testsTable$addFootnote(gettext("Please specify successes and failures."))
157+
154158
if (ready["data"] && !ready["models"])
155159
return()
156-
else if (!ready["data"]) {
157-
158-
if ((options[["dataInputType"]] == "variable" && options[["dataVariableSelected"]] != "") ||
159-
(options[["dataInputType"]] == "sequence" && options[["dataSequenceSequenceOfObservations"]] != ""))
160-
testsTable$addFootnote(gettext("Please specify successes and failures."))
161160

162-
return()
163-
} else if (ready["models"]) {
161+
else if (ready["models"]) {
164162

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

557555

558-
if (!all(ready) || (data[["nSuccesses"]] == 0 && data[["nFailures"]] == 0))
556+
if (!all(ready) || (sum(data$nSuccesses, data$nFailures) == 0 && type == "Prior"))
559557
return()
560558
else {
561559

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

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

770768
for (i in 1:length(options[["models"]])) {
771769
plotsPredictionsIndividual[[options[["models"]][[i]]$name]] <- createJaspPlot(title = options[["models"]][[i]]$name,
@@ -939,29 +937,29 @@ LSbinomialtesting <- function(jaspResults, dataset, options, state = NULL) {
939937
tablePredictions$addColumns(c(0:tempN)/tempN)
940938
} else {
941939
tablePredictions$addColumnInfo(name = "successes", title = gettext("Successes"), type = "integer")
942-
tablePredictions$addColumns(0:tempN)
940+
if (tempN > 0)
941+
tablePredictions$addColumns(0:tempN)
943942
}
944943

945944

945+
if (type != "Prior") {
946+
947+
if ((options[["dataInputType"]] == "variable" && options[["dataVariableSelected"]] != "" && sum(data$nSuccesses, data$nFailures) == 0) ||
948+
(options[["dataInputType"]] == "sequence" && options[["dataSequenceSequenceOfObservations"]] != "" && sum(data$nSuccesses, data$nFailures) == 0))
949+
tablePredictions$addFootnote(gettext("Please specify successes and failures."))
950+
}
951+
946952
if (ready["models"]) {
947953
if (options[[ifelse (type == "Prior", "priorPredictivePerformanceDistributionPlotType", "posteriorPredictionDistributionPlotType")]] %in% c("joint", "conditional")) {
948954
for (i in seq_along(options[["models"]])) {
949955
tablePredictions$addColumnInfo(name = paste0("hyp_", i), title = gettextf("P(Successes|%s)", options[["models"]][[i]]$name), type = "number")
950956
}
951957
} else if (options[[ifelse (type == "Prior", "priorPredictivePerformanceDistributionPlotType", "posteriorPredictionDistributionPlotType")]] == "marginal")
952958
tablePredictions$addColumnInfo(name = "marginal", title = gettextf("P(Successes)"), type = "number")
953-
} else
954-
return()
955-
956-
957-
if (!ready["data"] && type != "Prior") {
958-
959-
if ((options[["dataInputType"]] == "variable" && options[["dataVariableSelected"]] != "") ||
960-
(options[["dataInputType"]] == "sequence" && options[["dataSequenceSequenceOfObservations"]] != ""))
961-
tablePredictions$addFootnote(gettext("Please specify successes and failures."))
959+
}
962960

961+
if (!ready["models"] || (ready["models"] && type == "Prior" && sum(data$nSuccesses, data$nFailures) == 0))
963962
return()
964-
}
965963

966964

967965
tempResults <- .testBinomialLS(tempData, options[["models"]])
@@ -1195,7 +1193,7 @@ LSbinomialtesting <- function(jaspResults, dataset, options, state = NULL) {
11951193
}
11961194

11971195

1198-
if (!all(ready))
1196+
if (!all(ready) || (ready["models"] && sum(data$nSuccesses, data$nFailures) == 0))
11991197
return()
12001198

12011199
if (options[["sequentialAnalysisPredictivePerformancePlotType"]] == "BF") {
@@ -1475,17 +1473,14 @@ LSbinomialtesting <- function(jaspResults, dataset, options, state = NULL) {
14751473

14761474
containerPredictions[["predictionsTable"]] <- predictionsTable
14771475

1478-
if (ready["data"] && !ready["models"])
1479-
return()
1480-
else if (!ready["data"]) {
1481-
1482-
if ((options[["dataInputType"]] == "variable" && options[["dataVariableSelected"]] != "") ||
1483-
(options[["dataInputType"]] == "sequence" && options[["dataSequenceSequenceOfObservations"]] != ""))
1484-
predictionsTable$addFootnote(gettext("Please specify successes and failures."))
1476+
if ((options[["dataInputType"]] == "variable" && options[["dataVariableSelected"]] != "" && sum(data$nSuccesses, data$nFailures) == 0) ||
1477+
(options[["dataInputType"]] == "sequence" && options[["dataSequenceSequenceOfObservations"]] != "" && sum(data$nSuccesses, data$nFailures) == 0))
1478+
predictionsTable$addFootnote(gettext("Please specify successes and failures."))
14851479

1480+
if (ready["data"] && !ready["models"])
14861481
return()
14871482

1488-
} else {
1483+
else {
14891484

14901485
tempTests <- .testBinomialLS(data, options[["models"]])
14911486
tempMeans <- NULL

0 commit comments

Comments
 (0)