I am wondering if there is a way to do ADF Test on a given interval. Below is an example of me calculating the mean for every 20 samples:
rollapply(data, 20, FUN = mean)
I want to use the same logic and run ADF test for every 20 samples. Therefore I used the following code:
n = 24
test <- rollapply(spreadClose, n, FUN = adf.test)
Note: adf.test() is from library called "tseries".
Could anyone explain why this is not working? I am getting the following error.
Error in dimnames(x) <- dn : length of 'dimnames' [2] not equal to array extent
I would really appreciate any feedbacks!
I used the following codes and it started working:
adftest <- function(x)
{
adfPvalue <- adf.test(x)$p.value
adfPvalue
}
PValue <- function(x) {
Pvalue <- rollapply(x, N, adftest)
Pvalue
}
PValue(out)
How about this:
library(zoo)
library(tseries)
z <- zoo(rnorm(100), as.Date(1:100))
rollapplyr(z, 20, adf.test)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.