replace_outliers
replace_outliers(x, [method=], [threshold=], [window=], [fill_method="linear"], [value=])
Input: x, method, threshold, window, fill_method, value · Output: no output
What it is
The same criterion, with the flagged samples patched in place. Length-preserving, so a Signal keeps its Fs. fill_method is a named string taking fill_missing's own method set plus "nan" (mark them missing and stop, leaving the decision to you); value is a named number that overrides it with a constant. Samples that were *already* missing stay missing — this replaces outliers, not dropouts. The keyword is fill_method=, not fill=: fill is a plotting colour keyword engine-wide, so fill="median" would be rejected as a colour name.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
replace_outliers(x, [method=], [threshold=], [window=], [fill_method="linear"], [value=]) | x —not documented yetmethod string, optionalfill_method is a named string taking fill_missing's own method set plus "nan" (mark them missing and stop, leaving the decision to you).threshold optionalnot documented yetwindow optionalnot documented yetfill_method string, optional (default "linear")fill_method is a named string taking fill_missing's own method set plus "nan" (mark them missing and stop, leaving the decision to you).value number, optionalvalue is a named number that overrides it with a constant. | not documented yet | The same criterion, with the flagged samples patched in place. Length-preserving, so a Signal keeps its Fs. Samples that were *already* missing stay missing — this replaces outliers, not dropouts. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
y = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 100]
print(find_outliers(y, method = "modified_zscore")) # [10]
print(remove_outliers(y, method = "modified_zscore")) # the 100 is gone
print(replace_outliers(y, method = "modified_zscore")[10]) # 2 -- patched in place
drift = 0 to 40
drift[20] = drift[20] + 30
print(find_outliers(drift, method = "hampel", window = 7)) # [20]
print(find_outliers(drift, method = "zscore")) # [] -- global test cannot see it
[10] [1, 2, 3, 2, 1, 2, 3, 2, 1, 2] 2 [20] []
from noise
How it works
find_outliers/remove_outliers/replace_outliers(x, [method="zscore"], [threshold=], [window=7], [fill_method="linear"], [value=]) — one function per ANSWER (which samples / drop them / patch them), one method= kwarg for the criterion, following smooth's own shape rather than growing a function per variant. "zscore" |x-mean|/std > threshold (3) "modified_zscore" 0.6745|x-med|/MAD > threshold (3.5) "iqr" outside Q1/Q3 +- threshold*IQR (1.5) "hampel" the local, windowed test -- hampel's own criterion, shared with it rather than reimplemented. The default threshold is per-method on purpose: 3 sigma, 3.5 modified-z and 1.5 IQR are the conventional cutoffs for three DIFFERENT scales, and one shared number would silently make two of the three mean something nobody intends. window= is read only by method="hampel", the only criterion that has a window -- passing it to the others is an unread kwarg and errors, rather than being accepted and ignored. There is deliberately no count in the return value: the "how many" question is length(find_outliers(...)), which is the same number and available before committing to a transform, and that keeps the two transforms chainable (x.remove_outliers().fft()) instead of returning a record the next call cannot take.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.