Although I'm aware of several workarounds available to handle the extrapolation warnings raised by the interpolation that takes place in some built-in functions (e.g., ContourPlot), I find the "ExtrapolationHandler" option cannot be used directly inside the ResamplingMethod of TimeSeriesResample.

For instance,

TimeSeriesResample[TimeSeries[Table[{i, RandomReal[]}, {i,300}]], {Range[301]}]

will raise the following warning:

InterpolatingFunction::dmval: Input value {301} lies outside the range of data in the interpolating function. Extrapolation will be used.

As such, my question is: what is an elegant way of handling extrapolation raised by TimeSeriesResample? i.e., detect the range outliers and take action on them. I want something like "ExtrapolationHandler" in Interpolation.

  • $\begingroup$ It is not clear whether you want to suppress the warning message or detect it in your code and take action. $\endgroup$
    – m_goldberg
    Commented Jul 13, 2017 at 8:09
  • $\begingroup$ @m_goldberg, I meant the latter: how to detect the outliers and take action on them. $\endgroup$
    – sunt05
    Commented Jul 13, 2017 at 8:11

1 Answer 1

data = Table[{i, 100 + i}, {i, 3}];

You avoid the warning by specifying a resampling method

ts = TimeSeriesResample[TimeSeries@data, {Range@4}, ResamplingMethod -> None]["Path"]

{{1, 101}, {2, 102}, {3, 103}, {4, Missing[]}}

Now you can delete or replace the missing value, f.e.

ts /. {_, Missing[]} :> Sequence[]

{{1, 0.243066}, {2, 0.455276}, {3, 0.0923567}}

You can also use

TimeSeriesResample[TimeSeries@data, {Range@4},
  ResamplingMethod -> {"Constant", c}] // Normal

{{1, 101}, {2, 102}, {3, 103}, {4, c}}

  • $\begingroup$ thanks for the answer! But I was thinking if Interpolation could be used while the outliers could be removed or replaced as Missing[]. $\endgroup$
    – sunt05
    Commented Jul 13, 2017 at 9:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.