How to implement an iterative unit root test

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

How to implement an iterative unit root test

herr dittmann
Hello,

How can an interative unit root test be implemented in R?
More specifically, given a time series, I wish to perform the Dickey
Fuller Test on a daily basis for say the last 100 observations. It would
be interative in the sense that this test would be repeated each day for
the last 100 observations.
Given the daily Dickey Fuller estimates of delta for the autoregressive
process

d(Y(t)) = delta * Y(t-1) + u(t)

, the significance of delta would be computed. If possible, I would like
to extract that value and record it in a table, that is a table
containing the tau-values of a each day's calculations.


How can such a test be done in R? More specifically, how can it be
programmed to iteratively perform the test and also how to extract the
t-values on a daily basis?


Thank you.

Sincerely,

Bernd Dittmann

______________________________________________
[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: How to implement an iterative unit root test

Andy Bunn
Does this get you started?

library(tseries)
?adf.test
foo <- matrix(rnorm(1000),ncol=10,nrow=100)
bar <- apply(foo,2,adf.test)
sapply(bar, "[[", "statistic")
sapply(bar, "[[", "p.value")


HTH, Andy

-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Bernd Dittmann
Sent: Wednesday, April 05, 2006 8:58 PM
To: [hidden email]
Subject: [R] How to implement an iterative unit root test


Hello,

How can an interative unit root test be implemented in R?
More specifically, given a time series, I wish to perform the Dickey
Fuller Test on a daily basis for say the last 100 observations. It would
be interative in the sense that this test would be repeated each day for
the last 100 observations.
Given the daily Dickey Fuller estimates of delta for the autoregressive
process

d(Y(t)) = delta * Y(t-1) + u(t)

, the significance of delta would be computed. If possible, I would like
to extract that value and record it in a table, that is a table
containing the tau-values of a each day's calculations.


How can such a test be done in R? More specifically, how can it be
programmed to iteratively perform the test and also how to extract the
t-values on a daily basis?


Thank you.

Sincerely,

Bernd Dittmann

______________________________________________
[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

______________________________________________
[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: How to implement an iterative unit root test

herr dittmann
Thank you for your suggestion, Andy.

Luckily, the fMultivar package has already implemented such a "rolling"
function: "rollFun".

Thus I tried the following:


myfunction <- function(x, n = 5)
{
    rollFun(x = x, n = n, FUN = adfTest)
}


This however does not return the tau values (or alternatively, the
p.values) I am looking for.
How do I need to define the function FUN to obtain these values?


Many thanks!

Sincerely,

Bernd



Andy Bunn schrieb:

> Does this get you started?
>
> library(tseries)
> ?adf.test
> foo <- matrix(rnorm(1000),ncol=10,nrow=100)
> bar <- apply(foo,2,adf.test)
> sapply(bar, "[[", "statistic")
> sapply(bar, "[[", "p.value")
>
>
> HTH, Andy
>
> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of Bernd Dittmann
> Sent: Wednesday, April 05, 2006 8:58 PM
> To: [hidden email]
> Subject: [R] How to implement an iterative unit root test
>
>
> Hello,
>
> How can an interative unit root test be implemented in R?
> More specifically, given a time series, I wish to perform the Dickey
> Fuller Test on a daily basis for say the last 100 observations. It would
> be interative in the sense that this test would be repeated each day for
> the last 100 observations.
> Given the daily Dickey Fuller estimates of delta for the autoregressive
> process
>
> d(Y(t)) = delta * Y(t-1) + u(t)
>
> , the significance of delta would be computed. If possible, I would like
> to extract that value and record it in a table, that is a table
> containing the tau-values of a each day's calculations.
>
>
> How can such a test be done in R? More specifically, how can it be
> programmed to iteratively perform the test and also how to extract the
> t-values on a daily basis?
>
>
> Thank you.
>
> Sincerely,
>
> Bernd Dittmann
>
> ______________________________________________
> [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
>
>
>

______________________________________________
[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: How to implement an iterative unit root test

Gabor Grothendieck
Try this:

> library(fMultivar)
> set.seed(1)
> x <- rnorm(25)
> rollFun(x, 15, FUN = function(x) adf.test(x)$p.value)
 [1] 0.1207730 0.3995849 0.3261577 0.4733004 0.5776586 0.6400228 0.6758550
 [8] 0.6897812 0.3792858 0.6587171 0.5675147
> rollFun(x, 15, FUN = function(x) adf.test(x)$statistic)
 [1] -3.185471 -2.453590 -2.646336 -2.260086 -1.986146 -1.822440 -1.728381
 [8] -1.691824 -2.506875 -1.773368 -2.012774

Also, rapply in the zoo package and running in the gtools package are two other
rolling routines.

On 4/8/06, Bernd Dittmann <[hidden email]> wrote:

> Thank you for your suggestion, Andy.
>
> Luckily, the fMultivar package has already implemented such a "rolling"
> function: "rollFun".
>
> Thus I tried the following:
>
>
> myfunction <- function(x, n = 5)
> {
>    rollFun(x = x, n = n, FUN = adfTest)
> }
>
>
> This however does not return the tau values (or alternatively, the
> p.values) I am looking for.
> How do I need to define the function FUN to obtain these values?
>
>
> Many thanks!
>
> Sincerely,
>
> Bernd
>
>
>
> Andy Bunn schrieb:
> > Does this get you started?
> >
> > library(tseries)
> > ?adf.test
> > foo <- matrix(rnorm(1000),ncol=10,nrow=100)
> > bar <- apply(foo,2,adf.test)
> > sapply(bar, "[[", "statistic")
> > sapply(bar, "[[", "p.value")
> >
> >
> > HTH, Andy
> >
> > -----Original Message-----
> > From: [hidden email]
> > [mailto:[hidden email]] On Behalf Of Bernd Dittmann
> > Sent: Wednesday, April 05, 2006 8:58 PM
> > To: [hidden email]
> > Subject: [R] How to implement an iterative unit root test
> >
> >
> > Hello,
> >
> > How can an interative unit root test be implemented in R?
> > More specifically, given a time series, I wish to perform the Dickey
> > Fuller Test on a daily basis for say the last 100 observations. It would
> > be interative in the sense that this test would be repeated each day for
> > the last 100 observations.
> > Given the daily Dickey Fuller estimates of delta for the autoregressive
> > process
> >
> > d(Y(t)) = delta * Y(t-1) + u(t)
> >
> > , the significance of delta would be computed. If possible, I would like
> > to extract that value and record it in a table, that is a table
> > containing the tau-values of a each day's calculations.
> >
> >
> > How can such a test be done in R? More specifically, how can it be
> > programmed to iteratively perform the test and also how to extract the
> > t-values on a daily basis?
> >
> >
> > Thank you.
> >
> > Sincerely,
> >
> > Bernd Dittmann
> >
> > ______________________________________________
> > [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
> >
> >
> >
>
> ______________________________________________
> [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
>

______________________________________________
[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: How to implement an iterative unit root test

herr dittmann
Thank you for the suggestion.

I ran it and oddly enough I am getting contradicting results:


 > rollFun(x[1:100], 10, FUN = function(x) adfTest(x)$statistic)
NULL
Warning messages:
1: p-value smaller than printed p-value in: adfTest(x)
.......
.......
.......

These error messages appear for each single calculation.


However, performing the unit root test for that very interval (although
not repetitive) the results are:

 > adfTest(x[1:100])

Title:
Augmented Dickey-Fuller Test

Test Results:
  PARAMETER:
    Lag Order: 1
  STATISTIC:
    Dickey-Fuller: -0.1627
  P VALUE:
    0.5612

Description:
Sat Apr 08 19:11:40 2006


I checked with the help pages of the adfTest and fMultivar, but can
simply not figure out why I am receiving these error messages above.


How could I fix this?

Many thanks!

Sincerely,

Bernd Dittmann

Gabor Grothendieck schrieb:

> Try this:
>
>  
>> library(fMultivar)
>> set.seed(1)
>> x <- rnorm(25)
>> rollFun(x, 15, FUN = function(x) adf.test(x)$p.value)
>>    
>  [1] 0.1207730 0.3995849 0.3261577 0.4733004 0.5776586 0.6400228 0.6758550
>  [8] 0.6897812 0.3792858 0.6587171 0.5675147
>  
>> rollFun(x, 15, FUN = function(x) adf.test(x)$statistic)
>>    
>  [1] -3.185471 -2.453590 -2.646336 -2.260086 -1.986146 -1.822440 -1.728381
>  [8] -1.691824 -2.506875 -1.773368 -2.012774
>
> Also, rapply in the zoo package and running in the gtools package are two other
> rolling routines.
>
> On 4/8/06, Bernd Dittmann <[hidden email]> wrote:
>  
>> Thank you for your suggestion, Andy.
>>
>> Luckily, the fMultivar package has already implemented such a "rolling"
>> function: "rollFun".
>>
>> Thus I tried the following:
>>
>>
>> myfunction <- function(x, n = 5)
>> {
>>    rollFun(x = x, n = n, FUN = adfTest)
>> }
>>
>>
>> This however does not return the tau values (or alternatively, the
>> p.values) I am looking for.
>> How do I need to define the function FUN to obtain these values?
>>
>>
>> Many thanks!
>>
>> Sincerely,
>>
>> Bernd
>>
>>
>>
>> Andy Bunn schrieb:
>>    
>>> Does this get you started?
>>>
>>> library(tseries)
>>> ?adf.test
>>> foo <- matrix(rnorm(1000),ncol=10,nrow=100)
>>> bar <- apply(foo,2,adf.test)
>>> sapply(bar, "[[", "statistic")
>>> sapply(bar, "[[", "p.value")
>>>
>>>
>>> HTH, Andy
>>>
>>> -----Original Message-----
>>> From: [hidden email]
>>> [mailto:[hidden email]] On Behalf Of Bernd Dittmann
>>> Sent: Wednesday, April 05, 2006 8:58 PM
>>> To: [hidden email]
>>> Subject: [R] How to implement an iterative unit root test
>>>
>>>
>>> Hello,
>>>
>>> How can an interative unit root test be implemented in R?
>>> More specifically, given a time series, I wish to perform the Dickey
>>> Fuller Test on a daily basis for say the last 100 observations. It would
>>> be interative in the sense that this test would be repeated each day for
>>> the last 100 observations.
>>> Given the daily Dickey Fuller estimates of delta for the autoregressive
>>> process
>>>
>>> d(Y(t)) = delta * Y(t-1) + u(t)
>>>
>>> , the significance of delta would be computed. If possible, I would like
>>> to extract that value and record it in a table, that is a table
>>> containing the tau-values of a each day's calculations.
>>>
>>>
>>> How can such a test be done in R? More specifically, how can it be
>>> programmed to iteratively perform the test and also how to extract the
>>> t-values on a daily basis?
>>>
>>>
>>> Thank you.
>>>
>>> Sincerely,
>>>
>>> Bernd Dittmann
>>>
>>> ______________________________________________
>>> [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
>>>
>>>
>>>
>>>      
>> ______________________________________________
>> [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
>>
>>    
>
>  


        [[alternative HTML version deleted]]


               
___________________________________________________________
Does your mail provider give you FREE antivirus protection?

______________________________________________
[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: How to implement an iterative unit root test

Gabor Grothendieck
That's a warning, not an error.   I get it or don't get it with and
without rollFun in the same circumstances. If you have a situation
where that is not so please provide it in a reproducible way.

> library(fMultivar)
> set.seed(1)
> x <- rnorm(25)

> # these give no warning
> rollFun(x, 15, FUN = function(x) adf.test(x)$p.value)
 [1] 0.1207730 0.3995849 0.3261577 0.4733004 0.5776586 0.6400228 0.6758550
 [8] 0.6897812 0.3792858 0.6587171 0.5675147
> adf.test(x[1:15])$statistic
Dickey-Fuller
    -3.185471

> # these give warning
> rollFun(x, 10, FUN = function(x) adf.test(x)$p.statistic)
NULL
Warning messages:
1: p-value smaller than printed p-value in: adf.test(x)
2: p-value smaller than printed p-value in: adf.test(x)
3: p-value smaller than printed p-value in: adf.test(x)
4: p-value smaller than printed p-value in: adf.test(x)
5: p-value greater than printed p-value in: adf.test(x)
6: p-value greater than printed p-value in: adf.test(x)
7: p-value greater than printed p-value in: adf.test(x)
> # this gives warning
> adf.test(x[1:10])$statistic
Dickey-Fuller
    -5.316689
Warning message:
p-value smaller than printed p-value in: adf.test(x[1:10])





On 4/8/06, Bernd Dittmann <[hidden email]> wrote:

> Thank you for the suggestion.
>
> I ran it and oddly enough I am getting contradicting results:
>
>
> > rollFun(x[1:100], 10, FUN = function(x) adfTest(x)$statistic)
> NULL
> Warning messages:
> 1: p-value smaller than printed p-value in: adfTest(x)
> .......
> .......
> .......
>
> These error messages appear for each single calculation.
>
>
> However, performing the unit root test for that very interval (although not
> repetitive) the results are:
>
> > adfTest(x[1:100])
>
> Title:
> Augmented Dickey-Fuller Test
>
> Test Results:
>   PARAMETER:
>     Lag Order: 1
>   STATISTIC:
>     Dickey-Fuller: -0.1627
>   P VALUE:
>     0.5612
>
> Description:
> Sat Apr 08 19:11:40 2006
>
>
> I checked with the help pages of the adfTest and fMultivar, but can simply
> not figure out why I am receiving these error messages above.
>
>
> How could I fix this?
>
> Many thanks!
>
> Sincerely,
>
> Bernd Dittmann
>
> Gabor Grothendieck schrieb:
> Try this:


> library(fMultivar)
set.seed(1)
x <- rnorm(25)
rollFun(x, 15, FUN =
> function(x) adf.test(x)$p.value)

>  [1] 0.1207730 0.3995849 0.3261577 0.4733004 0.5776586 0.6400228 0.6758550
> [8] 0.6897812 0.3792858 0.6587171 0.5675147

> rollFun(x, 15, FUN = function(x) adf.test(x)$statistic)

>  [1] -3.185471 -2.453590 -2.646336 -2.260086 -1.986146 -1.822440 -1.728381
> [8] -1.691824 -2.506875 -1.773368 -2.012774

Also, rapply in the zoo package
> and running in the gtools package are two other
rolling routines.

On
> 4/8/06, Bernd Dittmann <[hidden email]> wrote:

> Thank you for your suggestion, Andy.

Luckily, the fMultivar package has
> already implemented such a "rolling"
function: "rollFun".

Thus I tried the
> following:


myfunction <- function(x, n = 5)
{
 rollFun(x = x, n = n, FUN =
> adfTest)
}


This however does not return the tau values (or alternatively,
> the
p.values) I am looking for.
How do I need to define the function FUN to
> obtain these values?


Many thanks!

Sincerely,

Bernd



Andy Bunn
> schrieb:

> Does this get you started?

library(tseries)
?adf.test
foo <-
> matrix(rnorm(1000),ncol=10,nrow=100)
bar <-
> apply(foo,2,adf.test)
sapply(bar, "[[", "statistic")
sapply(bar, "[[",
> "p.value")


HTH, Andy

-----Original Message-----
From:
> [hidden email]
[mailto:[hidden email]]
> On Behalf Of Bernd Dittmann
Sent: Wednesday, April 05, 2006 8:58 PM
To:
> [hidden email]
Subject: [R] How to implement an iterative unit
> root test


Hello,

How can an interative unit root test be implemented in
> R?
More specifically, given a time series, I wish to perform the
> Dickey
Fuller Test on a daily basis for say the last 100 observations. It
> would
be interative in the sense that this test would be repeated each day
> for
the last 100 observations.
Given the daily Dickey Fuller estimates of
> delta for the autoregressive
process

d(Y(t)) = delta * Y(t-1) + u(t)

, the
> significance of delta would be computed. If possible, I would like
to
> extract that value and record it in a table, that is a table
containing the
> tau-values of a each day's calculations.


How can such a test be done in R?
> More specifically, how can it be
programmed to iteratively perform the test
> and also how to extract the
t-values on a daily basis?


Thank
> you.

Sincerely,

Bernd
> Dittmann

______________________________________________
[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




> ______________________________________________
[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


>
>
>

______________________________________________
[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