简体   繁体   English

时间序列的自举方法

[英]The bootstrapping method with timeseries

I got this error message about my code:我收到有关我的代码的错误消息:

Error in statistic(data, original, ...) : unused argument (original)

I need to run a bootstrap method to estimate pvalue in a periodogram.我需要运行引导程序方法来估计周期图中的 pvalue。 My timeseries was created by ts() function containing data of 365 days.我的时间序列是由包含 365 天数据的ts()函数创建的。

First, I defined a function:首先,我定义了一个函数:

periodogram_fun <- function(x) {
  TSA::periodogram(x)$spec
}

Following, I tried to run the boot:接下来,我尝试运行引导:

bootstrapped_periodograms <- boot(tsdata, periodogram_fun, R=1000)

and got the error message persists: Error in statistic(data, original, ...): unused argument (original)并得到错误消息仍然存在: Error in statistic(data, original, ...): unused argument (original)

Please, I need to solve this questions to run my seasonality data拜托,我需要解决这个问题才能运行我的季节性数据

This should do it:这应该这样做:

library(TSA)
library(boot)
periodogram_fun <- function(x, ind) {
   periodogram(ts(x[ind], start=1, end=365), plot=FALSE)$spec
}
bootstrapped_periodograms <- boot(tsdata, periodogram_fun, R=1000)

The function you're bootstrapping has to have two arguments - the first being the data and the second being the bootstrapped observation numbers.您引导的函数必须有两个参数——第一个是数据,第二个是引导的观察值。 This assumes that you just want a nonparametric bootstrap where you're randomly resampling the values in your time-series and creating a new time-series out of those 365 randomly re-sampled values.这假设您只需要一个非参数引导程序,您可以在其中随机重新采样时间序列中的值,并从这 365 个随机重新采样的值中创建一个新的时间序列。

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

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