Provide Mdn, IQR, and Range for ordinal#470
Provide Mdn, IQR, and Range for ordinal#470Joao-O-Santos wants to merge 1 commit intojasp-stats:masterfrom
Conversation
|
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 Kind regards, |
|
@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. |
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 || ordinalblockNumeric conversion: Added
as.numeric()conversion for ordinal data to enable quantile-based statistics while preserving factor level orderNo 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.