2

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.

sunt05
  • 4,367
  • 23
  • 34

1 Answers1

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}}

eldo
  • 67,911
  • 5
  • 60
  • 168
  • thanks for the answer! But I was thinking if Interpolation could be used while the outliers could be removed or replaced as Missing[]. – sunt05 Jul 13 '17 at 09:28