简体   繁体   English

R:从summary()提取值

[英]R: Extracting values from summary()

I'm using the urca package to conduct some calculations on unit roots. 我正在使用urca软件包对单位根进行一些计算。 For example, let's use following dataset from the urca package: 例如,让我们使用urca包中的以下数据集:

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

Applying the Augmented Dickey Fuller test looks like: 应用增强的Dickey Fuller测试如下所示:

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"). 但是,从“ pval”或“ lag”中提取值不起作用(返回“ NULL”)。

When I looked here , I discovered that the problem appears with every variable that is "=NULL". 当我在这里查看时 ,我发现问题出在“ = NULL”的每个变量上。 Not sure if it's important. 不知道这是否重要。

setMethod("summary", "ur.df", function(object){
  return(new("sumurca", classname="ur.df", test.name=object@test.name,     
             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? 任何想法如何解决这个问题?

Get the slots with @ and after that as usual: 使用@获取插槽,然后像往常一样:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM