Re: [R] Dickey Fuller Test
Dear Cuckovic, although you got already an answer to your post that relates a little bit more on the time series characteristics of your data in question; I will take up on your initial question. Basically, you got trapped by the word 'time series' in the documentation for adf.test(). What is meant, is an object of informal class ts, hence: YYY - as.ts(Y) adf.test(Y) adf.test(YYY) does yield the same result. Now, what's happening if an object of formal class timeSeries is inserted? Well, have a look at adf.test directly: adf.test Here, you will see that the series becomes differenced, but this operation is applied differently for numeric/ts objects viz. timeSeries objects; check: showMethods(diff) and/or diff(Y) diff(YY) diff(YYY) Now, to rectify your results, use: adf.test(series(YY)) instead. Here, the data part of your timeSeries object is extracted only and hence the same method for diff() is used as in the case of numeric/ts objects. Best, Bernhard -Ursprüngliche Nachricht- Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im Auftrag von Cuckovic Paik Gesendet: Freitag, 29. Oktober 2010 05:48 An: r-help@r-project.org Betreff: [R] Dickey Fuller Test Dear Users, please help with the following DF test: = library(tseries) library(timeSeries) Y=c(3519,3803,4332,4251,4661,4811,4448,4451,4343,4067,4001,3934,3652,3768 ,4082,4101,4628,4898,4476,4728,4458,4004,4095,4056,3641,3966,4417,4367 ,4821,5190,4638,4904,4528,4383,4339,4327,3856,4072,4563,4561,4984,5316 ,4843,5383,4889,4681,4466,4463,4217,4322,4779,4988,5383,5591,5322,5404 ,5106,4871,4977,4706,4193,4460,4956,5022,5408,5565,5360,5490,5286,5257 ,5002,4897,4577,4764,5052,5251,5558,5931,5476,5603,5425,5177,4792,4776 ,4450,4659,5043,5233,5423,5814,5339,5474,5278,5184,4975,4751,4600,4718 ,5218,5336,5665,5900,5330,5626,5512,5293,5143,4842,4627,4981,5321,5290 ,6002,5811,5671,6102,5482,5429,5356,5167,4608,4889,5352,5441,5970,5750 ,5670,5860,5449,5401,5240,5229,4770,5006,5518,5576,6160,6121,5900,5994 ,5841,5832,5505,5573,5331,5355,6057,6055,6771,6669,6375,,6383,6118 ,5927,5750,5122,5398,5817,6163,6763,6835,6678,6821,6421,6338,6265,6291 ,5540,5822,6318,6268,7270,7096,6505,7039,6440,6446,6717,6320) YY=as.timeSeries(Y) adf.test(Y) adf.test(YY) Output adf.test(Y) Augmented Dickey-Fuller Test data: Y Dickey-Fuller = -6.1661, Lag order = 5, p-value = 0.01 alternative hypothesis: stationary Warning message: In adf.test(Y) : p-value smaller than printed p-value adf.test(YY) Augmented Dickey-Fuller Test data: YY Dickey-Fuller = 12.4944, Lag order = 5, p-value = 0.99 alternative hypothesis: stationary Warning message: In adf.test(YY) : p-value greater than printed p-value == Question: Why the two results are different? The help file says that the input series is either a numeric vector or a time series object. But the results are completely opposite if the different types of arguments are used. Thanks in advance. -- View this message in context: http://r.789695.n4.nabble.com/Dickey-Fuller-Test-tp3018408p3018408.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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 ...{{dropped:10}} __ R-help@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.
Re: [R] Dickey Fuller Test
Thanks a lot for your answers, Dennis and Bernhard! -- View this message in context: http://r.789695.n4.nabble.com/Dickey-Fuller-Test-tp3018408p3019544.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] Dickey Fuller Test
Hi: Since the series is obviously nonstationary and periodic, it would seem that one should embrace a wider window over which to evaluate the DF test. I did the following: y - ts(Y, frequency = 12) # looked like an annual series to me plot(stl(y, 'periodic')) # very informative!! adf.test(y) Augmented Dickey-Fuller Test data: y Dickey-Fuller = -6.1661, Lag order = 5, p-value = 0.01 alternative hypothesis: stationary # Try a wider window of 12 lags: adf.test(y, k = 12) Augmented Dickey-Fuller Test data: y Dickey-Fuller = -1.061, Lag order = 12, p-value = 0.9261 alternative hypothesis: stationary This certainly made me wonder, and since I don't know much about unit root testing, it was time to play. What should k be? I decided to plot the value of the ADF statistic and its p-value for lags k from 5 to 40 just to see what would happen. df - data.frame(lag = 5:40, ADF.statistic = sapply(5:40, function(x) adf.test(y, k = x)$statistic), ADF.pvalue = sapply(5:40, function(x) adf.test(y, k = x)$p.value)) library(ggplot2) dfm - melt(df, id = 'lag') # one could use geom_point() in place of geom_path() ggplot(dfm, aes(x = lag, y = value)) + geom_path(size = 1) + facet_grid(variable ~ ., scales = 'free_y') + xlab('Lag number') + ylab() This shows pretty clearly that after about eight or nine lags, the ADF statistic fails to reject the null hypothesis of a unit root. The appearance of periodicity in both graphs indicates that the seasonality of the series has some impact on the value of the augmented DF test. Since I'm not up on the literature re this test, is it meant to be applied in the presence of seasonality? If not, I would suggest deseasonalizing the series first before applying the unit root test. I tried a few models and the best fitting one had differencing in both the non-seasonal and seasonal parts. This isn't really supported by the stl() graph, but there is an improvement in the fit if the seasonal part of the series is differenced, too. So if there is nonstationarity in both the non-seasonal and seasonal parts of the series, is the ADF test sensitive enough to pick up on this and does it still do the right thing? From my limited web searching, I didn't find any adjustments in the presence of seasonality, statiionary or not, which makes me wonder... HTH, Dennis On Thu, Oct 28, 2010 at 8:47 PM, Cuckovic Paik cuckovic.p...@gmail.comwrote: Dear Users, please help with the following DF test: = library(tseries) library(timeSeries) Y=c(3519,3803,4332,4251,4661,4811,4448,4451,4343,4067,4001,3934,3652,3768 ,4082,4101,4628,4898,4476,4728,4458,4004,4095,4056,3641,3966,4417,4367 ,4821,5190,4638,4904,4528,4383,4339,4327,3856,4072,4563,4561,4984,5316 ,4843,5383,4889,4681,4466,4463,4217,4322,4779,4988,5383,5591,5322,5404 ,5106,4871,4977,4706,4193,4460,4956,5022,5408,5565,5360,5490,5286,5257 ,5002,4897,4577,4764,5052,5251,5558,5931,5476,5603,5425,5177,4792,4776 ,4450,4659,5043,5233,5423,5814,5339,5474,5278,5184,4975,4751,4600,4718 ,5218,5336,5665,5900,5330,5626,5512,5293,5143,4842,4627,4981,5321,5290 ,6002,5811,5671,6102,5482,5429,5356,5167,4608,4889,5352,5441,5970,5750 ,5670,5860,5449,5401,5240,5229,4770,5006,5518,5576,6160,6121,5900,5994 ,5841,5832,5505,5573,5331,5355,6057,6055,6771,6669,6375,,6383,6118 ,5927,5750,5122,5398,5817,6163,6763,6835,6678,6821,6421,6338,6265,6291 ,5540,5822,6318,6268,7270,7096,6505,7039,6440,6446,6717,6320) YY=as.timeSeries(Y) adf.test(Y) adf.test(YY) Output adf.test(Y) Augmented Dickey-Fuller Test data: Y Dickey-Fuller = -6.1661, Lag order = 5, p-value = 0.01 alternative hypothesis: stationary Warning message: In adf.test(Y) : p-value smaller than printed p-value adf.test(YY) Augmented Dickey-Fuller Test data: YY Dickey-Fuller = 12.4944, Lag order = 5, p-value = 0.99 alternative hypothesis: stationary Warning message: In adf.test(YY) : p-value greater than printed p-value == Question: Why the two results are different? The help file says that the input series is either a numeric vector or a time series object. But the results are completely opposite if the different types of arguments are used. Thanks in advance. -- View this message in context: http://r.789695.n4.nabble.com/Dickey-Fuller-Test-tp3018408p3018408.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide
Re: [R] Dickey–Fuller test in R
On Mon, 2010-08-23 at 08:18 +0530, Aditya Damani wrote: Hi, While doing the adf test using ur.df “price.df2=ur.df(y=log(price),type = drift, selectlags=AIC) summary(price.df2)” It gives two values for “value of test statistic is: -1.5992 2.32” one value is the t-test (or t-ratio), what is the other one? This is ur.df in package urca? If so, from ?ur.df Details: The function ‘ur.df()’ computes the augmented Dickey-Fuller test. If type is set to ‘none’ neither an intercept nor a trend is included in the test regression. If it is set to ‘drift’ an intercept is added and if it is set to ‘trend’ both an intercept and a trend is added. The critical values are taken from Hamilton (1994) and Dickey and Fuller(1981). So as you selected type = drift the second value is for the intercept added to the test regression. I'm not familiar with the package nor this particular test so can't hep further. You might also like to compare this with adf.test() in package tseries. HTH G Please help. TIA Aditya -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@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.
Re: [R] Dickey Fuller test of a time series (problem)
i also having the problem with R . R version 2.10.0 (2009-10-26) Copyright (C) 2009 The R Foundation for Statistical Computing ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. [Previously saved workspace restored] z-rnorm(289) z [1] 2.330811003 1.504743043 1.768175890 0.629578885 -1.102466476 1.022360003 -0.683596222 0.825797728 1.970304092 [10] -0.434295690 -0.332111909 0.784754124 0.618029090 -0.323679397 0.477139243 0.567437753 -0.082967056 -0.631445108 [19] -0.599448056 -0.023043350 0.254275136 0.729704319 -0.557885077 0.136863688 0.336083722 -0.574337438 0.489163710 [28] -1.178968998 -0.500117153 0.194962840 1.077193868 -0.224323646 0.830018849 -0.923133317 0.984637207 -0.967962617 [37] -0.330364545 0.411477240 1.921856365 -0.402244385 0.287249079 -0.254981296 1.373816270 0.051474667 0.467294146 [46] -0.084979045 1.010413164 -1.685650845 -0.225540927 -0.068473164 0.076474205 -0.599026450 0.749528909 -0.005966977 [55] -0.751531710 -0.566290715 -0.653128084 1.252402084 -0.475794837 0.361830550 0.534634320 0.128657947 -0.998795343 [64] 0.439908085 -0.616926920 0.616190407 -0.503356528 -1.571513634 -0.862492045 -0.858421322 0.37011 0.026994800 [73] -0.072956095 0.750615120 -0.111619011 0.073884163 -0.962739147 0.038873386 -0.343490682 0.752229210 0.965300992 [82] -1.604473652 1.516414656 -0.938925299 -0.709151677 0.231854623 -0.218100137 1.543797726 -0.898485417 -0.383154763 [91] 1.676661233 -0.050011605 -0.885938130 -0.759522611 0.825827497 0.307787209 -1.582181323 1.548739934 0.874375153 [100] -1.929437918 -1.257364398 -1.789263683 -2.143550087 -0.299557119 -0.034432098 0.523581523 1.282782038 -0.627147412 [109] 1.379406957 -1.943450866 -0.109843039 -0.186738958 1.940752202 -0.399888402 0.889084467 0.347721291 0.221675595 [118] 1.014829243 0.815928201 -1.289821785 1.086385072 -0.299486086 -0.126573107 0.527587325 -1.988292033 -0.661784968 [127] -0.739984305 0.043729158 0.780508168 -0.329149317 -0.239561967 0.479590885 0.483343301 -1.330296792 -1.347459911 [136] -0.588658836 -0.954908406 -0.215942979 -0.079013859 -0.386107147 1.030946757 1.352902085 1.621552841 0.951461132 [145] 0.107764563 -0.143231089 0.837469606 -0.687510567 1.376661975 0.837165093 0.063985577 1.381120151 -0.628153036 [154] -1.144266557 1.005945165 1.085202192 0.273625164 0.022451305 -0.372955252 0.283434935 -1.174292734 1.513095774 [163] -1.406613019 -0.954491994 0.275374664 -0.404428637 -0.791690077 -0.325169327 0.859515784 -1.605660446 -0.126481055 [172] -1.163844796 0.234669024 0.694055806 -0.503758028 0.747620192 -0.490237653 -0.673188493 0.597849322 0.508355060 [181] 0.220080232 1.254662349 -1.390019760 1.036511650 0.004499064 -0.171119971 0.341759420 0.883209195 0.196981832 [190] 1.93083 -0.472635901 -0.143698739 0.134008071 0.123061173 -0.847030934 0.478631946 -0.640264555 1.198188793 [199] 0.928747360 -1.223396075 0.042572331 -1.193181087 -0.284040641 -0.511904510 -0.591542425 0.763156940 0.649463947 [208] -0.762889670 -0.628481227 0.367263423 -0.286380274 0.354460516 -0.138982551 -1.184283483 0.489375881 1.005739798 [217] 0.267274437 -0.118960041 -1.207006456 0.461973434 0.325420233 0.996123459 1.188010215 -2.000847324 1.043974965 [226] 0.356219212 0.620522833 3.800773985 -2.080091995 0.322824104 -1.793810727 0.49250 -0.092310467 2.893818046 [235] -0.846021981 0.402650410 -0.426312400 1.162983880 2.076818805 -0.260109032 0.725039578 0.361726563 -0.116508468 [244] 0.820778041 1.664995327 0.361725669 0.577447944 -1.008407703 0.390553465 0.263064760 0.915409450 0.294579966 [253] 1.478028593 1.865177412 -1.050708541 -2.071520363 0.450842362 0.530261688 0.226103509 -0.875767768 0.255960500 [262] -0.675455904 -1.436531605 -0.715532812 0.498582850 0.463511831 0.568583368 0.337032963 -0.31489 -0.738982923 [271] 1.740242504 1.089138147 -0.128574330 1.834612295 -0.657243928 0.701904808 1.550270461 -0.234375326 -0.420885683 [280] 1.845942481 -0.895760996 -0.593765244 0.586912606 -1.062899762 0.277845308 -0.834841694 -0.614720628 -0.343506642 [289] 0.442537573 x - data.frame(z) x z 12.330811003 21.504743043 31.768175890 40.629578885 5 -1.102466476 61.022360003 7 -0.683596222 80.825797728 91.970304092 10 -0.434295690 11 -0.332111909 12 0.784754124 13 0.618029090 14 -0.323679397 15 0.477139243 16
Re: [R] Dickey Fuller test of a time series (problem)
The argument 'x' of adf.test should not only be a vector but also a numeric vector (see ?adf.test). Have a closer look at your data and how they are stored. What does is.numeric(x) give? I guess that originally your data are stored as a data frame. Converting a data.frame to a vector is not done properly by c(), as the following example shows: z - rnorm(289) x - data.frame(z) adf.test(x,k=1) # produces an error y - c(x) is.numeric(y) # FALSE adf.test(y,k=1) # produces an error k - 1 y - x[,1] # or y - x$z adf.test(y,k=1) # this works well At 10:31 20.03.2009, you wrote: Hi all, I tried to do a Dickey Fuller test with R using adf.test with a time series of german stock prices. I have 10 stocks from 1985 to 2009 with monthly stock prices. So if you do the math I have 289 values for each stock. I tried to do the test for each stock alone and had the 289 values of my first stock listed in R. When I tried to do the test with command adf.test(x, k=1) the following warning displayed: Fehler in embed(y, k) : 'x' is not a vector or matrix (Fehler means error) so I tried to write x as a vector with command: z-c(x) I retried the test with adf.test(z, k=1) and the following error appeared: Fehler in embed(y, k) : wrong embedding dimension I tried quite a lot of other things but I cannot get why the test isn't working. I'm really no expert on this matter so please help me out as the test if the time series is stationary is crucial for my work. Thank you very much indeed Matthias [[alternative HTML version deleted]] __ R-help@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. __ R-help@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.