rp-value

How to fetch p-value from ADF test (ur.df)?


i have the following r code:

for (p in 1:5) {
  # Perform ADF test
  R.urdf_IND <- ur.df(L.ts$m_IND, type = "trend", lags = p)
  # Extract test statistic
  test_statistic <- R.urdf_IND@teststat[1, "tau3"]
  # Extract p-value
  p_value <- summary(R.urdf_IND)@pval??????
  # Store results in the table
  results_table <- rbind(results_table, data.frame(Lag = p, p_value = p_value, test_statistic = test_statistic))
}
print(results_table)

I want to perform a ADF test and store the test statistic and the p-value for the corresponding lag in a table. I am facing errors in extracting the p-value via the summary (I tried @pval which gives NULL...) Do you have an idea on how to fetch those information or should I use a different ADF function? Thank you in advanced!

I tried to fetch the p-values outside the loop with this code:

R.urdf_IND_l1 <- ur.df(L.ts$m_IND, type = "trend", lags = 1)
sum_urdf_1 <- summary(R.urdf_IND_l1)
sum_urdf_1@pval

but get the Output: NULL If I print sum_urdf_1 I receive the typical ADF output with a p-value of 0.0165. I also asked ChatGPT with no solution.


Solution

  • Get the p-value for the F statistics with

    mod.fstat <- R.urdf_IND@testreg$fstatistic
    
    pf(mod.fstat["value"], mod.fstat["numdf"], mod.fstat["dendf"], lower.tail=F)