0

The task is to check whether there is cointegration between time series

   DT                  Os.ilosc   BG.ilosc
 1 2023-01-01 00:00:00       45           799.
 2 2023-01-01 01:00:00       45          1100.
 3 2023-01-01 02:00:00       45          1131.
 4 2023-01-01 03:00:00       45          1077.
 5 2023-01-01 04:00:00       45.8        1094.
 6 2023-01-01 05:00:00       45          1158.
 7 2023-01-01 06:00:00       44.8        1060 
 8 2023-01-01 07:00:00       45.2         984.
 9 2023-01-01 08:00:00       45.2         965.
10 2023-01-01 09:00:00       45.8         939.

The process is fast, so data is saved every hour. I am using adf.test from the tseries package. Do I need to transform my dataframe into a time series? I usually come across daily or monthly, quarterly, yearly time series: How to convert dataframe into time series?

How to transform a dataframe containing hours?

GrBa
  • 381
  • 1
  • 9

1 Answers1

1

The adf.test() checks for stationarity in a time series. Its a prerequisite for cointegratiuon analyses.

However, to check for cointegration between two time series, we often use the Johansen Test, as the ADF test is used on single time series to check for stationarity, not for cointegration directly.

You can check for cointegration using the ca.jo() function from the "urca" package, which performs the Johansen Test:

# Install and load necessary package
if(!require(urca)) { install.packages("urca") }
library(urca)
#assuming these are the different time series you're interested in
time_series <- df[,c("Os.ilosc", "BG.ilosc")]

# Run the Johansen Test
jotest <- ca.jo(time_series, type="trace", ecdet="none", K=2)
summary(jotest)

Its unclear which time series you are referring to though. Do you have that data for another time series? Or are you just trying to check this time series for stationarity which is why you need the adf.test?

If thats the case, try making a time series object and then runing the adf.test

df$DT <- as.POSIXct(df$DT)

adf.test(df$Os.ilosc)

adf.test(df$BG.ilosc)
Chris Bova
  • 134
  • 1
  • 2
  • 9
  • 1
    Thank you for your comments and broader context of the issue. I planned to check the stationarity of "Os.ilosc" and "BG.ilosc". In the next step, I wanted to check the cointegration (```coint.test``` from the ```aTSA``` package). If the time series (Os.ilosc and BG.ilosc) were not stationary, I planned to perform differentiation. The aim is to develop a model for predicting the production volume of BG.ilosc based on Os.ilosc. Though I don't know which model to use. – GrBa Jul 10 '23 at 07:19