[英]Interpolation of time series data in R
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:
当我直接绘制序列时,用“ interpolation.date.vector”约束插值点,该图是正确的:
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? lines()函数是否必须执行spline()函数以与我执行相同的方式来获取插值点?
For interpolation, I use approx . 对于插值,我使用rox 。 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. 缺点是它可以进行线性或恒定插值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.