我可以使用非常规时间步长对 R 中的动物园对象执行自相关/滞后分析吗?如果是这样,怎么办?
我可以使用非常规时间步长对 R 中的动物园对象执行自相关/滞后分析吗?如果是这样,怎么办?
我在这里找到的唯一一篇文章涉及常规时间序列。我以不规则的时间步长进行了一系列观察。例如,(t,y) = (0,2668), (36.62,2723), (42,2723),...
,其中
t
是时间小时,y
是(分类*)观察值。 ... *从原始帖子编辑
我想寻找每日(滞后= 24)和每周(滞后= 168)的滞后相关性,以查看某些类别的观察是否在这些滞后间隔处/附近重复。在 R 中有没有办法做到这一点?我为我的数据创建了一个动物园对象,但找不到任何有关如何执行此操作的文档。
Can I perform autocorrelation / lag analysis on a zoo object in R with non-regular time steps? If so, how?
The only other post I could find here dealt with regular time series. I have a sequence of observations taken at irregular time steps. For example, (t,y) = (0,2668), (36.62,2723), (42,2723),...
where
t
is the time in hours, andy
is the (categorical*) observation. ... *edited from original post
I would like to look for lag correlations daily (lag = 24) and weekly (lag = 168) to see whether certain categories of observation repeat at / near these lag intervals. Is there a way to do this in R? I created a zoo object for my data but have been unable to find any documentation concerning how to do this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
aggregate
将数据转换为每日数据和每日数据。每周间隔,然后使用对常规时间序列执行此操作的任何函数计算自相关(例如acf
)。例如:aggregate
将z
转换为每日或每周数据,您可以在其中对每天/每周发生的所有事件进行求和。它通过查看index(z) %/% 24
(或168)来进行分组,这是观察时间除以24(即发生的日期)的整数部分。然后,
acf
函数计算自相关(lag
位于矢量索引上,而不是时间上)。我对统计不太了解,我注意到的一件事是,如果您这样做:
您会得到与从
z.weekly
计算自相关时不同的答案,因为它在 每日数据的滞后为 7,而不是每周数据的滞后为 1——所以我不确定我正在做的是否真的是您想要的。You can use
aggregate
to convert your data into daily & weekly intervals, and then calculate the autocorrelation with whatever function does it for regular time series (sayacf
). e.g.:The
aggregate
convertsz
to daily or weekly data where you sum all occurences for each day/week. It does the grouping by looking atindex(z) %/% 24
(or 168) which is the integer part of the hour of observation divided by 24 (ie, the day it occurs).Then the
acf
function calculates autocorrelation (with thelag
being on indices of the vector, not on time).I don't really know much about statistics, and one thing I noticed was that if you do:
you get a different answer from when you calculate autocorrelation from
z.weekly
, because it's doing autocorrelation on daily data with a lag of 7 as opposed to weekly data with a lag of 1 -- so I'm not sure if what I'm doing is actualy what you want.