Magicmahdi
Magicmahdi

Reputation: 83

How to extract p-value in var package?

How can we extract p-value in var package. When we write summary(var), where 'var' is the name of var model, we see p-value at the bottom the results, but how we can extract this value? For example:

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)

after summary(vardatap_3) we can see the p-value, like this:

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 

at the end of thi output, we see that p-value is less than 2.2e-16. when I run this code:

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

the output is:

$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 

and it's not the p-value. How can I reach to this value?

Upvotes: 1

Views: 1484

Answers (1)

Sven Hohenstein
Sven Hohenstein

Reputation: 81683

If fit is the object returned by the VAR function, you can use

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

to generate a list of vectors of the p-values.

If you want to extract/calculate the p-values for the whole models, you can try

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

Upvotes: 1

Related Questions