Skip to content
All library documents

Extracting Regression and Test P-Values from an R Unit Root Test

Article Quant Q&A · Author: syed tabrez

Summary

The document explains how to inspect the result object from the urca package's augmented Dickey–Fuller test in R to retrieve coefficient p-values. The suggested approach uses object inspection to find the stored regression summary, then accesses the p-value column in its coefficient table. This offers a practical way to extract values when the package output does not present them in the desired form.

It distinguishes coefficient-level p-values from a p-value for the overall test. The latter is described as being calculated from an F distribution using values available in the object. The example is specific to this package and test output; the response notes that a package convenience method may exist, but does not establish whether one does. It also gives no broader interpretation of unit root test results or guidance on model specification.

Key ideas

  • Inspecting an R object can reveal data stored in its attributes.
  • The regression summary stored with the test object includes a coefficient table with p-values.
  • Coefficient p-values and an overall test p-value are distinct quantities.
  • The example computes the overall p-value from an F distribution.

Tags

Full text
# How to extract p-value from ur.df package of urca in R?


# How to extract p-value from ur.df package of urca in R?












I want to extract the p-value from the below output. How do i get it?

```
library(urca)

data(Raotbl3)

attach(Raotbl3)

lc.df <- ur.df(y=lc, lags=3, type='trend')

summary(lc.df)
```

### Output:

## Answer by Bob Jansen (score 1)

https://quant.stackexchange.com/a/57462

Using `dput()` you can inspect an R object, e.g.

```
dput(lc.df)
```

Using that I found that the p-values are stored in an attribute `'testreg'` which turns out to be a list with class `summary.lm` (again with `dput()`). The coefficient table is in `coefficients` so getting the p-values is easy enough:

```
attr(lc.df, 'testreg')$coefficients[,4]
```

It's not unlikely that `urca` has a convenience method for this too.

Admittedly, finding the p-value of the whole test is a bit more tricky, the p-value is calculated on the fly as

```
1 - pf(3.07132302249161, 5, 89)
```

These values can be extracted from the object.

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.