运行ADF时在R-Studio上解析数据时出错

时间:2017-04-11 12:48:39

标签: r rstudio

在尝试在R-Studio上运行ADF(Augmented Dickey Fuller)测试时,我似乎无法理解这个错误有什么问题。将欣赏评论。

library(AER)
library("dynlm", lib.loc="~/R/win-library/3.2")
x<-read.table("C://R Files/protein.csv", header=T, sep=",")
"adf" <- function(x,k = 0, int = TRUE, trend = FALSE){
     require(dynlm)
     dx <- diff(x)
     formula <- paste("dx ~ L(x)")
     if(k > 0)
         formula <- paste(formula,"  L(dx,1:k)")
     if(trend){
         s <- time(x)
         t <- ts(s - s[1],start = s[1],freq = frequency(x))
         formula <- paste(formula,"  t")
     }
     if(!int) formula <- paste(formula," - 1")
     summary(dynlm(as.formula(formula)))
 }

a<-ts(x$a)
adf(a, k=1, int=T, trend=T)

我在此之后收到的错误消息是:

解析时出错(text = x,keep.source = FALSE):   :1:13:意外的符号 1:dx~L(x)L                 ^

1 个答案:

答案 0 :(得分:1)

可能是这样的: formula <- paste(formula," L(dx,1:k)")

您不能只是向模型添加内容。尝试做: formula <- paste(formula,"+ L(dx,1:k)") 看看是否有帮助。如果不是,您可能想要分享protein.csv的内容,以便我可以尝试重现您的问题。