简体   繁体   English

如何在 R 中创建移动平均线 model?

[英]How do I create an moving average model in R?

I'm running analysis on a certain dataset, and while looking over the data, I noticed that the PACF have no values (besides the first of course) that are significant, while the auto correlation function's (ACF's) values are all mostly significant.我正在对某个数据集进行分析,在查看数据时,我注意到 PACF 没有任何重要的值(当然除了第一个),而自相关函数 (ACF) 的值大部分都很重要。 So, I decided on creating an MA model (since the ACF's values are the ones that are significant), but I'm not sure how to do this in R, and how to decide the size of the window.所以,我决定创建一个 MA model(因为 ACF 的值很重要),但是我不确定如何在 R 中执行此操作,以及如何确定 Z05B8C7352706FFB2F4DE4C1 的大小。

Would this below suffice?下面的就够了吗?

arima(time-series_object, order = c(0,0,1))

Again, given an ACF graph, how should we decide the what MA we should use (eg (0,0,1), (0,1,1), etc.)?同样,给定一个 ACF 图,我们应该如何决定我们应该使用什么 MA(例如 (0,0,1)、(0,1,1) 等)?

There are many ways to create a moving average in R, I personally always did it in plain R using filter() , simply because I see what is happening.在 R 中创建移动平均线的方法有很多,我个人总是使用filter()在普通的 R 中做到这一点,只是因为我看到了正在发生的事情。 Assume that your data is stored in two vectors x <- 1:100 and y <- sin(x/10) + rnorm(100,sd=.1) .假设您的数据存储在两个向量x <- 1:100y <- sin(x/10) + rnorm(100,sd=.1)中。

One way of moving average calculation would be to average the current value and its 9 previous values if the window length is 10:如果 window 长度为 10,则移动平均计算的一种方法是平均当前值及其 9 个先前值:

f <- rep(1/10, 10)
z <- filter(y, f, sides=1)

Now, you have your smoothed value is z .现在,您的平滑值为z You will see that z starts with 9 NA values because the first 9 steps you do not have enough values to average yet.您将看到z从 9 个NA值开始,因为前 9 个步骤您还没有足够的值来平均。

Having a minimal reproducible data set would help answer the 2nd part of your question:拥有一个最小的可重现数据集将有助于回答您问题的第二部分:

[How do] we decide [...] what MA we should use (eg (0,0,1), (0,1,1) , etc.)? [如何] 我们决定 [...] 我们应该使用什么 MA(例如(0,0,1), (0,1,1)等)?

Related有关的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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