Christopher
Christopher

Reputation: 2232

R: Extracting values from summary()

I'm using the urca package to conduct some calculations on unit roots. For example, let's use following dataset from the urca package:

library(urca)
data(Raotbl3)
attach(Raotbl3)

Applying the Augmented Dickey Fuller test looks like:

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

In return, we get a summary of all values. However, I want to extract only specific values. The possible fields are here:

slotNames(summary(lc.df))
#  [1] "classname" "test.name" "testreg"   "teststat"  "cval"      "bpoint"        "signif"    "model"     "type"      "auxstat"  
# [11] "lag"       "H"         "A"         "lambda"    "pval"      "V"             "W"         "P"       

Interestingly,

ur.df(y=lc, lags=3, type='trend')@teststat 
#             tau3  phi2  phi3
# statistic -2.239 3.738 2.597

or

ur.df(y=lc, lags=3, type='trend')@cval
#       1pct  5pct 10pct
# tau3 -4.04 -3.45 -3.15
# phi2  6.50  4.88  4.16
# phi3  8.73  6.49  5.47

works just fine. However, extracting values from "pval" or "lag" does not work (returns "NULL").

When I looked here, I discovered that the problem appears with every variable that is "=NULL". Not sure if it's important.

setMethod("summary", "ur.df", function(object){
  return(new("sumurca", classname="ur.df", [email protected],     
             testreg=object@testreg, teststat=object@teststat, 
             cval=object@cval, bpoint=NULL, signif=NULL, 
             model=object@model, type=NULL, auxstat=NULL, lag=NULL, 
             H=NULL, A=NULL, lambda=NULL, pval=NULL, V=NULL, W=NULL, P=NULL))
})

Any idea how to solve this?

Upvotes: 3

Views: 15955

Answers (1)

Robert
Robert

Reputation: 5152

Get the slots with @ and after that as usual:

summary(lc.df)@testreg$coefficients
summary(lc.df)@testreg$coefficients[-c(1,3),4]

Upvotes: 2

Related Questions