[R] Extracting slots from an object (e.g.: object produced by unit root test function "urdfTest")
jpm miao
miaojpm at gmail.com
Thu Mar 12 09:04:05 CET 2015
Hi,
I run a statistical test function in the package "fUnitRoots" that
returns a S4 object but I am wondering how to extract the p-value, one of
the output elements.
The document of the function "urdfTest":
.....
All tests return an object of class "fHTEST" with the following slots:
@call
.....
@test
a list object which holds the output of the underlying test function.
@title
.....
The entries of the @test slot include the following components:
$statistic
......
$p.value
the p-value of the test.
.....
(end)
I store the result of the test test in an element of a list
(adf1["r3m"][[1]]), and I want to extract the p-value. I was expecting the
p-value via adf1["r3m"][[1]]@test$p.value but it gives only an error
message. Could someone tell me how to extract the p-value? Thanks!!!
>adf1["r3m"][[1]]<-urdfTest(dat[,i], lags = 1, type = "ct")
> adf1["r3m"][[1]]
[1] " "
[2] " Test regression trend "
[3] " "
[4] " Call:"
[5] " lm(formula = z.diff ~ z.lag.1 + 1 + tt + z.diff.lag)"
[6] " "
[7] " Residuals:"
[8] " Min 1Q Median 3Q Max "
[9] " -3.0785 -0.0485 0.0072 0.0627 3.5672 "
[10] " "
[11] " Coefficients:"
[12] " Estimate Std. Error t value Pr(>|t|) "
[13] " (Intercept) -1.733e-02 9.529e-03 -1.818 0.06910 . "
[14] " z.lag.1 -7.060e-03 2.343e-03 -3.013 0.00261 ** "
[15] " tt 5.299e-06 4.927e-06 1.076 0.28221 "
[16] " z.diff.lag -1.035e-01 1.859e-02 -5.569 2.81e-08 ***"
[17] " ---"
[18] " Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1"
[19] " "
[20] " Residual standard error: 0.2107 on 2864 degrees of freedom"
[21] " Multiple R-squared: 0.01461,\tAdjusted R-squared: 0.01358 "
[22] " F-statistic: 14.15 on 3 and 2864 DF, p-value: 3.716e-09"
[23] " "
[24] " "
[25] " Value of test-statistic is: -3.0134 3.0697 4.5828 "
[26] " "
[27] " Critical values for test statistics: "
[28] " 1pct 5pct 10pct"
[29] " tau3 -3.96 -3.41 -3.12"
[30] " phi2 6.09 4.68 4.03"
[31] " phi3 8.27 6.25 5.34"
> adf1["r3m"][[1]]@test
Error: trying to get slot "test" from an object of a basic class
("character") with no slots
> adf1["r3m"][[1]]@test$p-value
Error: trying to get slot "test" from an object of a basic class
("character") with no slots
[[alternative HTML version deleted]]
More information about the R-help
mailing list