Can't seem to get ACF of differenced variable in R

925 views Asked by At

I am a novice in R and I have a time series variable (stock returns), I create the differenced variable diff(stock , lag=1 , differences=1)

This works well, I plot it and it looks rather stationary. However, when I try to run the dicky fuller test it gives me an error, even though the dicky fuller test works fine on the original variable (stock), which is ofc non stationary.

error:

adf.test(stock) Error in adf.test(stock) : NAs in x

I think the same issue that keeps me from running a dicky fuller test on the differenced variable also keeps me from testing the acf and pacf of the diferenced variable. in this case it pritns the following error.

pacf(stock) Error in na.fail.default(as.ts(x)) : missing values in object

I think that I am missing data, but I do not understand why.

Thank you in advance, and I apologise for being such a novice.

Best,

1

There are 1 answers

1
ira On

When you run the diff() function, the first element will be a missing value, because you can't calculate the difference for the first observation in the original Time Series. Either drop this missing observation (with something like x[!is.na(x)]), or replace it with zero.