You can also use the new-in-9 built-in TemporalData which has the option MissingDataMethod
to impute missing values.
dataOP = {{1, 1}, {2, 2}, {3, Missing[]}, {4, 4}, {5, 5}, {6, 6}, {7, 5},
{8, 4}, {9, 3}, {10, 2}, {11, 1}};
states = dataOP[[All, 2]];
times = dataOP[[All, 1]];
style = {Joined -> True, Mesh -> Full, LabelStyle -> {"Panel", 14}, ImageSize -> 400};
tD = TemporalData[states, {times}, MissingDataMethod -> Automatic];
Row[Table[Quiet@ListLinePlot[dt, style, PlotStyle -> Directive[{PointSize[.03], Thick}],
InterpolationOrder -> 2], {dt, {dataOP, tD}}], Spacer[5]]
Default setting for InterpolationOrder
suboption seems to be 0
.
{td1, td2, td3} = TemporalData[states, {times},
MissingDataMethod -> {"Interpolation",InterpolationOrder -> #}] & /@ {0, 1, 2};
Grid[i = 1; Table[Quiet@ListLinePlot[dt, style, InterpolationOrder -> io,
PlotStyle -> Directive[{PointSize[.03], Thick, Opacity[.8],
ColorData[63, "ColorList"][[i++]]}],
PlotLabel -> Style[StringForm["InterpolationOrder-> `1`\nMissingDataMethod->`2`",
io, MissingDataMethod /. dt[[2, -1]]], 14]] /.
Point[x : {__}] :> {Point[x], Red, PointSize[.04], Point[x[[3]]]},
{dt, {td1, td2}}, {io, {0, 1, 2}}], Dividers -> All]
With modified data with more missing values, the effect of the suboption values become more visible:
dataA = {{1, 1}, {2, 2}, {3, Missing[]}, {4, 4}, {5, 5}, {6, 7}, {7, Missing[]},
{8, Missing[]}, {9, 3}, {10, 2}, {11, 3}, {12, 3}, {13, 3}, {14, 3}};
statesA = dataA[[All, 2]];
timesA = dataA[[All, 1]];
{td1A, td2A, td3A} = TemporalData[statesA, {timesA},
MissingDataMethod -> {"Interpolation", InterpolationOrder -> #}] & /@ {0, 1, 3};
Grid[i = 1; Table[Quiet@ ListLinePlot[dt, style, InterpolationOrder -> io,
PlotStyle -> Directive[{PointSize[.03], Thick, Opacity[.8],
ColorData[63, "ColorList"][[i++]]}],
PlotLabel -> Style[StringForm["InterpolationOrder-> `1`\nMissingDataMethod->`2`",
io, MissingDataMethod /. dt[[2, -1]]], 14]] /.
Point[x : {__}] :> {Point[x], Red, PointSize[.04], Point[x[[{3, 7, 8}]]]},
{dt, {td2A, td3A}}, {io, {0, 1, 3}}], Dividers -> All]
Split[]
and plot the parts separately. $\endgroup$data[[All,1]]
) always sorted/non-decreasing as in your example? $\endgroup$