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.r25 chars2 lines
Load the required packages:
main.r14 chars2 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.r287 chars9 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