如何在var包中提取p值?

时间:2013-11-10 11:33:23

标签: r

我们如何在var包中提取p值。当我们写summary(var)时,' var'是var模型的名称,我们在底部看到p值的结果,但我们如何才能提取这个值? 例如:

library(vars)
symbols=c('^N225','^FTSE','^GSPC')
getSymbols(symbols,src='yahoo', from="2003-04-28", to="2007-10-29")
period="daily"
A1=periodReturn(N225$N225.Adjusted,period=period)
B1=periodReturn(FTSE$FTSE.Adjusted,period=period)
C1=periodReturn(GSPC$GSPC.Adjusted,period=period)
datap_1<-cbind(A1,B1,C1)
datap_1<-na.omit(datap_1)   
datap_1<-(datap_1)^2
vardatap_3<-VAR(datap_1,p=3,type="none")
summary(vardatap_3)

summary(vardatap_3)之后我们可以看到p值,如下所示:

VAR Estimation Results:
========================= 
Endogenous variables: N225, FTSE, SP500 
Deterministic variables: none 
Sample size: 1055 
Log Likelihood: 23637.848 
Roots of the characteristic polynomial:
0.8639 0.6224 0.6224 0.5711 0.5711 0.5471 0.5471 0.4683 0.4683
Call:
VAR(y = datap_1, p = 3, type = "none")
Estimation results for equation N225: 
===================================== 
N225 = N225.l1 + FTSE.l1 + SP500.l1 + N225.l2 + FTSE.l2 + SP500.l2 + N225.l3 + FTSE.l3 + SP500.l3 
     Estimate Std. Error t value Pr(>|t|)    
N225.l1   0.03436    0.03116   1.103    0.270    
FTSE.l1   0.47025    0.06633   7.089 2.48e-12 ***
SP500.l1  0.60717    0.07512   8.083 1.74e-15 ***
N225.l2   0.14938    0.03057   4.886 1.19e-06 ***
FTSE.l2  -0.05440    0.06744  -0.807    0.420    
SP500.l2 -0.09024    0.07782  -1.160    0.246    
N225.l3   0.16809    0.02924   5.749 1.18e-08 ***
FTSE.l3   0.04480    0.06597   0.679    0.497    
SP500.l3 -0.01007    0.07941  -0.127    0.899    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.0002397 on 1046 degrees of freedom
Multiple R-Squared: 0.3099,     Adjusted R-squared: 0.304 
F-statistic:  52.2 on 9 and 1046 DF,  p-value: < 2.2e-16 

在输出结束时,我们看到p值小于2.2e-16。 当我运行这段代码时:

lapply(coef(vardatap_3), "[", , "Pr(>|t|)"))

输出是:

$N225
N225.l1      FTSE.l1     SP500.l1      N225.l2      FTSE.l2     SP500.l2 
2.703965e-01 2.479333e-12 1.738649e-15 1.189843e-06 4.201011e-01 2.464906e-01 
N225.l3      FTSE.l3     SP500.l3 
1.177588e-08 4.971743e-01 8.990626e-01 

$FTSE
N225.l1      FTSE.l1     SP500.l1      N225.l2      FTSE.l2     SP500.l2 
8.849041e-01 2.730359e-09 3.415860e-10 8.673114e-01 5.232037e-02 2.887330e-10 
N225.l3      FTSE.l3     SP500.l3 
8.698535e-02 6.215429e-15 9.290871e-02 

$SP500
N225.l1      FTSE.l1     SP500.l1      N225.l2      FTSE.l2     SP500.l2 
2.431252e-01 3.928462e-02 4.362288e-02 1.007840e-01 1.141799e-01 8.819460e-03 
N225.l3      FTSE.l3     SP500.l3 
1.129084e-03 1.426315e-01 1.307562e-06 

并且它不是p值。我怎样才能达到这个值?

1 个答案:

答案 0 :(得分:1)

如果fitVAR函数返回的对象,则可以使用

lapply(coef(fit), "[", , "Pr(>|t|)")

生成p值的向量列表。

如果要提取/计算整个模型的p值,可以尝试

sapply(summary(fit)$varresult, function(x) {
  tmp <- x[["fstatistic"]]
  pf(tmp[1], tmp[2], tmp[3], lower.tail = FALSE)
})