Skip to content

[jaspFrequencies] Fix crash in Bayesian Informed Multinomial Test when enabling...#308

Open
sisyphus-jasp wants to merge 1 commit into
jasp-stats:masterfrom
sisyphus-jasp:fix-sisyphus-1772460414
Open

[jaspFrequencies] Fix crash in Bayesian Informed Multinomial Test when enabling...#308
sisyphus-jasp wants to merge 1 commit into
jasp-stats:masterfrom
sisyphus-jasp:fix-sisyphus-1772460414

Conversation

@sisyphus-jasp

Copy link
Copy Markdown

Summary

Fixes: https://github.com/jasp-stats/INTERNAL-jasp/issues/3106

Root cause

  • .createInformedMultSequentialAnalysisPlot() assumed sequential results always existed.
  • For aggregated multinomial input (factor + counts), .computeInformedMultSequentialResults() yields no sequential rows/state; posterior-probability code then built a mismatched data.frame, causing fatal crash.

What changed

  • Added guards in R/informedmultinomialtestbayesian.R inside .createInformedMultSequentialAnalysisPlot():
  • If sequential state is missing/NULL/non-data.frame/empty, create the sequential plot element and set a clear error: sequential analysis needs individual-level data.
  • After include/exclude model filtering, if no rows remain, create plot element and set a clear error.
  • Kept normal path unchanged when valid sequential results exist.

Why

  • Prevent fatal termination and convert invalid sequential-analysis states into user-facing plot errors.

Caveats / reviewer checks

  • testAll() result after fix: [ FAIL 0 | WARN 9 | SKIP 3 | PASS 110 ] (matches baseline counts).
  • Reproduced attached .jasp now returns status: complete; sequential plot carries error message instead of crashing.
Implementation Plan

Root cause

  • In R/informedmultinomialtestbayesian.R, .createInformedMultSequentialAnalysisPlot() assumes .computeInformedMultSequentialResults() always creates jaspResults[["sequentialAnalysisResults"]] with rows.
  • For aggregated multinomial input (factor + count, no individual trials), .multinomAggregateData() sets attr(dataset, "individual") <- FALSE; then .computeInformedMultSequentialResults() returns early and no sequential state is created.
  • The plot builder still executes posterior-probability code and constructs data.frame(model = unique(sequentialAnalysisResults$model), ..., postProb = priorProb), causing row-length mismatch and fatal crash.

Proposed changes

  • File: R/informedmultinomialtestbayesian.R
  • Function: .createInformedMultSequentialAnalysisPlot()
  • Add an early guard after compute step:
    • if sequential results state is missing/NULL/empty, create sequentialAnalysisPlot with proper dependencies and set a user-facing error (sequential analysis requires unaggregated individual data), then return.
  • Add a second guard after model filtering (includeNullModel, includeEncompassingModel): if no models remain, create same plot with error and return.
  • Keep behavior unchanged when valid sequential rows exist.

Expected test impact

  • Existing tests should stay green: change only converts current crash path into explicit plot error handling.
  • No snapshot auto-accept; if any snapshot differs due new error message in this path, it would be expected stale output.

Fix issue #3106: Fix crash in Bayesian Informed Multinomial Test when enabling Sequential analysis plot with Posterior probability display option.

Attachment files available in: /workspace/attachment/
Files: bayes_inform_multinom.jasp

Screenshot Analysis

screenshot-1.png:

The screenshot shows JASP in the Frequencies module, analysis: Informed Bayesian Multinomial Test (results pane title: “Informed Bayesian Multinomial Test”).

Exact visible error text (as shown):

This analysis terminated unexpectedly.

Error in data.frame(model = unique(sequentialAnalysisResults$model),
step = 0, : arguments imply differing number of rows: 0, 1

Stack trace

To receive assistance with this problem, please report the message
above at: https://jasp-stats.org/bug-reports

Note: the call stack itself is not expanded/visible in this screenshot; only the “Stack trace” row is shown.

Selected UI state / settings visible:

  • Analysis panel: Informed Bayesian Multinomial Test
  • Top toolbar module selected: Frequencies
  • Variables list (left): Trials, Count2, Trials2
  • Assigned fields:
    • Factor: Race
    • Counts: Count
  • Show all options: unchecked
  • Bayes Factor Comparison:
    • Null: selected
    • Encompassing: unselected
    • vs. Model 1: unselected
  • Bayes Factor output type:
    • BF₁₀: selected
    • BF₀₁: unselected
    • Log(BF₁₀): unselected
  • Descriptives:
    • Table: checked
    • Plot: unchecked
    • Display Counts: unselected
    • Display Proportions: selected
  • Posterior plot: unchecked (Credible interval shown as 95%, disabled)
  • Sequential analysis plot: checked
    • Display Bayes factors: unselected
    • Display Posterior probability: selected
  • Collapsed sections: Prior Distribution, Prior Model Probability
  • Order Restricted Hypotheses: expanded
    • Tabs visible: Model 1, Model 2, Model 3
    • Entered hypothesis text (Model 1): White > Black > Chinese > Indian
  • Advanced: collapsed

Output visible:

  • No tables/plots produced.
  • Only the red error warning card in the Results pane.

Test Results

Test Run Result
Baseline (pre-fix) [ FAIL 0 | WARN 9 | SKIP 3 | PASS 110 ]
Post-fix [ FAIL 0 | WARN 9 | SKIP 3 | PASS 110 ]
Upstream CI e24f81f -- CI: passing

Automated Code Review

Approved after 1 review iteration(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant