[R] ARCH LM test for univariant time series
Pfaff, Bernhard Dr.
Bernhard_Pfaff at fra.invesco.com
Wed Feb 6 09:49:38 CET 2008
Hello Spencer,
splendid. Please go ahead. I am wondering if one should return the lm-object too and not only the htest-object. The benefit would be, that summary(lm-object) would return the mentioned F-test in the R-Help thread too, or one can return just the F-test result as a separate list element. If so, a more appropriate function name would be archtest().
What do you think?
Best,
Bernhard
Dr. Bernhard Pfaff
International Structured Products Group
Director
Invesco Asset Management Deutschland GmbH
Bleichstrasse 60-62
D-60313 Frankfurt am Main
Tel: +49(0)69 29807 230
Fax: +49(0)69 29807 178
Email: bernhard_pfaff at fra.invesco.com
Geschäftsführer: Karl Georg Bayer, Bernhard Langer, Dr. Jens Langewand, Alexander Lehmann, Christian Puschmann
Handelsregister: Frankfurt am Main, HRB 28469
Sitz der Gesellschaft: Frankfurt am Main
>-----Ursprüngliche Nachricht-----
>Von: Spencer Graves [mailto:spencer.graves at pdf.com]
>Gesendet: Mittwoch, 6. Februar 2008 05:02
>An: Pfaff, Bernhard Dr.
>Cc: tom soyer; r-help at r-project.org
>Betreff: Re: AW: [R] ARCH LM test for univariant time series
>
>Dear Bernhard:
>
> Thanks very much. Unless you object, I shall add it to the
>'FinTS' library as "ArchTest" (comparable to the S-PLUS Finmetrics
>'archTest' function) -- with a worked example in '\scripts\ch03.R'.
>
> Best Wishes,
> Spencer
>
>Pfaff, Bernhard Dr. wrote:
>> Dear All,
>>
>>
>> one can visually inspect ARCH-effects by plotting acf/pacf of the
>> squared residuals from an OLS-estimation. This can be as simple as a
>> demeaned series. Further one can run an auxiliary regression by
>> regressing q lagged squared values and a constant on the
>squared series
>> itself. This test statistic (N-q)*R^2 is distributed as chisq with q
>> degrees of freedom.
>>
>> Something along the lines:
>>
>> archlmtest <- function (x, lags, demean = FALSE)
>> {
>> x <- as.vector(x)
>> if(demean) x <- scale(x, center = TRUE, scale = FALSE)
>> lags <- lags + 1
>> mat <- embed(x^2, lags)
>> arch.lm <- summary(lm(mat[, 1] ~ mat[, -1]))
>> STATISTIC <- arch.lm$r.squared * length(resid(arch.lm))
>> names(STATISTIC) <- "Chi-squared"
>> PARAMETER <- lags - 1
>> names(PARAMETER) <- "df"
>> PVAL <- 1 - pchisq(STATISTIC, df = PARAMETER)
>> METHOD <- "ARCH LM-test"
>> result <- list(statistic = STATISTIC, parameter = PARAMETER,
>> p.value = PVAL, method = METHOD, data.name =
>> deparse(substitute(x)))
>> class(result) <- "htest"
>> return(result)
>> }
>>
>> should work and yield equal results as mentioned earlier in
>this thread.
>>
>> Best,
>> Bernhard
>>
>>
>>
>>> Spencer,
>>>
>>> The warning message is sent from VAR, it basically lets you
>>> know that the
>>> data it used had no column names and it had to supply them
>>> using y1, y2, y3,
>>> etc. It can be suppressed by including options(warn=-1) in the
>>> function.
>>>
>>> Anyway, it seems that the p value from my function does not match
>>> FinMetrics'. I guess the function doesn't work... hmm...
>>>
>>>
>>> On 2/2/08, Spencer Graves <spencer.graves at pdf.com> wrote:
>>>
>>>> Dear Tom:
>>>>
>>>> Your revised function eliminates the discrepancy in the
>>>>
>>> degrees of
>>>
>>>> freedom but is still very different from the numbers reports
>>>>
>>> on Tsay, p.
>>>
>>>> 102:
>>>>
>>>> archTest(log(1+as.numeric(m.intc7303)), lag=12)
>>>>
>>>> ARCH test (univariate)
>>>>
>>>> data: Residual of y1 equation
>>>> Chi-squared = 13.1483, df = 12, p-value = 0.3584
>>>>
>>>> Warning message:
>>>> In VAR(s, p = 1, type = "const") :
>>>> No column names supplied in y, using: y1, y2, y3, y4, y5,
>y6, y7, y8,
>>>> y9, y10, y11, y12 , instead.
>>>>
>>>>
>>>> TOM: What can you tell me about the warning message?
>>>>
>>>> Thanks for your help with this.
>>>> Spencer Graves
>>>>
>>>> tom soyer wrote:
>>>>
>>>>> Spencer,
>>>>>
>>>>> Sorry, I forgot that the default lag in arch is 16. Here
>>>>>
>>> is the fix. Can
>>>
>>>> you
>>>>
>>>>> try it again and see if it gives the correct (or at least similar
>>>>>
>>>> compared
>>>>
>>>>> to a true LM test) result?
>>>>>
>>>>> archTest=function(x, lags=12){
>>>>> #x is a vector
>>>>> require(vars)
>>>>> s=embed(x,lags)
>>>>> y=VAR(s,p=1,type="const")
>>>>> result=arch(y,lags.single=lags,multi=F)$arch.uni[[1]]
>>>>> return(result)
>>>>> }
>>>>>
>>>>> Thanks and sorry about the bug.
>>>>>
>>>>>
>>>>> On 2/2/08, Spencer Graves <spencer.graves at pdf.com> wrote:
>>>>>
>>>>>
>>>>>> Dear Tom, Bernhard, Ruey:
>>>>>>
>>>>>> I can't get that to match Tsay's example, but I have other
>>>>>> questions about that.
>>>>>>
>>>>>> 1. I got the following using Tom's 'archTest'
>>>>>>
>>> function (below):
>>>
>>>>>>
>>>>>>> archTest(log(1+as.numeric(m.intc7303)), lags=12)
>>>>>>>
>>>>>>>
>>>>>> ARCH test (univariate)
>>>>>>
>>>>>> data: Residual of y1 equation
>>>>>> Chi-squared = 10.8562, df = 16, p-value = 0.8183
>>>>>>
>>>>>> Warning message:
>>>>>> In VAR(s, p = 1, type = "const") :
>>>>>> No column names supplied in y, using: y1, y2, y3, y4, y5,
>>>>>>
>>> y6, y7, y8,
>>>
>>>>>> y9, y10, y11, y12 , instead.
>>>>>>
>>>>>>
>>>>>> ** First note that the answer has df = 16,
>even though I
>>>>>> supplied lags = 12.
>>>>>>
>>>>>> 2. For (apparently) this example, S-Plus FinMetrics
>>>>>>
>>> 'archTest'
>>>
>>>>>> function returned "Test for ARCH Effects: LM Test. Null
>>>>>>
>>> Hypothesis:
>>>
>>>>>> no ARCH effects. Test Stat 43.5041, p.value 0.0000.
>>>>>>
>>> Dist. under Null:
>>>
>>>>>> chi-square with 12 degrees of freedom".
>>>>>>
>>>>>> 3. Starting on p. 101, Ruey mentioned "the Lagrange
>>>>>>
>>> multiplier
>>>
>>>>>> test of Engle (1982)", saying "This test is equivalent to
>>>>>>
>>> the usual F
>>>
>>>>>> test for" no regression, but refers it to a chi-square, not an F
>>>>>> distribution. Clearly, there is a gap here, because the
>>>>>>
>>> expected value
>>>
>>>>>> of the F distribution is close to 1 [d2/(d2-2), where d2
>>>>>>
>>> = denominator
>>>
>>>>>> degrees of freedom;
>http://en.wikipedia.org/wiki/F-distribution],
>>>>>>
>>>> while
>>>>
>>>>>> the expected value for a chi-square is the number of
>>>>>>
>>> degrees of freedom
>>>
>>>>>> Unfortunately, I don't feel I can afford the time to
>>>>>>
>>> dig into this
>>>
>>>>>> further right now.
>>>>>>
>>>>>> Thanks for your help.
>>>>>> Spencer Graves
>>>>>>
>>>>>> tom soyer wrote:
>>>>>>
>>>>>>
>>>>>>> Spencer, how about something like this:
>>>>>>>
>>>>>>> archTest=function (x, lags= 16){
>>>>>>> #x is a vector
>>>>>>> require(vars)
>>>>>>> s=embed(x,lags)
>>>>>>> y=VAR(s,p=1,type="const")
>>>>>>> result=arch(y,multi=F)$arch.uni[[1]]
>>>>>>> return(result)
>>>>>>> }
>>>>>>>
>>>>>>> can you, or maybe Bernhard, check and see whether this
>>>>>>>
>>> function gives
>>>
>>>>>>> the correct result?
>>>>>>>
>>>>>>> thanks,
>>>>>>>
>>>>>>> On 2/1/08, *Spencer Graves* <spencer.graves at pdf.com
>>>>>>> <mailto:spencer.graves at pdf.com>> wrote:
>>>>>>>
>>>>>>> Hi, Tom:
>>>>>>>
>>>>>>> The 'arch' function in the 'vars' package is
>>>>>>>
>>> supposed to be
>>>
>>>>>> able
>>>>>>
>>>>>>
>>>>>>> to do that. Unfortunately, I was unable to make it
>>>>>>>
>>> work for a
>>>
>>>>>>> univariate series. Bernhard Pfaff, the author of
>>>>>>>
>>> 'vars', said
>>>
>>>>>>> that if I
>>>>>>> read the code for 'arch', I could easily retrieve
>>>>>>>
>>> the necessary
>>>
>>>>>> lines
>>>>>>
>>>>>>
>>>>>>> and put them in my own function; I have not so far
>>>>>>>
>>> found the time
>>>
>>>>>> to
>>>>>>
>>>>>>
>>>>>>> try that. If you do, or if you get a better answer
>>>>>>>
>>> than this,
>>>
>>>>>>> would you
>>>>>>> please let me know? I would like to have this
>>>>>>>
>>> capability for the
>>>
>>>>>>> 'FinTS' package, and I would happily write a help
>>>>>>>
>>> page if someone
>>>
>>>>>>> would
>>>>>>> contribute the function -- or use a function in another
>>>>>>>
>>>>>>>
>>>>>> package. Tsay
>>>>>>
>>>>>>
>>>>>>> (2005) Analysis of Financial Time Series, 2nd ed.
>>>>>>>
>>> (Wiley) includes
>>>
>>>>>> an
>>>>>>
>>>>>>
>>>>>>> example on p. 103 that could be used for a reference.
>>>>>>>
>>>>>>> Hope this helps.
>>>>>>> Spencer Graves
>>>>>>>
>>>>>>> tom soyer wrote:
>>>>>>> > Hi,
>>>>>>> >
>>>>>>> > Does anyone know if R has a Lagrange multiplier
>>>>>>>
>>> (LM) test for
>>>
>>>> ARCH
>>>>
>>>>>>> > effects for univariant time series?
>>>>>>> >
>>>>>>> > Thanks!
>>>>>>> >
>>>>>>> >
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> Tom
>>>>>>>
>>>>>>>
>>>>>
>>>>>
>>>>>
>>>
>>> --
>>> Tom
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>>
>> *****************************************************************
>> Confidentiality Note: The information contained in this message,
>> and any attachments, may contain confidential and/or privileged
>> material. It is intended solely for the person(s) or entity to
>> which it is addressed. Any review, retransmission, dissemination,
>> or taking of any action in reliance upon this information by
>> persons or entities other than the intended recipient(s) is
>> prohibited. If you received this in error, please contact the
>> sender and delete the material from any computer.
>> *****************************************************************
>>
>>
>>
>
More information about the R-help
mailing list