Skip to content

fix broken quartiles method in isoutlier - #482

Merged
pr0m1th3as merged 4 commits into
gnu-octave:mainfrom
AvanishSalunke:isoutlier
Sep 16, 2026
Merged

pr0m1th3as merged 4 commits into
gnu-octave:mainfrom
AvanishSalunke:isoutlier

Conversation

@AvanishSalunke

Copy link
Copy Markdown
Contributor
  1. quartiles method in isoutlier always crashed, because dim was being passed into the wrong argument of quantile. While fixing it, also found the center value formula was wrong - it used the median instead of the average of the 25th and 75th percentiles, which is what MATLAB actually returns.
  2. Also removed a docstring line that incorrectly said ThresholdFactor isn't supported for quartiles.

BEFORE:

octave:2> A = [57 59 60 100 59 58 57 58 300 61 62 60 62 58 57];
octave:3> [TF, L, U, C] = isoutlier(A, 'quartiles')
error: Q(3): out of bound 2 (dimensions are 1x2)
error: called from
    isoutlier>quartiles_method at line 382 column 3
    isoutlier at line 341 column 8

AFTER:

octave:2> A = [57 59 60 100 59 58 57 58 300 61 62 60 62 58 57];
octave:3> [TF, L, U, C] = isoutlier(A, 'quartiles')
TF =

  0  0  0  1  0  0  0  0  1  0  0  0  0  0  0

L = 52.375
U = 67.375
C = 59.875

MATLAB:

>> A = [57 59 60 100 59 58 57 58 300 61 62 60 62 58 57];

>> [TF, L, U, C] = isoutlier(A, 'quartiles')

TF =

  1×15 logical array

   0   0   0   1   0   0   0   0   1   0   0   0   0   0   0


L =

   52.3750


U =

   67.3750


C =

   59.8750

@pr0m1th3as

Copy link
Copy Markdown
Member

You are correct about dim in quantiles method. I also get your approach in calling the function twice, since it eases the burden of handling dim > 1 later on, when data is a matrix or an ND-array. However, the same shape-related bug is still present in the percentiles_method. It reads L = Q(1)andU = Q(2)out ofquantile (x, P, dim)`, which is linear indexing into a result that only has two elements when the input is a vector, so every matrix silently gets the wrong thresholds instead of an error.

On another item: your changes purge a @end itemize texinfo command which results in help rendering plain text instead of texinfo. Make sure that you always run help <name> after applying any changes to make sure that help docstrings are rendered correctly.

Also it helps if you stamp the MATLAB run with version (this is a more general guide rather than specific to this PR).

Another thing I noticed in the function (unrelated to your PR, but you are welcome to fix it along) is that all methods that require a second input argument for window do not check if varargin{2} exists before trying to parse it into window = varargin{2};, which will error out without a proper error message. It would be nice to do the check and of course add the BISTs that verify that input parsing works properly.

@pr0m1th3as
pr0m1th3as merged commit da6a8da into gnu-octave:main Sep 16, 2026
pr0m1th3as added a commit that referenced this pull request Sep 16, 2026
  The docstring lost the @EnD itemize closing the output list, so help
  isoutlier failed with "`@end' expected `itemize', but saw `deftypefn'" and
  printed the raw texinfo source instead of the formatted text.  A trailing
  space on the ThresholdFactor paragraph goes with it. (PR #482)

  * inst/Data_Manipulation/isoutlier.m: Close the output list and drop a
    trailing space.
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.

2 participants