Skip to content

[jaspDescriptives] Fix heatmap mean calculation to handle single observation per cell...#465

Open
sisyphus-jasp wants to merge 1 commit intojasp-stats:masterfrom
sisyphus-jasp:fix-sisyphus-1772506815
Open

[jaspDescriptives] Fix heatmap mean calculation to handle single observation per cell...#465
sisyphus-jasp wants to merge 1 commit intojasp-stats:masterfrom
sisyphus-jasp:fix-sisyphus-1772506815

Conversation

@sisyphus-jasp
Copy link
Copy Markdown
Contributor

Summary

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

Root cause

  • Heatmap aggregation helper had mismatched stat names: match.arg() normalized to "meanArithmetic" while switch() only handled "mean".
  • That returned NULL, then colnames(data) <- ... crashed with "less than two dimensions".

What changed

  • Updated R/descriptives.R in .descriptivesHeatmapAggregateData().
  • match.arg() now accepts both "mean" and legacy "meanArithmetic".
  • switch() now maps both keys to stats::aggregate(..., mean).
  • This keeps behavior same for other stats and adds backward-compatible handling for serialized legacy values.

Verification

  • Ran full testAll(): [ FAIL 0 | WARN 4 | SKIP 2 | PASS 66 ] (matches baseline).
  • Re-ran attached reproduction (attachment/heatmap.jasp.jasp) with module reinstall: analysis status changed from fatalError to complete.
  • Extra direct check: n=1 per cell aggregation succeeds for both "mean" and "meanArithmetic".

Caveats for reviewer

  • runAnalysis() used stale installed module until reinstall was enabled; verification was done with reinstall.modules = TRUE to ensure patched code path.
Implementation Plan

Root cause

  • R/descriptives.R .descriptivesHeatmapAggregateData() calls match.arg(fun, c("identity", "meanArithmetic", "median", "mode", "length")) but switch() handles mean (not meanArithmetic).
  • For UI value "mean", match.arg() resolves to "meanArithmetic" (partial match), then switch() returns NULL; next colnames(data) <- ... crashes with "less than two dimensions".

Proposed changes

  • File: R/descriptives.R.
  • Function: .descriptivesHeatmapAggregateData.
  • Make statistic matching consistent and backward-compatible:
    • accept both "mean" and legacy "meanArithmetic" in match.arg;
    • route both to stats::aggregate(..., mean) in switch.
  • Keep output structure unchanged (horizontal, vertical, value, label).

Expected test impact

  • Existing tests should pass; change only prevents fatal error for mean heatmap statistic.
  • Behavior for median, mode, identity, length unchanged.
  • Reproduction with attached .jasp should switch from fatalError to complete.

Fix heatmap mean calculation to handle single observation per cell (n=1) instead of throwing an error

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

Screenshot Analysis

screenshot-1.png:

I couldn’t locate a local file named screenshot-1.png in /home/openclaw/resources, so I read the attached screenshot you provided in-chat.

Exact error text visible in the screenshot:

This analysis terminated unexpectedly.

Error in `colnames<-`(`*tmp*`, value = c('horizontal', 'vertical', 'value')): attempt to set 'colnames' on an object with less than two dimensions

Stack trace ◇

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

What the UI shows (for reproduction):

  • Module/analysis:
  1. Top ribbon shows Descriptives active.
  2. Output pane title is Results with section Descriptive Statistics.
  3. A Heatmaps output is visible below the warning, suggesting the Descriptives heatmap feature is being used.
  • Left analysis/options panel (visible selections):
  1. A Split field is present and appears empty.
  2. Transpose descriptives table appears unchecked.
  3. Color palette (viridis) is selected.
  4. Tile heatmaps for selected variables is enabled.
  5. In tile heatmap settings:
    • Horizontal axis: year
    • Vertical axis: month
    • Display value: checked
    • Under For scale variables: Mean selected (circled in red in screenshot)
    • Under For nominal and ordinal variables: Value itself selected
    • Display legend: checked
    • Width to height ratio of tiles: 1
    • Relative text size: 1
  • Output elements visible:
  1. Red warning box with the error above.
  2. A partially visible Descriptive Statistics table behind/under the warning.
  3. A Heatmaps plot labeled temp with month labels and numeric tile values.
  4. A legend/colorbar labeled value.

State likely relevant to bug:

  • Heatmap is configured with categorical axes (year, month) and a scale summary statistic (Mean), and the analysis crashes while still rendering at least part of the heatmap output.

Test Results

Test Run Result
Baseline (pre-fix) [ FAIL 0 | WARN 4 | SKIP 2 | PASS 66 ]
Post-fix [ FAIL 0 | WARN 4 | SKIP 2 | PASS 66 ]
Upstream CI 31dbca5 -- 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.

3 participants