Skip to content

Provide Mdn, IQR, and Range for ordinal#470

Open
Joao-O-Santos wants to merge 1 commit intojasp-stats:masterfrom
Joao-O-Santos:master
Open

Provide Mdn, IQR, and Range for ordinal#470
Joao-O-Santos wants to merge 1 commit intojasp-stats:masterfrom
Joao-O-Santos:master

Conversation

@Joao-O-Santos
Copy link
Copy Markdown

Add support for Median, IQR, and Range for ordinal variables

Fixes: [jasp-stats/jasp-issues#3738](jasp-stats/jasp-issues#3738)

Related: [jaspDescriptives#421](#421)

Summary

This PR enables computation of Median, Interquartile Range (IQR), and Range statistics for ordinal variables in the descriptives table. Previously, these statistics were only available for scale (continuous) variables.

Changes

  • Unified computation block: Moved Median, IQR, and Range calculations from the scale-only block to the scale || ordinal block

  • Numeric conversion: Added as.numeric() conversion for ordinal data to enable quantile-based statistics while preserving factor level order

  • No behavior change for scale variables: The conversion is a no-op for scale variables, maintaining backward compatibility

Technical Details

For ordinal variables:

  • as.numeric() converts factor levels to their integer indices (1, 2, 3, ...)

  • This allows quantile functions to work correctly across all quantile types

  • Results are mapped back to the original factor labels for display in the table

  • Min/Max already worked with ordinal variables and remain unchanged

Rationale

Ordinal variables have a meaningful ordering that makes median, range, and IQR interpretable statistics. This change aligns with standard statistical practice for ordinal data and addresses the logical inconsistency where JASP computes Q1, Q2 (median), and Q3 but doesn't display the median or IQR.

This approach is less controversial than #421, which converts ordinal variables to scale and computes means/SDs. The current PR only enables statistics that are appropriate for ordinal data.

@JohnnyDoorn
Copy link
Copy Markdown
Contributor

Hi @Joao-O-Santos ,

Really cool you made a PR with a solution! Unfortunately this was our older behavior that we tried to (over)remedy, because the as.numeric leads to some counterintuitive results sometimes. We are working on a solution, although there are some small caveats in trying to respect the original types (and treating ordinals like the ordered factor in R), for instance changing the quantile types not working properly without as.numeric.

Kind regards,
Johnny

@Joao-O-Santos
Copy link
Copy Markdown
Author

@JohnnyDoorn, apologies for wasting your time.

May I ask what are you referring to as counterintuitive results?

Are you concerned about decimal results in a median of an ordinal variable?

It is my understanding that most software (SPSS, SAS) and textbooks are ok with that.

Or are you referring to what happens to ordinal variables that have numbers as labels, but it is the level number, not the label that gets converted to numeric?

Not sure what happened regarding the quantile type specification, but I'd say most JASP users are probably not aware of the different algorithms and expect results of different variable types to be similar.

@tomtomme tomtomme added duplicate This issue or pull request already exists help wanted Extra attention is needed labels Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate This issue or pull request already exists help wanted Extra attention is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Range, Median, IQR, and boxplot are not displayed for ordinal variables

3 participants