0
votes

I'm not sure what i'm missing here, but i'm basically trying to compute interpolated values for a time series; when I directly plot the series, constraining the interpolation points with "interpolation.date.vector", the plot is correct:

plot(date.vector,fact.vector,ylab='Quantity')
lines(spline(date.vector,fact.vector,xout=interpolation.date.vector))

When I compute the interpolation, store it in an intermediate variable, and then plot the results; I get a radically incorrect result:

intepolated.values <- spline(date.vector,fact.vector,xout=interpolation.date.vector)

plot(intepolated.values$x,intepolated.values$y)
lines(intepolated.values$x,intepolated.values$y)

Doesn't the lines() function have to execute the spline() function to retrieve the interpolated points in the same way i'm doing it?

1
You have to be specific about what's wrong besides your using plot(intepolated.values$x,intepolated.values$y) instead of plot(date.vector,fact.vector,ylab='Quantity') the second time, because the results look fine to me.Aniko
Looks fine to me as well. lines(spline(date.vector,fact.vector,xout=interpolation.date.vector)) should be the same as lines(intepolated.values)hatmatrix

1 Answers

1
votes

For interpolation, I use approx. Example:

inter <- approx(date.vector, fact.vector, xout=interpolation.date.vector)
inter$x # holds x interpolated values, basically interpolation.date.vector 
inter$y # holds y interpolated values

The drawback is that it either does linear or constant interpolation.