[R] Scaling Statistical
Rui Barradas
ruipbarradas at sapo.pt
Mon Jun 24 21:41:52 CEST 2013
Hello,
From the help page for ?adf.test: "The p-values are interpolated from
Table 4.2, p. 103 of Banerjee et al. (1993)."
I believe it's a problem with your data. Putting a print statement in
the code for adf.test() gave me the following:
Call:
lm(formula = yt ~ xt1 + 1 + tt + yt1)
Residuals:
ALL 3 residuals are 0: no residual degrees of freedom!
Coefficients: (1 not defined because of singularities)
Estimate Std. Error t value Pr(>|t|)
(Intercept) -24.319 NA NA NA
xt1 -3.115 NA NA NA
tt 18.087 NA NA NA
yt1 NA NA NA NA
Residual standard error: NaN on 0 degrees of freedom
Multiple R-squared: 1, Adjusted R-squared: NaN
F-statistic: NaN on 2 and 0 DF, p-value: NA
And the test statistic becomes NaN (Not a Number). It's computed as
coefficients[2, 1]/coefficients[2, 2] or -3.115/NA.
So when it tries to interpolate the p-value, the variable 'interpol' is
equal to NaN and the if test fails.
With a standard error like NA, maybe you don't have enough data points
to run the tests. (Only 3 residuals, all zero, like seen above.)
Rui Barradas
Em 24-06-2013 20:12, Olga Musayev escreveu:
> Rui-- thanks so much for the help!
>
> I'm getting this error though, which is leaving me stumped:
>
> test<-lapply(ids, function(i) {
> if(!any(is.na <http://is.na>(df[df$ID==i,3])))
> {adf.test(df[df$ID==i, 3])} else {NA} })
>
> Error in if (interpol == min(tablep)) warning("p-value smaller than
> printed p-value") else warning("p-value greater than printed p-value") :
> missing value where TRUE/FALSE needed
>
> Any idea what this could mean?
>
>
>
> On Sun, Jun 23, 2013 at 4:54 PM, Rui Barradas <ruipbarradas at sapo.pt
> <mailto:ruipbarradas at sapo.pt>> wrote:
>
> Hello,
>
> Sorry, I forgot to Cc the list.
>
> Rui Barradas
>
> Em 23-06-2013 21:44, Rui Barradas escreveu:
>
> Hello,
>
> See if the following does what you want.
>
> lapply(seq_len(obsv), function(i) adf.test(df[df$ID == i, 3]))
>
>
> Hope this helps,
>
> Rui Barradas
>
> Em 23-06-2013 19:12, Olga Musayev escreveu:
>
> Short question: Is it possible to use statistical tests,
> like the
> Augmented
> Dickey-Fuller test, in functions with for-loops? If not, are
> there any
> alternative ways to scale measures?
>
> Detailed explanation: I am working with time-series, and I
> want to flag
> curves that are not stationary and which display pulses,
> trends, or level
> shifts.
>
> df
>
>
> DATE ID VALUE2012-03-06 1 5.672012-03-07 1
> 3.452012-03-08 1 4.562012-03-09 1 20.302012-03-10 1
> 5.102012-03-06 2 5.672012-03-07 2 3.452012-03-08 2
> 4.562012-03-09 2 5.282012-03-10 2 5.102012-03-06 3
> 5.672012-03-07 3 7.802012-03-08 3 8.792012-03-09 3
> 9.432012-03-10 3 10.99
>
> You can see, object 2 is stationary, but 3 exhibits a
> trend and 1 has a
> pulse at 3/09.
>
> What I want, in pseudo-code:
>
> flag<- list()
> for (i in 1:length(obsv)) {
> if adf.test(i) FAIL {
> append(flag, i)
> }}
>
> What I have so far:
>
> library(tseries)
> adf.test(df[which(df$ID==1), 3])
>
> Augmented Dickey-Fuller Test
>
> data: dataDickey-Fuller = 11.1451, Lag order = 16, p-value
> = 0.01null
> hypothesis: non-stationary
>
> adf.test(df[which(df$ID==2), 3])
>
> Augmented Dickey-Fuller Test
>
> data: dataDickey-Fuller = 11.1451, Lag order = 16, p-value
> = 0.99
> alternative hypothesis: stationary
>
> adf.test(df[which(df$ID==3), 3])Augmented Dickey-Fuller Test
>
>
> data: dataDickey-Fuller = 11.1451, Lag order = 16, p-value
> = 0.04null
> hypothesis: non-stationary
>
> How can I use this output in a for-loop? Thank you in
> advance!
>
> [[alternative HTML version deleted]]
>
> ________________________________________________
> R-help at r-project.org <mailto:R-help at r-project.org> mailing list
> https://stat.ethz.ch/mailman/__listinfo/r-help
> <https://stat.ethz.ch/mailman/listinfo/r-help>
> PLEASE do read the posting guide
> http://www.R-project.org/__posting-guide.html
> <http://www.R-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible
> code.
>
>
More information about the R-help
mailing list