简体   繁体   中英

NAs in y in Statistical Analysis

I have a problem with the following code below:

return1 = diff(log(bist))
return1[,1] <- na.locf(return1[,1],na.rm = F)

When I run the Dickey–Fuller test, I get the following error:

df.test <- ur.df(return1, type =c("drift"),lags = 0 )

Error in ur.df(return1, type = c("drift"), lags = 0) : NAs in y.

Do you know how to fix the error?

I'm guessing it's because of your data and the distribution of NA s due to the log. If the first elements in log. If the first elements in return1 are missing then they will not be filled in with na.locf`.

If you change the first part of the code to

return1=diff(log(bist))
return1[,1]<-na.locf(return1[,1],na.rm = TRUE)

then you will have removed the first missing elements. Not sure how that matches with the ur.df test, though.

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.

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