cointegration using engle_granger_test y variable is differenced_real_sales_ts and x variables are real_industrial_production_ts, real_interest_rate_ts and cpi_ts in r

To test for cointegration using the Engle-Granger test in R, you can use the ca.jo function from the urca package. Here's how you can perform the test with your specific variables:

First, make sure you have the urca package installed:

main.r
install.packages("urca")
25 chars
2 lines

Load the required packages:

main.r
library(urca)
14 chars
2 lines

Assuming you have loaded your data into variables differenced_real_sales_ts, real_industrial_production_ts, real_interest_rate_ts, and cpi_ts, you can run the Engle-Granger test as follows:

main.r
# Combine the variables into a data frame
data <- data.frame(differenced_real_sales_ts, real_industrial_production_ts, real_interest_rate_ts, cpi_ts)

# Perform the cointegration test
result <- ca.jo(data, type = "eigen", ecdet = "none", K = 2)

# Derive test statistics
summary(result)
287 chars
9 lines

The ca.jo function performs the Johansen-Engle test for cointegration. The type argument specifies the method for selecting the number of cointegrating vectors, and the ecdet argument determines if constant and/or trend terms are included in the model. In this example, we use the eigenvalue method for selecting the number of cointegrating vectors and exclude any deterministic terms (none).

The summary function provides various test statistics such as Eigenvalues, trace statistics, and critical values. You can interpret the test results based on these statistics.

Remember to adjust the code accordingly if you have different variable names or want to include different deterministic terms or use alternative selection methods.

Note that the Engle-Granger test assumes that the time series are I(1) (integrated of order 1). Make sure your variables are differenced appropriately if they are not already in stationary form.

gistlibby LogSnag