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




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



enter image description here


1 Answer 1


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


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.

  • $\begingroup$ Im not able to fetch the p-value with the above code $\endgroup$ Aug 19, 2020 at 7:29
  • $\begingroup$ > attr(lc.df, 'testreg')$coefficients[,4] (Intercept) z.lag.1 tt z.diff.lag1 z.diff.lag2 z.diff.lag3 0.027024311 0.027658041 0.025174790 0.293449348 0.050021177 0.004203314 $\endgroup$ Aug 19, 2020 at 7:30
  • $\begingroup$ This is what i got by using your logic, im want p-value:0.01325(check the image) $\endgroup$ Aug 19, 2020 at 7:30
  • $\begingroup$ Those are the same values as you show in the right column of your table? In any case, using dput() you should be able to be able to figure out how to get any value from that table. $\endgroup$
    – Bob Jansen
    Aug 19, 2020 at 7:33
  • $\begingroup$ thanks 1-pf() worked $\endgroup$ Aug 19, 2020 at 8:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.