GARCH

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

GARCH

Arun.stat
Dear all R-users,

I have a GARCH related query. Suppose I fit a GARCH(1,1) model on a
dataframe dat

>garch1 = garch(dat)
>summary(garch1)
Call:
garch(x = dat)

Model:
GARCH(1,1)

Residuals:
    Min      1Q  Median      3Q     Max
-4.7278 -0.3240  0.0000  0.3107 12.3981

Coefficient(s):
    Estimate  Std. Error  t value Pr(>|t|)
a0 1.212e-04   2.053e-06    59.05   <2e-16 ***
a1 1.001e+00   4.165e-02    24.04   <2e-16 ***
b1 2.435e-15   1.086e-02 2.24e-13        1
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Diagnostic Tests:
        Jarque Bera Test

data:  Residuals
X-squared = 54480.76, df = 2, p-value < 2.2e-16

Now I want to store the value of Pr(>|t|) for coefficient a0, a1, and b1,
and also values of these coefficients, so that I can use them in future
separately. I know that I can do it for coefficients by using the command:
coef(garch1)["a0"] etc, but not for Pr(>|t|). Can anyone please tell me how
to do this?

Thanks and regards,

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: GARCH

Jeff Newmiller
Arun Kumar Saha wrote:

> Dear all R-users,
>
> I have a GARCH related query. Suppose I fit a GARCH(1,1) model on a
> dataframe dat
>
>
>>garch1 = garch(dat)
>>summary(garch1)
>
> Call:
> garch(x = dat)
>
> Model:
> GARCH(1,1)
>
> Residuals:
>     Min      1Q  Median      3Q     Max
> -4.7278 -0.3240  0.0000  0.3107 12.3981
>
> Coefficient(s):
>     Estimate  Std. Error  t value Pr(>|t|)
> a0 1.212e-04   2.053e-06    59.05   <2e-16 ***
> a1 1.001e+00   4.165e-02    24.04   <2e-16 ***
> b1 2.435e-15   1.086e-02 2.24e-13        1
> ---
> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
>
> Diagnostic Tests:
>         Jarque Bera Test
>
> data:  Residuals
> X-squared = 54480.76, df = 2, p-value < 2.2e-16
>
> Now I want to store the value of Pr(>|t|) for coefficient a0, a1, and b1,
> and also values of these coefficients, so that I can use them in future
> separately. I know that I can do it for coefficients by using the command:
> coef(garch1)["a0"] etc, but not for Pr(>|t|). Can anyone please tell me how
> to do this?

