[英]Positivity-preserving interpolation of time series in R
I have some data with missing values that I know to be positive. 我有一些缺失值的数据,我知道这是肯定的。 I'm trying to interpolate the missing values using
na.interp
from the forecast
package. 我正在尝试使用
forecast
包中的na.interp
插值缺少的值。 However, some of the interpolated values turn out to be negative. 但是,某些内插值结果为负。
I've tried na.approx
from the package zoo
, but the approximated values do not agree with the seasonal trend of the time series. 我已经尝试从包
zoo
na.approx
,但是近似值与时间序列的季节性趋势不一致。
I cannot interpolate in the log domain since some of my observations are 0
. 由于某些观察
0
因此无法在对数域中进行插值。 Interpolating in the square-root domain somehow produces too many outliers. 在平方根域内插值会产生太多离群值。 Is there any other way to interpolate time series while preserving positivity?
还有其他方法可以在保持阳性的同时对时间序列进行插值吗? Any references to other R packages would also be appreciated.
对其他R包的任何引用也将不胜感激。
There is the imputeTS package, which specifically focuses on missing values in time series. 有imputeTS软件包,专门针对时间序列中的缺失值。 (take a look at this Paper )
(看一下这篇论文 )
It works like this: 它是这样的:
na.kalman(yourTimeSeries)
That's it already. 就这样。
It offers several time series imputation functions: 它提供了几种时间序列插补功能:
Some of these functions are more advanced some are less advanced. 这些功能中有些功能更高级,有些功能则不太高级。 I would try the na.kalman() function of the package for this task.
我将为此任务尝试软件包的na.kalman()函数。 Might be that the results of this function already adhere the constraints.
可能是此功能的结果已经遵守约束。 Otherwise you need to perform some transformations before performing the imputation (as explained below).
否则,您需要在执行插补之前进行一些转换(如下所述)。
In general if you want your imputation to be constrained to some bounds this transformation approach might also help: 通常,如果您希望将插补限制在一定范围内,则此转换方法也可能会有所帮助:
library("imputeTS")
# Bounds
a <- 50
b <- 400
# Transform data
y <- log((myTimeSeries-a)/(b-myTimeSeries))
imputations <- na.kalman(y)
# Back-transform
imputationsBack <- (b-a)*exp(imputations)/(1+exp(imputations)) + a
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.