Reputation: 10147
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?
Upvotes: 0
Views: 4444
Reputation: 988
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.
Upvotes: 1