This is less a question about GARCH and more a question about how R works
(which I know is true because I didn't know what GARCH was when I read the
question and I still don't but I can provide you a usable answer).

You can use the str() function to see the structure of an object in R:

 > garch1.summary <- summary(garch1)
 > str(garch1.summary)
List of 6
  $ residuals: Time-Series [1:999] from 2 to 1000:  0.206  0.709  0.476

                                                    -0.291 -1.676 ...
   ..- attr(*, "na.removed")= int 1
  $ coef     : num [1:3, 1:4] 0.0799 0.6287 0.2118 0.0110 0.0755 ...
   ..- attr(*, "dimnames")=List of 2
   .. ..$ : chr [1:3] "a0" "a1" "b1"
   .. ..$ : chr [1:4] " Estimate" " Std. Error" " t value" "Pr(>|t|)"
  $ call     : language garch(x = x, order = c(1, 1))
  $ order    : Named num [1:2] 1 1
   ..- attr(*, "names")= chr [1:2] "p" "q"
  $ j.b.test :List of 5
   ..$ statistic: Named num 0.468
   .. ..- attr(*, "names")= chr "X-squared"
   ..$ parameter: Named num 2
   .. ..- attr(*, "names")= chr "df"
   ..$ p.value  : Named num 0.791
   .. ..- attr(*, "names")= chr "X-squared"
   ..$ method   : chr "Jarque Bera Test"
   ..$ data.name: chr "Residuals"
   ..- attr(*, "class")= chr "htest"
  $ l.b.test :List of 5
   ..$ statistic: Named num 1.01
   .. ..- attr(*, "names")= chr "X-squared"
   ..$ parameter: Named num 1
   .. ..- attr(*, "names")= chr "df"
   ..$ p.value  : num 0.316
   ..$ method   : chr "Box-Ljung test"
   ..$ data.name: chr "Squared.Residuals"
   ..- attr(*, "class")= chr "htest"
  - attr(*, "class")= chr "summary.garch"

 From this you can see that there is a "coef" list member
that contains the information you are after:

 > garch1.summary$coef
      Estimate  Std. Error  t value     Pr(>|t|)
a0 0.07989234  0.01104719 7.231912 4.762857e-13
a1 0.62870916  0.07551333 8.325804 0.000000e+00
b1 0.21184013  0.05384033 3.934599 8.333558e-05

this is apparently a matrix, so try matrix notation:

 > garch1.summary$coef[,4]
           a0           a1           b1
4.762857e-13 0.000000e+00 8.333558e-05

or

 > garch1.summary$coef[1,4]
[1] 4.762857e-13

Having said all that, this solution depends on implementation details
of the innards of the relevant objects, and in general if accessor
functions are available they should be used instead... but in this
case such accessors don't seem to be available.

 > help.search("garch-methods", package="tseries")

--
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<[hidden email]>        Basics: ##.#.       ##.#.  Live Go...
                                       Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: GARCH

Prof Brian Ripley
Why do you think

> help.search("garch-methods", package="tseries")

finds accessor functions?  That is notation for S4 methods, and "garch" is
an S3 class so there will be none.  Here there _is_ an accessor, coef(),
and you can find that there is by

> methods(class="garch")
[1] coef.garch*      fitted.garch*    logLik.garch*    plot.garch*
[5] predict.garch*   print.garch*     residuals.garch* summary.garch*

    Non-visible functions are asterisked

Note though that inherited methods might be relevant too (e.g. default
methods) and indeed it seems that here the default method for coef would
work just as well.


On Tue, 20 Jun 2006, Jeff Newmiller wrote:

> Arun Kumar Saha wrote:
>> Dear all R-users,
>>
>> I have a GARCH related query. Suppose I fit a GARCH(1,1) model on a
>> dataframe dat
>>
>>
>>> garch1 = garch(dat)
>>> summary(garch1)
>>
>> Call:
>> garch(x = dat)
>>
>> Model:
>> GARCH(1,1)
>>
>> Residuals:
>>     Min      1Q  Median      3Q     Max
>> -4.7278 -0.3240  0.0000  0.3107 12.3981
>>
>> Coefficient(s):
>>     Estimate  Std. Error  t value Pr(>|t|)
>> a0 1.212e-04   2.053e-06    59.05   <2e-16 ***
>> a1 1.001e+00   4.165e-02    24.04   <2e-16 ***
>> b1 2.435e-15   1.086e-02 2.24e-13        1
>> ---
>> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
>>
>> Diagnostic Tests:
>>         Jarque Bera Test
>>
>> data:  Residuals
>> X-squared = 54480.76, df = 2, p-value < 2.2e-16
>>
>> Now I want to store the value of Pr(>|t|) for coefficient a0, a1, and b1,
>> and also values of these coefficients, so that I can use them in future
>> separately. I know that I can do it for coefficients by using the command:
>> coef(garch1)["a0"] etc, but not for Pr(>|t|). Can anyone please tell me how
>> to do this?
>
> This is less a question about GARCH and more a question about how R works
> (which I know is true because I didn't know what GARCH was when I read the
> question and I still don't but I can provide you a usable answer).
>
> You can use the str() function to see the structure of an object in R:
>
> > garch1.summary <- summary(garch1)
> > str(garch1.summary)
> List of 6
>  $ residuals: Time-Series [1:999] from 2 to 1000:  0.206  0.709  0.476
>
>                                                    -0.291 -1.676 ...
>   ..- attr(*, "na.removed")= int 1
>  $ coef     : num [1:3, 1:4] 0.0799 0.6287 0.2118 0.0110 0.0755 ...
>   ..- attr(*, "dimnames")=List of 2
>   .. ..$ : chr [1:3] "a0" "a1" "b1"
>   .. ..$ : chr [1:4] " Estimate" " Std. Error" " t value" "Pr(>|t|)"
>  $ call     : language garch(x = x, order = c(1, 1))
>  $ order    : Named num [1:2] 1 1
>   ..- attr(*, "names")= chr [1:2] "p" "q"
>  $ j.b.test :List of 5
>   ..$ statistic: Named num 0.468
>   .. ..- attr(*, "names")= chr "X-squared"
>   ..$ parameter: Named num 2
>   .. ..- attr(*, "names")= chr "df"
>   ..$ p.value  : Named num 0.791
>   .. ..- attr(*, "names")= chr "X-squared"
>   ..$ method   : chr "Jarque Bera Test"
>   ..$ data.name: chr "Residuals"
>   ..- attr(*, "class")= chr "htest"
>  $ l.b.test :List of 5
>   ..$ statistic: Named num 1.01
>   .. ..- attr(*, "names")= chr "X-squared"
>   ..$ parameter: Named num 1
>   .. ..- attr(*, "names")= chr "df"
>   ..$ p.value  : num 0.316
>   ..$ method   : chr "Box-Ljung test"
>   ..$ data.name: chr "Squared.Residuals"
>   ..- attr(*, "class")= chr "htest"
>  - attr(*, "class")= chr "summary.garch"
>
> From this you can see that there is a "coef" list member
> that contains the information you are after:
>
> > garch1.summary$coef
>      Estimate  Std. Error  t value     Pr(>|t|)
> a0 0.07989234  0.01104719 7.231912 4.762857e-13
> a1 0.62870916  0.07551333 8.325804 0.000000e+00
> b1 0.21184013  0.05384033 3.934599 8.333558e-05
>
> this is apparently a matrix, so try matrix notation:
>
> > garch1.summary$coef[,4]
>           a0           a1           b1
> 4.762857e-13 0.000000e+00 8.333558e-05
>
> or
>
> > garch1.summary$coef[1,4]
> [1] 4.762857e-13
>
> Having said all that, this solution depends on implementation details
> of the innards of the relevant objects, and in general if accessor
> functions are available they should be used instead... but in this
> case such accessors don't seem to be available.
>
> > help.search("garch-methods", package="tseries")
>
>

--
Brian D. Ripley,                  [hidden email]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: GARCH

Jeff Newmiller
Prof Brian Ripley wrote:
> Why do you think
>
>> help.search("garch-methods", package="tseries")
>
> finds accessor functions?  That is notation for S4 methods, and "garch"
> is an S3 class so there will be none.  Here there _is_ an accessor,
> coef(), and you can find that there is by

Probably because I used it, found a mention of various extraction functions
including coef(), and could not find a way to access "Pr(>|t|)" using
coef(). Nor have I had luck with
  help.search("summary.garch", package="tseries")

Possibly also because I have not yet figured out the difference between
S4 and S3 methods, but since the result of my  help.search call displayed S3
functions I don't see how knowing this difference would have helped.

>> methods(class="garch")
>
> [1] coef.garch*      fitted.garch*    logLik.garch*    plot.garch*
> [5] predict.garch*   print.garch*     residuals.garch* summary.garch*
>
>    Non-visible functions are asterisked
>
> Note though that inherited methods might be relevant too (e.g. default
> methods) and indeed it seems that here the default method for coef would
> work just as well.

Given Arun Kumar Saha's question...

 > > Now I want to store the value of Pr(>|t|) for coefficient a0, a1,
 > > and b1, and also values of these coefficients, so that I can use
 > > them in future separately. I know that I can do it for coefficients
 > > by using the command:
 > > coef(garch1)["a0"] etc, but not for Pr(>|t|). Can anyone please
 > > tell me how to do this?

... I don't see how coef() helps because I have yet to figure out how
to use coef() (or any other accessor) to find " Std. Error" of the
coefficient, much less "Pr(>|t|)". summary.garch seems to have only a
print method, with no accessors at all. Can you offer a solution?

--
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<[hidden email]>        Basics: ##.#.       ##.#.  Live Go...
                                       Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: GARCH

Spencer Graves
          I'll outline here how you can solve this kind of problem, using the
first example in the 'garch' help page:

library(tseries)
      n <- 1100
      a <- c(0.1, 0.5, 0.2)  # ARCH(2) coefficients
      e <- rnorm(n)
      x <- double(n)
      x[1:2] <- rnorm(2, sd = sqrt(a[1]/(1.0-a[2]-a[3])))
      for(i in 3:n)  # Generate ARCH(2) process
      {
        x[i] <- e[i]*sqrt(a[1]+a[2]*x[i-1]^2+a[3]*x[i-2]^2)
      }
      x <- ts(x[101:1100])
      x.arch <- garch(x, order = c(0,2))  # Fit ARCH(2)
(sum.arch <- summary(x.arch))
<snip>
     Estimate  Std. Error  t value Pr(>|t|)
a0   0.09887     0.01013    9.764  < 2e-16 ***
a1   0.43104     0.05276    8.170 2.22e-16 ***
a2   0.31261     0.05844    5.350 8.82e-08 ***
<snip>

          Then I tried 'str(sum.arch)'.  This told me it is a list with 6
components, and the one I want is named 'coef'.  This led me to examine
'sum.arch$coef', which includes the desired numbers.  Moreover,
'class(sum.arch$coef)' told me this is a 'matrix'.  This information
suggests that the following might be what you requested:

  sum.arch$coef[, "Pr(>|t|)"]
           a0           a1           a2
0.000000e+00 2.220446e-16 8.815239e-08

          Hope this helps.
          Spencer Graves

Jeff Newmiller wrote:

> Prof Brian Ripley wrote:
>> Why do you think
>>
>>> help.search("garch-methods", package="tseries")
>> finds accessor functions?  That is notation for S4 methods, and "garch"
>> is an S3 class so there will be none.  Here there _is_ an accessor,
>> coef(), and you can find that there is by
>
> Probably because I used it, found a mention of various extraction functions
> including coef(), and could not find a way to access "Pr(>|t|)" using
> coef(). Nor have I had luck with
>   help.search("summary.garch", package="tseries")
>
> Possibly also because I have not yet figured out the difference between
> S4 and S3 methods, but since the result of my  help.search call displayed S3
> functions I don't see how knowing this difference would have helped.
>
>>> methods(class="garch")
>> [1] coef.garch*      fitted.garch*    logLik.garch*    plot.garch*
>> [5] predict.garch*   print.garch*     residuals.garch* summary.garch*
>>
>>    Non-visible functions are asterisked
>>
>> Note though that inherited methods might be relevant too (e.g. default
>> methods) and indeed it seems that here the default method for coef would
>> work just as well.
>
> Given Arun Kumar Saha's question...
>
>  > > Now I want to store the value of Pr(>|t|) for coefficient a0, a1,
>  > > and b1, and also values of these coefficients, so that I can use
>  > > them in future separately. I know that I can do it for coefficients
>  > > by using the command:
>  > > coef(garch1)["a0"] etc, but not for Pr(>|t|). Can anyone please
>  > > tell me how to do this?
>
> ... I don't see how coef() helps because I have yet to figure out how
> to use coef() (or any other accessor) to find " Std. Error" of the
> coefficient, much less "Pr(>|t|)". summary.garch seems to have only a
> print method, with no accessors at all. Can you offer a solution?
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html