使用 R 对不均匀间隔的单变量时间序列进行缺失值插补

发布于 2025-01-18 05:12:20 字数 294 浏览 3 评论 0原文

我有以下数据集:

timestamp   value

1           90

3           78

6           87

8           NA

12          98

15          100

18          NA

24          88

27          101

如您所见,连续的时间戳之间的差距不是宽度的。有没有办法使用时间戳依赖性方法来替换NA的值?

我发现的所有包装仅适用于Equi间隔时间序列... 谢谢!

I have the following dataset:

timestamp   value

1           90

3           78

6           87

8           NA

12          98

15          100

18          NA

24          88

27          101

As you can see, the gaps between the consecutive timestamps are not equi-spaced. Is there a way to imputate values to replace the NA using a timestamp dependend method?

All packages I found are only suitable for equi-spaced time series...
Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瑾夏年华 2025-01-25 05:12:20

Zoo < / strong> r软件包可用于处理不规则间隔 /不均匀的时间序列。

首先,您必须创建一个Zoo TS对象。您可以指定索引或使用Posixct时间戳。

之后,您可以在此对象上使用插补方法。动物园的插补方法有限,但它们也用于不规则规格的时间序列。您可以使用线性插值(Na.Approx)或样条插值(NA.Spline),这也解释了时间戳记不均。

# First create a unevenly spaced zoo time series object
# First vector with values, second with your indices
zoo_ts <- zoo(c(90,78,87,NA,98,100,NA,88,101), c(1, 3, 6,8,12,15,18,24,27))

# Perform the imputation
na.approx(zoo_ts)

您的动物园对象看起来像这样:

>  1   3   6   8  12  15  18  24  27 
> 90  78  87  NA  98 100  NA  88 101 

以后的估算系列:

> 1         3         6         8        12        15        18        24        27 
> 90.00000  78.00000  87.00000  90.66667  98.00000 100.00000  96.00000  88.00000 101.00000 

当您有时间戳记并且该系列仅略微 /几秒钟,您也可以尝试通过映射您的时间序列值适用于正确的常规间隔。 (仅在差异很小的情况下合理)。通过这样做,您还可以使用其他插补方法,例如质量软件包(仅适用于常规间隔数据)。

The zoo R package can be used to handle irregular spaced / unevenly spaced time series.

First you have to create a zoo ts object. You can either specify indices or use POSIXct timestamps.

Afterwards you can use a imputation method on this object. Zoo's imputation methods are limited, but they also work on irregular speced time series. You can use linear interpolation (na.approx) or spline interpolation (na.spline), which also account for the uneven time stamps.

# First create a unevenly spaced zoo time series object
# First vector with values, second with your indices
zoo_ts <- zoo(c(90,78,87,NA,98,100,NA,88,101), c(1, 3, 6,8,12,15,18,24,27))

# Perform the imputation
na.approx(zoo_ts)

Your zoo object looks like this:

>  1   3   6   8  12  15  18  24  27 
> 90  78  87  NA  98 100  NA  88 101 

Your imputed series like this afterwards:

> 1         3         6         8        12        15        18        24        27 
> 90.00000  78.00000  87.00000  90.66667  98.00000 100.00000  96.00000  88.00000 101.00000 

When you have time stamps and the series is only slightly / few seconds off for each time stamp, you could also try to transform the series into a regular time series by mapping your values to the correct regular intervals. (only reasonably if the differences are small). By doing this you could also use additional imputation methods e.g. by the imputeTS package (which only works for regular spaced data).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文