简体   繁体   English

R中时间序列的保正插值

[英]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: 它提供了几种时间序列插补功能:

  • Imputation by Linear Interpolation 线性插补插补
  • Imputation by Spline Interpolation 样条插补插补
  • Imputation by Stineman Interpolation Stineman插值法
  • Imputation by Structural Model & Kalman Smoothing 通过结构模型和卡尔曼平滑法进行插补
  • Imputation by ARIMA State Space Representation & Kalman Sm. 由ARIMA状态空间表示法和Kalman Sm进行插补。
  • Imputation by Last Observation Carried Forward 进行最后观察的推算
  • Imputation by Next Observation Carried Backward 下一个观测值的归因
  • Missing Value Imputation by Simple Moving Average 简单移动平均数的缺失值估算
  • Imputation by Linear Weighted Moving Average 线性加权移动平均值的插补
  • Imputation by Exponential Weighted Moving Average 指数加权移动平均值的插补
  • Missing Value Imputation by Mean Value 均值缺失值估算
  • Seasonally Decomposed Missing Value Imputation 季节性分解的缺失值估算
  • Seasonally Splitted Missing Value Imputation 季节性分割的缺失值估算

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM