R : Copyright 2005, The R Foundation for Statistical Computing Version 2.1.1 (2005-06-20), 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. 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 a HTML browser interface to help. Type 'q()' to quit R. > ### *
> ### > attach(NULL, name = "CheckExEnv") > assign(".CheckExEnv", as.environment(2), pos = length(search())) # base > ## add some hooks to label plot pages for base and grid graphics > setHook("plot.new", ".newplot.hook") > setHook("persp", ".newplot.hook") > setHook("grid.newpage", ".gridplot.hook") > > assign("cleanEx", + function(env = .GlobalEnv) { + rm(list = ls(envir = env, all.names = TRUE), envir = env) + RNGkind("default", "default") + set.seed(1) + options(warn = 1) + delayedAssign("T", stop("T used instead of TRUE"), + assign.env = .CheckExEnv) + delayedAssign("F", stop("F used instead of FALSE"), + assign.env = .CheckExEnv) + sch <- search() + newitems <- sch[! sch %in% .oldSearch] + for(item in rev(newitems)) + eval(substitute(detach(item), list(item=item))) + missitems <- .oldSearch[! .oldSearch %in% sch] + if(length(missitems)) + warning("items ", paste(missitems, collapse=", "), + " have been removed from the search path") + }, + env = .CheckExEnv) > assign("..nameEx", "__{must remake R-ex/*.R}__", env = .CheckExEnv) # for now > assign("ptime", proc.time(), env = .CheckExEnv) > grDevices::postscript("tseries-Examples.ps") > assign("par.postscript", graphics::par(no.readonly = TRUE), env = .CheckExEnv) > options(contrasts = c(unordered = "contr.treatment", ordered = "contr.poly")) > options(warn = 1) > library('tseries') Loading required package: quadprog > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "adf.test" > > ### * adf.test > > flush(stderr()); flush(stdout()) > > ### Name: adf.test > ### Title: Augmented Dickey-Fuller Test > ### Aliases: adf.test > ### Keywords: ts > > ### ** Examples > > x <- rnorm(1000) # no unit-root > adf.test(x) Warning in adf.test(x) : p-value smaller than printed p-value Augmented Dickey-Fuller Test data: x Dickey-Fuller = -9.9291, Lag order = 9, p-value = 0.01 alternative hypothesis: stationary > > y <- diffinv(x) # contains a unit-root > adf.test(y) Augmented Dickey-Fuller Test data: y Dickey-Fuller = -2.5115, Lag order = 9, p-value = 0.3618 alternative hypothesis: stationary > > > > cleanEx(); ..nameEx <- "arma" > > ### * arma > > flush(stderr()); flush(stdout()) > > ### Name: arma > ### Title: Fit ARMA Models to Time Series > ### Aliases: arma > ### Keywords: ts > > ### ** Examples > > data(tcm) > r <- diff(tcm10y) > summary(r.arma <- arma(r, order = c(1, 0))) Call: arma(x = r, order = c(1, 0)) Model: ARMA(1,0) Residuals: Min 1Q Median 3Q Max -1.707400 -0.116059 0.006282 0.128118 1.471796 Coefficient(s): Estimate Std. Error t value Pr(>|t|) ar1 0.328972 0.039991 8.226 2.22e-16 *** intercept 0.003325 0.011430 0.291 0.771 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Fit: sigma^2 estimated as 0.07287, Conditional Sum-of-Squares = 40.44, AIC = 125.89 > summary(r.arma <- arma(r, order = c(2, 0))) Call: arma(x = r, order = c(2, 0)) Model: ARMA(2,0) Residuals: Min 1Q Median 3Q Max -1.603801 -0.117037 0.002274 0.129126 1.376261 Coefficient(s): Estimate Std. Error t value Pr(>|t|) ar1 0.40790 0.04114 9.915 < 2e-16 *** ar2 -0.23962 0.04113 -5.826 5.67e-09 *** intercept 0.00420 0.01111 0.378 0.705 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Fit: sigma^2 estimated as 0.06881, Conditional Sum-of-Squares = 38.12, AIC = 95.94 > summary(r.arma <- arma(r, order = c(0, 1))) Call: arma(x = r, order = c(0, 1)) Model: ARMA(0,1) Residuals: Min 1Q Median 3Q Max -1.590634 -0.118433 -0.000165 0.129751 1.339717 Coefficient(s): Estimate Std. Error t value Pr(>|t|) ma1 0.506871 0.042113 12.036 <2e-16 *** intercept 0.005287 0.016632 0.318 0.75 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Fit: sigma^2 estimated as 0.0681, Conditional Sum-of-Squares = 37.8, AIC = 88.21 > summary(r.arma <- arma(r, order = c(0, 2))) Call: arma(x = r, order = c(0, 2)) Model: ARMA(0,2) Residuals: Min 1Q Median 3Q Max -1.5497077 -0.1224297 0.0009082 0.1343164 1.3639450 Coefficient(s): Estimate Std. Error t value Pr(>|t|) ma1 0.449184 0.042387 10.597 <2e-16 *** ma2 -0.117937 0.042662 -2.764 0.0057 ** intercept 0.004701 0.014613 0.322 0.7477 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Fit: sigma^2 estimated as 0.0673, Conditional Sum-of-Squares = 37.28, AIC = 83.58 > summary(r.arma <- arma(r, order = c(1, 1))) Call: arma(x = r, order = c(1, 1)) Model: ARMA(1,1) Residuals: Min 1Q Median 3Q Max -1.5529214 -0.1189386 0.0001515 0.1337559 1.3663775 Coefficient(s): Estimate Std. Error t value Pr(>|t|) ar1 -0.202320 0.074961 -2.699 0.00695 ** ma1 0.658111 0.056927 11.561 < 2e-16 *** intercept 0.006799 0.018195 0.374 0.70866 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Fit: sigma^2 estimated as 0.0673, Conditional Sum-of-Squares = 37.35, AIC = 83.62 > plot(r.arma) > > data(nino) > s <- nino3.4 > summary(s.arma <- arma(s, order=c(20,0))) Call: arma(x = s, order = c(20, 0)) Model: ARMA(20,0) Residuals: Min 1Q Median 3Q Max -1.378647 -0.223040 0.007358 0.215996 1.103511 Coefficient(s): Estimate Std. Error t value Pr(>|t|) ar1 1.10163 0.04090 26.932 < 2e-16 *** ar2 -0.05461 0.06063 -0.901 0.367693 ar3 -0.17718 0.06060 -2.924 0.003457 ** ar4 0.07072 0.06056 1.168 0.242900 ar5 -0.05292 0.05990 -0.884 0.376941 ar6 0.06743 0.05932 1.137 0.255661 ar7 -0.17060 0.05877 -2.903 0.003698 ** ar8 -0.03509 0.05857 -0.599 0.549068 ar9 0.03326 0.05827 0.571 0.568113 ar10 0.14149 0.05829 2.427 0.015206 * ar11 0.01597 0.05812 0.275 0.783504 ar12 0.16400 0.05791 2.832 0.004629 ** ar13 -0.22467 0.05833 -3.852 0.000117 *** ar14 -0.01355 0.05869 -0.231 0.817394 ar15 -0.04530 0.05845 -0.775 0.438283 ar16 -0.18815 0.05807 -3.240 0.001196 ** ar17 0.20923 0.05868 3.566 0.000363 *** ar18 0.07387 0.05868 1.259 0.208074 ar19 -0.13363 0.05792 -2.307 0.021045 * ar20 0.05234 0.04002 1.308 0.190952 intercept 4.46824 0.79612 5.613 1.99e-08 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Fit: sigma^2 estimated as 0.1079, Conditional Sum-of-Squares = 62.24, AIC = 407.41 > summary(s.arma + <- arma(s, lag=list(ar=c(1,3,7,10,12,13,16,17,19),ma=NULL))) Warning in arma(s, lag = list(ar = c(1, 3, 7, 10, 12, 13, 16, 17, 19), ma = NULL)) : order is ignored Call: arma(x = s, lag = list(ar = c(1, 3, 7, 10, 12, 13, 16, 17, 19), ma = NULL)) Model: ARMA(19,0) Residuals: Min 1Q Median 3Q Max -1.360875 -0.230887 0.005043 0.226822 1.090989 Coefficient(s): Estimate Std. Error t value Pr(>|t|) ar1 1.07772 0.02642 40.793 < 2e-16 *** ar3 -0.16942 0.03016 -5.618 1.93e-08 *** ar7 -0.13913 0.02254 -6.174 6.67e-10 *** ar10 0.16459 0.02931 5.615 1.97e-08 *** ar12 0.20472 0.04754 4.306 1.66e-05 *** ar13 -0.29976 0.04133 -7.253 4.07e-13 *** ar16 -0.21637 0.04349 -4.975 6.54e-07 *** ar17 0.25139 0.04648 5.408 6.37e-08 *** ar19 -0.04510 0.02580 -1.748 0.0804 . intercept 4.61896 0.77687 5.946 2.75e-09 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Fit: sigma^2 estimated as 0.1094, Conditional Sum-of-Squares = 63.24, AIC = 393.87 > acf(residuals(s.arma), na.action=na.remove) > pacf(residuals(s.arma), na.action=na.remove) > summary(s.arma + <- arma(s, lag=list(ar=c(1,3,7,10,12,13,16,17,19),ma=12))) Warning in arma(s, lag = list(ar = c(1, 3, 7, 10, 12, 13, 16, 17, 19), ma = 12)) : order is ignored Call: arma(x = s, lag = list(ar = c(1, 3, 7, 10, 12, 13, 16, 17, 19), ma = 12)) Model: ARMA(19,12) Residuals: Min 1Q Median 3Q Max -1.339941 -0.209727 0.001678 0.224448 1.065923 Coefficient(s): Estimate Std. Error t value Pr(>|t|) ar1 1.06644 0.02807 37.997 < 2e-16 *** ar3 -0.15394 0.03295 -4.673 2.98e-06 *** ar7 -0.12194 0.01971 -6.187 6.14e-10 *** ar10 0.12689 0.02735 4.639 3.50e-06 *** ar12 0.46228 0.10391 4.449 8.63e-06 *** ar13 -0.53619 0.09507 -5.640 1.70e-08 *** ar16 -0.18195 0.05069 -3.589 0.000331 *** ar17 0.24859 0.05087 4.887 1.02e-06 *** ar19 -0.04463 0.02864 -1.558 0.119164 ma12 -0.36376 0.11096 -3.278 0.001044 ** intercept 3.62293 0.78419 4.620 3.84e-06 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Fit: sigma^2 estimated as 0.103, Conditional Sum-of-Squares = 59.54, AIC = 359.84 > summary(s.arma + <- arma(s, lag=list(ar=c(1,3,7,10,12,13,16,17),ma=12))) Warning in arma(s, lag = list(ar = c(1, 3, 7, 10, 12, 13, 16, 17), ma = 12)) : order is ignored Call: arma(x = s, lag = list(ar = c(1, 3, 7, 10, 12, 13, 16, 17), ma = 12)) Model: ARMA(17,12) Residuals: Min 1Q Median 3Q Max -1.27924 -0.19931 0.01423 0.22825 1.08027 Coefficient(s): Estimate Std. Error t value Pr(>|t|) ar1 1.05679 0.02457 43.010 < 2e-16 *** ar3 -0.10723 0.02392 -4.482 7.39e-06 *** ar7 -0.15482 0.01939 -7.984 1.33e-15 *** ar10 0.14458 0.02713 5.330 9.84e-08 *** ar12 0.53544 0.07242 7.394 1.43e-13 *** ar13 -0.64133 0.06248 -10.265 < 2e-16 *** ar16 -0.14278 0.04063 -3.514 0.000441 *** ar17 0.19739 0.03386 5.830 5.53e-09 *** ma12 -0.43009 0.07957 -5.405 6.48e-08 *** intercept 3.01582 0.63664 4.737 2.17e-06 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Fit: sigma^2 estimated as 0.1023, Conditional Sum-of-Squares = 59.37, AIC = 353.98 > plot(s.arma) > > > > cleanEx(); ..nameEx <- "bds.test" > > ### * bds.test > > flush(stderr()); flush(stdout()) > > ### Name: bds.test > ### Title: BDS Test > ### Aliases: bds.test print.bdstest > ### Keywords: ts > > ### ** Examples > > x <- rnorm(100) > bds.test(x) # i.i.d. example BDS Test data: x Embedding dimension = 2 3 Epsilon for close points = 0.4491 0.8982 1.3473 1.7964 Standard Normal = [ 0.4491 ] [ 0.8982 ] [ 1.3473 ] [ 1.7964 ] [ 2 ] -1.2151 -1.7399 -1.6477 -2.0174 [ 3 ] -3.0937 -1.8985 -1.9449 -1.9759 p-value = [ 0.4491 ] [ 0.8982 ] [ 1.3473 ] [ 1.7964 ] [ 2 ] 0.2243 0.0819 0.0994 0.0437 [ 3 ] 0.0020 0.0576 0.0518 0.0482 > > x <- c(rnorm(50), runif(50)) > bds.test(x) # not identically distributed BDS Test data: x Embedding dimension = 2 3 Epsilon for close points = 0.3731 0.7462 1.1193 1.4923 Standard Normal = [ 0.3731 ] [ 0.7462 ] [ 1.1193 ] [ 1.4923 ] [ 2 ] 8.6357 5.1644 2.0464 0.3572 [ 3 ] 14.9978 9.6187 5.3121 3.4352 p-value = [ 0.3731 ] [ 0.7462 ] [ 1.1193 ] [ 1.4923 ] [ 2 ] 0 0 0.0407 0.7209 [ 3 ] 0 0 0.0000 0.0006 > > x <- quadmap(xi = 0.2, a = 4.0, n = 100) > bds.test(x) # not independent BDS Test data: x Embedding dimension = 2 3 Epsilon for close points = 0.1786 0.3573 0.5359 0.7145 Standard Normal = [ 0.1786 ] [ 0.3573 ] [ 0.5359 ] [ 0.7145 ] [ 2 ] 547.6341 123.2873 2.0759 -9.3362 [ 3 ] 743.4724 115.3152 -2.1764 -7.9260 p-value = [ 0.1786 ] [ 0.3573 ] [ 0.5359 ] [ 0.7145 ] [ 2 ] 0 0 0.0379 0 [ 3 ] 0 0 0.0295 0 > > > > cleanEx(); ..nameEx <- "garch" > > ### * garch > > flush(stderr()); flush(stdout()) > > ### Name: garch > ### Title: Fit GARCH Models to Time Series > ### Aliases: garch > ### Keywords: ts > > ### ** Examples > > 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) ***** ESTIMATION WITH ANALYTICAL GRADIENT ***** I INITIAL X(I) D(I) 1 0.349117E+00 0.100E+01 2 0.500000E-01 0.100E+01 3 0.500000E-01 0.100E+01 IT NF F RELDF PRELDF RELDX STPPAR D*STEP NPRELDF 0 1 -0.419E+02 1 3 -0.829E+02 0.49E+00 0.66E+00 0.1E+00 0.5E+04 0.1E+00 0.18E+04 2 5 -0.117E+03 0.29E+00 0.33E+00 0.2E+00 0.9E+01 0.1E+00 0.13E+04 3 6 -0.137E+03 0.15E+00 0.19E+00 0.2E+00 0.8E+01 0.1E+00 0.45E+02 4 7 -0.139E+03 0.15E-01 0.14E+00 0.1E+00 0.8E+01 0.1E+00 0.57E+01 5 8 -0.147E+03 0.56E-01 0.82E-01 0.1E+00 0.2E+01 0.1E+00 0.68E+00 6 9 -0.150E+03 0.23E-01 0.41E-01 0.1E+00 0.2E+01 0.1E+00 0.20E+01 7 11 -0.151E+03 0.59E-02 0.84E-02 0.2E-01 0.2E+01 0.2E-01 0.12E+00 8 12 -0.152E+03 0.53E-02 0.67E-02 0.2E-01 0.2E+01 0.2E-01 0.53E+00 9 13 -0.152E+03 0.24E-02 0.68E-02 0.5E-01 0.2E+01 0.4E-01 0.18E+00 10 14 -0.153E+03 0.59E-02 0.12E-01 0.8E-01 0.2E+01 0.8E-01 0.81E-01 11 16 -0.154E+03 0.18E-02 0.55E-02 0.1E-01 0.2E+02 0.1E-01 0.15E+00 12 17 -0.154E+03 0.36E-02 0.38E-02 0.1E-01 0.2E+01 0.1E-01 0.21E-01 13 18 -0.155E+03 0.43E-02 0.49E-02 0.3E-01 0.1E+01 0.3E-01 0.11E-01 14 19 -0.155E+03 0.34E-02 0.36E-02 0.5E-01 0.0E+00 0.5E-01 0.36E-02 15 20 -0.155E+03 0.11E-03 0.10E-03 0.5E-02 0.0E+00 0.5E-02 0.10E-03 16 21 -0.155E+03 0.88E-06 0.91E-06 0.8E-03 0.0E+00 0.8E-03 0.91E-06 17 22 -0.155E+03 0.19E-07 0.24E-07 0.2E-03 0.0E+00 0.2E-03 0.24E-07 18 23 -0.155E+03 0.91E-09 0.91E-09 0.3E-04 0.0E+00 0.3E-04 0.91E-09 19 24 -0.155E+03 0.73E-14 0.71E-14 0.4E-07 0.0E+00 0.4E-07 0.71E-14 ***** RELATIVE FUNCTION CONVERGENCE ***** FUNCTION -0.155444E+03 RELDX 0.389E-07 FUNC. EVALS 24 GRAD. EVALS 20 PRELDF 0.709E-14 NPRELDF 0.709E-14 I FINAL X(I) D(I) G(I) 1 0.111111E+00 0.100E+01 0.344E-05 2 0.479876E+00 0.100E+01 -0.399E-07 3 0.263690E+00 0.100E+01 0.444E-06 > summary(x.arch) # Diagnostic tests Call: garch(x = x, order = c(0, 2)) Model: GARCH(0,2) Residuals: Min 1Q Median 3Q Max -2.84044 -0.69758 -0.03496 0.66715 3.40413 Coefficient(s): Estimate Std. Error t value Pr(>|t|) a0 0.11111 0.01199 9.264 < 2e-16 *** a1 0.47988 0.06310 7.605 2.86e-14 *** a2 0.26369 0.04626 5.700 1.20e-08 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Diagnostic Tests: Jarque Bera Test data: Residuals X-squared = 0.3683, df = 2, p-value = 0.8318 Box-Ljung test data: Squared.Residuals X-squared = 0.033, df = 1, p-value = 0.8558 > plot(x.arch) > > data(EuStockMarkets) > dax <- diff(log(EuStockMarkets))[,"DAX"] > dax.garch <- garch(dax) # Fit a GARCH(1,1) to DAX returns ***** ESTIMATION WITH ANALYTICAL GRADIENT ***** I INITIAL X(I) D(I) 1 0.954965E-04 0.100E+01 2 0.500000E-01 0.100E+01 3 0.500000E-01 0.100E+01 IT NF F RELDF PRELDF RELDX STPPAR D*STEP NPRELDF 0 1 -0.758E+04 1 8 -0.758E+04 0.14E-04 0.26E-04 0.1E-04 0.1E+12 0.1E-05 0.13E+07 2 9 -0.758E+04 0.19E-06 0.20E-06 0.1E-04 0.2E+01 0.1E-05 0.15E+01 3 18 -0.759E+04 0.62E-03 0.11E-02 0.3E+00 0.2E+01 0.6E-01 0.15E+01 4 21 -0.760E+04 0.16E-02 0.18E-02 0.6E+00 0.2E+01 0.2E+00 0.31E+00 5 23 -0.763E+04 0.42E-02 0.36E-02 0.4E+00 0.1E+01 0.4E+00 0.31E-01 6 25 -0.765E+04 0.16E-02 0.18E-02 0.3E-01 0.2E+01 0.4E-01 0.54E-01 7 27 -0.765E+04 0.38E-04 0.52E-03 0.1E-01 0.2E+01 0.2E-01 0.15E-01 8 28 -0.765E+04 0.19E-03 0.15E-03 0.7E-02 0.2E+01 0.1E-01 0.15E-02 9 29 -0.765E+04 0.31E-04 0.48E-04 0.6E-02 0.2E+01 0.1E-01 0.33E-02 10 30 -0.765E+04 0.14E-04 0.63E-04 0.6E-02 0.2E+01 0.1E-01 0.19E-02 11 31 -0.765E+04 0.27E-03 0.32E-03 0.6E-02 0.2E+01 0.1E-01 0.50E-02 12 34 -0.766E+04 0.84E-03 0.86E-03 0.2E-01 0.2E+00 0.4E-01 0.22E-02 13 36 -0.766E+04 0.61E-03 0.64E-03 0.2E-01 0.4E+00 0.4E-01 0.21E-02 14 38 -0.766E+04 0.49E-03 0.86E-03 0.5E-01 0.4E+00 0.1E+00 0.97E-03 15 48 -0.767E+04 0.10E-03 0.19E-03 0.2E-06 0.4E+01 0.3E-06 0.39E-03 16 49 -0.767E+04 0.11E-06 0.10E-06 0.2E-06 0.2E+01 0.3E-06 0.62E-04 17 57 -0.767E+04 0.16E-04 0.27E-04 0.2E-02 0.9E+00 0.4E-02 0.61E-04 18 59 -0.767E+04 0.52E-05 0.70E-05 0.4E-02 0.4E+00 0.8E-02 0.78E-05 19 60 -0.767E+04 0.41E-07 0.37E-07 0.1E-03 0.0E+00 0.3E-03 0.37E-07 20 61 -0.767E+04 0.23E-08 0.86E-09 0.9E-05 0.0E+00 0.2E-04 0.86E-09 21 62 -0.767E+04 0.54E-10 0.23E-12 0.8E-06 0.0E+00 0.2E-05 0.23E-12 22 63 -0.767E+04 0.18E-11 0.71E-15 0.2E-07 0.0E+00 0.3E-07 0.71E-15 23 64 -0.767E+04 0.70E-13 0.17E-16 0.1E-08 0.0E+00 0.2E-08 0.17E-16 24 65 -0.767E+04 -0.12E-13 0.18E-19 0.2E-09 0.0E+00 0.4E-09 0.18E-19 ***** X- AND RELATIVE FUNCTION CONVERGENCE ***** FUNCTION -0.766578E+04 RELDX 0.187E-09 FUNC. EVALS 65 GRAD. EVALS 24 PRELDF 0.176E-19 NPRELDF 0.176E-19 I FINAL X(I) D(I) G(I) 1 0.463929E-05 0.100E+01 -0.234E-01 2 0.683287E-01 0.100E+01 -0.829E-06 3 0.889067E+00 0.100E+01 -0.223E-05 > summary(dax.garch) # ARCH effects are filtered. However, Call: garch(x = dax) Model: GARCH(1,1) Residuals: Min 1Q Median 3Q Max -12.18398 -0.47968 0.04949 0.65746 4.48048 Coefficient(s): Estimate Std. Error t value Pr(>|t|) a0 4.639e-06 7.560e-07 6.137 8.42e-10 *** a1 6.833e-02 1.125e-02 6.073 1.25e-09 *** b1 8.891e-01 1.652e-02 53.817 < 2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Diagnostic Tests: Jarque Bera Test data: Residuals X-squared = 12946.60, df = 2, p-value < 2.2e-16 Box-Ljung test data: Squared.Residuals X-squared = 0.1357, df = 1, p-value = 0.7126 > plot(dax.garch) # conditional normality seems to be violated > > > > cleanEx(); ..nameEx <- "get.hist.quote" > > ### * get.hist.quote > > flush(stderr()); flush(stdout()) > > ### Name: get.hist.quote > ### Title: Download Historical Finance Data > ### Aliases: get.hist.quote > ### Keywords: ts > > ### ** Examples > > if(!inherits(try(open(url("http://quote.yahoo.com")), silent = TRUE), + "try-error")) { + x <- get.hist.quote(instrument = "^gspc", start = "1998-01-01", + quote = "Close") + plot(x) + + x <- get.hist.quote(instrument = "ibm", quote = c("Cl", "Vol")) + plot(x, main = "International Business Machines Corp") + + spc <- get.hist.quote(instrument = "^gspc", start = "1998-01-01") + ibm <- get.hist.quote(instrument = "ibm", start = "1998-01-01") + x <- na.remove(ts.union(spc, ibm)) + plot(x, main = "IBM vs S&P 500") + } trying URL 'http://chart.yahoo.com/table.csv?s=^gspc&a=0&b=01&c=1998&d=6&e=12&f=2005&g=d&q=q&y=0&z=^gspc&x=.csv' Content type 'text/csv' length unknown opened URL .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... ...... downloaded 106Kb time series starts 1998-01-02 trying URL 'http://chart.yahoo.com/table.csv?s=ibm&a=0&b=02&c=1991&d=6&e=12&f=2005&g=d&q=q&y=0&z=ibm&x=.csv' Content type 'text/csv' length unknown opened URL .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... ........ downloaded 178Kb trying URL 'http://chart.yahoo.com/table.csv?s=^gspc&a=0&b=01&c=1998&d=6&e=12&f=2005&g=d&q=q&y=0&z=^gspc&x=.csv' Content type 'text/csv' length unknown opened URL .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... ...... downloaded 106Kb time series starts 1998-01-02 trying URL 'http://chart.yahoo.com/table.csv?s=ibm&a=0&b=01&c=1998&d=6&e=12&f=2005&g=d&q=q&y=0&z=ibm&x=.csv' Content type 'text/csv' length unknown opened URL .......... .......... .......... .......... .......... .......... .......... .......... .......... .. downloaded 92Kb time series starts 1998-01-02 > > > > cleanEx(); ..nameEx <- "irts-functions" > > ### * irts-functions > > flush(stderr()); flush(stdout()) > > ### Name: irts-functions > ### Title: Basic Functions for Irregular Time-Series Objects > ### Aliases: irts-functions approx.irts daysecond is.businessday is.weekend > ### read.irts weekday write.irts > ### Keywords: ts > > ### ** Examples > > n <- 10 > t <- cumsum(rexp(n, rate = 0.1)) > v <- rnorm(n) > x <- irts(t, v) > > daysecond(x) [1] 7 19 20 22 26 55 67 73 82 84 > weekday(x) [1] 4 4 4 4 4 4 4 4 4 4 > is.businessday(x) [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE > is.weekend(x) [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE > x 1970-01-01 00:00:07 GMT -1.148 1970-01-01 00:00:19 GMT -0.2895 1970-01-01 00:00:20 GMT -0.2992 1970-01-01 00:00:22 GMT -0.4115 1970-01-01 00:00:26 GMT 0.2522 1970-01-01 00:00:55 GMT -0.8919 1970-01-01 00:01:07 GMT 0.4357 1970-01-01 00:01:13 GMT -1.238 1970-01-01 00:01:22 GMT -0.2243 1970-01-01 00:01:24 GMT 0.3774 > > approx.irts(x, seq(ISOdatetime(1970, 1, 1, 0, 0, 0, tz = "GMT"), + by = "10 secs", length = 7), rule = 2) 1970-01-01 00:00:00 GMT -1.148 1970-01-01 00:00:10 GMT -0.9699 1970-01-01 00:00:20 GMT -0.2937 1970-01-01 00:00:30 GMT 0.1172 1970-01-01 00:00:40 GMT -0.278 1970-01-01 00:00:50 GMT -0.6732 1970-01-01 00:01:00 GMT -0.4097 > > ## Not run: > ##D file <- tempfile() > ##D > ##D # To write an irregular time-series object to a file one might use > ##D write.irts(x, file = file) > ##D > ##D # To read an irregular time-series object from a file one might use > ##D read.irts(file = file) > ##D > ##D unlink(file) > ## End(Not run) > > > > cleanEx(); ..nameEx <- "irts-methods" > > ### * irts-methods > > flush(stderr()); flush(stdout()) > > ### Name: irts-methods > ### Title: Methods for Irregular Time-Series Objects > ### Aliases: irts-methods lines.irts plot.irts points.irts print.irts > ### time.irts value value.irts [.irts > ### Keywords: ts > > ### ** Examples > > n <- 10 > t <- cumsum(rexp(n, rate = 0.1)) > v <- rnorm(n) > x <- irts(t, v) > > x 1970-01-01 00:00:07 GMT -1.148 1970-01-01 00:00:19 GMT -0.2895 1970-01-01 00:00:20 GMT -0.2992 1970-01-01 00:00:22 GMT -0.4115 1970-01-01 00:00:26 GMT 0.2522 1970-01-01 00:00:55 GMT -0.8919 1970-01-01 00:01:07 GMT 0.4357 1970-01-01 00:01:13 GMT -1.238 1970-01-01 00:01:22 GMT -0.2243 1970-01-01 00:01:24 GMT 0.3774 > time(x) [1] "1970-01-01 01:00:07 CET" "1970-01-01 01:00:19 CET" [3] "1970-01-01 01:00:20 CET" "1970-01-01 01:00:22 CET" [5] "1970-01-01 01:00:26 CET" "1970-01-01 01:00:55 CET" [7] "1970-01-01 01:01:07 CET" "1970-01-01 01:01:13 CET" [9] "1970-01-01 01:01:22 CET" "1970-01-01 01:01:24 CET" > value(x) [1] -1.1476570 -0.2894616 -0.2992151 -0.4115108 0.2522234 -0.8919211 [7] 0.4356833 -1.2375384 -0.2242679 0.3773956 > plot(x) > points(x) > > t <- cumsum(c(t[1], rexp(n-1, rate = 0.2))) > v <- rnorm(n, sd = 0.1) > x <- irts(t, v) > > lines(x, col = "red") > points(x, col = "red") > > # Multivariate > t <- cumsum(rexp(n, rate = 0.1)) > u <- rnorm(n) > v <- rnorm(n) > x <- irts(t, cbind(u, v)) > > x 1970-01-01 00:00:03 GMT -0.1123 0.5697 1970-01-01 00:00:15 GMT 0.8811 -0.1351 1970-01-01 00:00:25 GMT 0.3981 2.402 1970-01-01 00:00:31 GMT -0.612 -0.03924 1970-01-01 00:00:51 GMT 0.3411 0.6897 1970-01-01 00:00:55 GMT -1.129 0.028 1970-01-01 00:01:17 GMT 1.433 -0.7433 1970-01-01 00:01:49 GMT 1.98 0.1888 1970-01-01 00:01:54 GMT -0.3672 -1.805 1970-01-01 00:02:00 GMT -1.044 1.466 > x[,1] 1970-01-01 00:00:03 GMT -0.1123 1970-01-01 00:00:15 GMT 0.8811 1970-01-01 00:00:25 GMT 0.3981 1970-01-01 00:00:31 GMT -0.612 1970-01-01 00:00:51 GMT 0.3411 1970-01-01 00:00:55 GMT -1.129 1970-01-01 00:01:17 GMT 1.433 1970-01-01 00:01:49 GMT 1.98 1970-01-01 00:01:54 GMT -0.3672 1970-01-01 00:02:00 GMT -1.044 > x[1:3,] 1970-01-01 00:00:03 GMT -0.1123 0.5697 1970-01-01 00:00:15 GMT 0.8811 -0.1351 1970-01-01 00:00:25 GMT 0.3981 2.402 > x[1:3,1] 1970-01-01 00:00:03 GMT -0.1123 1970-01-01 00:00:15 GMT 0.8811 1970-01-01 00:00:25 GMT 0.3981 > plot(x) > > > > cleanEx(); ..nameEx <- "irts" > > ### * irts > > flush(stderr()); flush(stdout()) > > ### Name: irts > ### Title: Irregularly Spaced Time-Series > ### Aliases: irts is.irts as.irts as.irts.default as.irts.zoo > ### Keywords: ts > > ### ** Examples > > n <- 10 > t <- cumsum(rexp(n, rate = 0.1)) > v <- rnorm(n) > x <- irts(t, v) > x 1970-01-01 00:00:07 GMT -1.148 1970-01-01 00:00:19 GMT -0.2895 1970-01-01 00:00:20 GMT -0.2992 1970-01-01 00:00:22 GMT -0.4115 1970-01-01 00:00:26 GMT 0.2522 1970-01-01 00:00:55 GMT -0.8919 1970-01-01 00:01:07 GMT 0.4357 1970-01-01 00:01:13 GMT -1.238 1970-01-01 00:01:22 GMT -0.2243 1970-01-01 00:01:24 GMT 0.3774 > > as.irts(cbind(t, v)) 1970-01-01 00:00:07 GMT -1.148 1970-01-01 00:00:19 GMT -0.2895 1970-01-01 00:00:20 GMT -0.2992 1970-01-01 00:00:22 GMT -0.4115 1970-01-01 00:00:26 GMT 0.2522 1970-01-01 00:00:55 GMT -0.8919 1970-01-01 00:01:07 GMT 0.4357 1970-01-01 00:01:13 GMT -1.238 1970-01-01 00:01:22 GMT -0.2243 1970-01-01 00:01:24 GMT 0.3774 > > is.irts(x) [1] TRUE > > # Multivariate > u <- rnorm(n) > irts(t, cbind(u, v)) 1970-01-01 00:00:07 GMT 0.1333 -1.148 1970-01-01 00:00:19 GMT 0.8042 -0.2895 1970-01-01 00:00:20 GMT -0.05711 -0.2992 1970-01-01 00:00:22 GMT 0.5036 -0.4115 1970-01-01 00:00:26 GMT 1.086 0.2522 1970-01-01 00:00:55 GMT -0.691 -0.8919 1970-01-01 00:01:07 GMT -1.285 0.4357 1970-01-01 00:01:13 GMT 0.04673 -1.238 1970-01-01 00:01:22 GMT -0.2357 -0.2243 1970-01-01 00:01:24 GMT -0.5429 0.3774 > > > > cleanEx(); ..nameEx <- "jarque.bera.test" > > ### * jarque.bera.test > > flush(stderr()); flush(stdout()) > > ### Name: jarque.bera.test > ### Title: Jarque-Bera Test > ### Aliases: jarque.bera.test > ### Keywords: ts > > ### ** Examples > > x <- rnorm(100) # null > jarque.bera.test(x) Jarque Bera Test data: x X-squared = 0.0872, df = 2, p-value = 0.9573 > > x <- runif(100) # alternative > jarque.bera.test(x) Jarque Bera Test data: x X-squared = 7.4366, df = 2, p-value = 0.02427 > > > > cleanEx(); ..nameEx <- "kpss.test" > > ### * kpss.test > > flush(stderr()); flush(stdout()) > > ### Name: kpss.test > ### Title: KPSS Test for Stationarity > ### Aliases: kpss.test > ### Keywords: ts > > ### ** Examples > > x <- rnorm(1000) # is level stationary > kpss.test(x) Warning in kpss.test(x) : p-value greater than printed p-value KPSS Test for Level Stationarity data: x KPSS Level = 0.1567, Truncation lag parameter = 7, p-value = 0.1 > > y <- cumsum(x) # has unit root > kpss.test(y) Warning in kpss.test(y) : p-value smaller than printed p-value KPSS Test for Level Stationarity data: y KPSS Level = 8.3746, Truncation lag parameter = 7, p-value = 0.01 > > x <- 0.3*(1:1000)+rnorm(1000) # is trend stationary > kpss.test(x, null = "Trend") Warning in kpss.test(x, null = "Trend") : p-value greater than printed p-value KPSS Test for Trend Stationarity data: x KPSS Trend = 0.0381, Truncation lag parameter = 7, p-value = 0.1 > > > > cleanEx(); ..nameEx <- "maxdrawdown" > > ### * maxdrawdown > > flush(stderr()); flush(stdout()) > > ### Name: maxdrawdown > ### Title: Maximum Drawdown or Maximum Loss > ### Aliases: maxdrawdown > ### Keywords: ts > > ### ** Examples > > # Toy example > x <- c(1:10, 9:7, 8:14, 13:8, 9:20) > mdd <- maxdrawdown(x) > mdd $maxdrawdown [1] 6 $from [1] 20 $to [1] 26 > > plot(x) > segments(mdd$from, x[mdd$from], mdd$to, x[mdd$from], col="grey") > segments(mdd$from, x[mdd$to], mdd$to, x[mdd$to], col="grey") > mid <- (mdd$from + mdd$to)/2 > arrows(mid, x[mdd$from], mid, x[mdd$to], col="red", length = 0.16) > > # Realistic example > data(EuStockMarkets) > dax <- log(EuStockMarkets[,"DAX"]) > mdd <- maxdrawdown(dax) > mdd $maxdrawdown [1] 0.2564710 $from [1] 236 $to [1] 331 > > plot(dax) > segments(time(dax)[mdd$from], dax[mdd$from], + time(dax)[mdd$to], dax[mdd$from], col="grey") > segments(time(dax)[mdd$from], dax[mdd$to], + time(dax)[mdd$to], dax[mdd$to], col="grey") > mid <- time(dax)[(mdd$from + mdd$to)/2] > arrows(mid, dax[mdd$from], mid, dax[mdd$to], col="red", length = 0.16) > > > > cleanEx(); ..nameEx <- "na.remove" > > ### * na.remove > > flush(stderr()); flush(stdout()) > > ### Name: na.remove > ### Title: NA Handling Routines for Time Series > ### Aliases: na.remove na.remove.ts na.remove.default > ### Keywords: ts > > ### ** Examples > > x<-ts(c(5453.08,5409.24,5315.57,5270.53, # one and a half week stock index + 5211.66,NA,NA,5160.80,5172.37)) # data including a weekend > na.remove(x) # eliminate weekend and introduce ``business'' time scale Time Series: Start = 1 End = 9 Frequency = 0.75 [1] 5453.08 5409.24 5315.57 5270.53 5211.66 5160.80 5172.37 attr(,"na.removed") [1] 6 7 > > > > cleanEx(); ..nameEx <- "plotOHLC" > > ### * plotOHLC > > flush(stderr()); flush(stdout()) > > ### Name: plotOHLC > ### Title: Plot Open-High-Low-Close Bar Chart > ### Aliases: plotOHLC > ### Keywords: hplot ts > > ### ** Examples > > if(!inherits(try(open(url("http://quote.yahoo.com")), silent = TRUE), + "try-error")) { + ## Plot OHLC bar chart for the last 'nDays' days of the instrument + ## 'instrument' + + nDays <- 50 + instrument <- "^gspc" + + start <- strftime(as.POSIXlt(Sys.time() - nDays*24*3600), + format="%Y-%m-%d") + end <- strftime(as.POSIXlt(Sys.time()), format = "%Y-%m-%d") + x <- get.hist.quote(instrument = instrument, start = start, end = end) + + plotOHLC(x, ylab = "price", main = instrument) + } trying URL 'http://chart.yahoo.com/table.csv?s=^gspc&a=4&b=24&c=2005&d=6&e=13&f=2005&g=d&q=q&y=0&z=^gspc&x=.csv' Content type 'text/csv' length unknown opened URL . downloaded 2038 bytes time series ends 2005-07-12 > > > > cleanEx(); ..nameEx <- "po.test" > > ### * po.test > > flush(stderr()); flush(stdout()) > > ### Name: po.test > ### Title: Phillips-Ouliaris Cointegration Test > ### Aliases: po.test > ### Keywords: ts > > ### ** Examples > > x <- ts(diffinv(matrix(rnorm(2000),1000,2))) # no cointegration > po.test(x) Warning in po.test(x) : p-value greater than printed p-value Phillips-Ouliaris Cointegration Test data: x Phillips-Ouliaris demeaned = -10.1761, Truncation lag parameter = 10, p-value = 0.15 > > x <- diffinv(rnorm(1000)) > y <- 2.0-3.0*x+rnorm(x,sd=5) > z <- ts(cbind(x,y)) # cointegrated > po.test(z) Warning in po.test(z) : p-value smaller than printed p-value Phillips-Ouliaris Cointegration Test data: z Phillips-Ouliaris demeaned = -1147.098, Truncation lag parameter = 10, p-value = 0.01 > > > > cleanEx(); ..nameEx <- "portfolio.optim" > > ### * portfolio.optim > > flush(stderr()); flush(stdout()) > > ### Name: portfolio.optim > ### Title: Portfolio Optimization > ### Aliases: portfolio.optim portfolio.optim.ts portfolio.optim.default > ### Keywords: ts > > ### ** Examples > > x <- rnorm(1000) > dim(x) <- c(500,2) > res <- portfolio.optim(x) > res$pw [1] 0.5 0.5 > > > > cleanEx(); ..nameEx <- "pp.test" > > ### * pp.test > > flush(stderr()); flush(stdout()) > > ### Name: pp.test > ### Title: Phillips-Perron Unit Root Test > ### Aliases: pp.test > ### Keywords: ts > > ### ** Examples > > x <- rnorm(1000) # no unit-root > pp.test(x) Warning in pp.test(x) : p-value smaller than printed p-value Phillips-Perron Unit Root Test data: x Dickey-Fuller Z(alpha) = -959.9805, Truncation lag parameter = 7, p-value = 0.01 alternative hypothesis: stationary > > y <- cumsum(x) # has unit root > pp.test(y) Phillips-Perron Unit Root Test data: y Dickey-Fuller Z(alpha) = -11.0743, Truncation lag parameter = 7, p-value = 0.492 alternative hypothesis: stationary > > > > cleanEx(); ..nameEx <- "quadmap" > > ### * quadmap > > flush(stderr()); flush(stdout()) > > ### Name: quadmap > ### Title: Quadratic Map (Logistic Equation) > ### Aliases: quadmap > ### Keywords: ts > > ### ** Examples > > x <- quadmap() > acf(x, 10) > > > > cleanEx(); ..nameEx <- "read.matrix" > > ### * read.matrix > > flush(stderr()); flush(stdout()) > > ### Name: read.matrix > ### Title: Read Matrix Data > ### Aliases: read.matrix > ### Keywords: file ts > > ### ** Examples > > x <- matrix(0, 10, 10) > write(x, "test", ncolumns=10) > x <- read.matrix("test") > x [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 0 0 0 0 0 0 0 0 0 0 [2,] 0 0 0 0 0 0 0 0 0 0 [3,] 0 0 0 0 0 0 0 0 0 0 [4,] 0 0 0 0 0 0 0 0 0 0 [5,] 0 0 0 0 0 0 0 0 0 0 [6,] 0 0 0 0 0 0 0 0 0 0 [7,] 0 0 0 0 0 0 0 0 0 0 [8,] 0 0 0 0 0 0 0 0 0 0 [9,] 0 0 0 0 0 0 0 0 0 0 [10,] 0 0 0 0 0 0 0 0 0 0 > unlink("test") > > > > cleanEx(); ..nameEx <- "read.ts" > > ### * read.ts > > flush(stderr()); flush(stdout()) > > ### Name: read.ts > ### Title: Read Time Series Data > ### Aliases: read.ts > ### Keywords: file ts > > ### ** Examples > > data(sunspots) > st <- start(sunspots) > fr <- frequency(sunspots) > write(sunspots, "sunspots", ncolumns=1) > x <- read.ts("sunspots", start=st, frequency=fr) > plot(x) > unlink("sunspots") > > > > cleanEx(); ..nameEx <- "runs.test" > > ### * runs.test > > flush(stderr()); flush(stdout()) > > ### Name: runs.test > ### Title: Runs Test > ### Aliases: runs.test > ### Keywords: ts > > ### ** Examples > > x <- factor(sign(rnorm(100))) # randomness > runs.test(x) Runs Test data: x Standard Normal = 0.874, p-value = 0.3821 alternative hypothesis: two.sided > > x <- factor(rep(c(-1,1),50)) # over-mixing > runs.test(x) Runs Test data: x Standard Normal = 9.8499, p-value < 2.2e-16 alternative hypothesis: two.sided > > > > cleanEx(); ..nameEx <- "seqplot.ts" > > ### * seqplot.ts > > flush(stderr()); flush(stdout()) > > ### Name: seqplot.ts > ### Title: Plot Two Time Series > ### Aliases: seqplot.ts > ### Keywords: hplot ts > > ### ** Examples > > data(USeconomic) > x <- ts.union(log(M1), log(GNP), rs, rl) > m.ar <- ar(x, method = "ols", order.max = 5) > y <- predict(m.ar, x, n.ahead = 200, se.fit = FALSE) > seqplot.ts(x, y) > > > > cleanEx(); ..nameEx <- "sharpe" > > ### * sharpe > > flush(stderr()); flush(stdout()) > > ### Name: sharpe > ### Title: Sharpe Ratio > ### Aliases: sharpe > ### Keywords: ts > > ### ** Examples > > data(EuStockMarkets) > dax <- log(EuStockMarkets[,"DAX"]) > ftse <- log(EuStockMarkets[,"FTSE"]) > sharpe(dax) [1] 1.000859 > sharpe(ftse) [1] 0.8583209 > > > > cleanEx(); ..nameEx <- "sterling" > > ### * sterling > > flush(stderr()); flush(stdout()) > > ### Name: sterling > ### Title: Sterling Ratio > ### Aliases: sterling > ### Keywords: ts > > ### ** Examples > > data(EuStockMarkets) > dax <- log(EuStockMarkets[,"DAX"]) > ftse <- log(EuStockMarkets[,"FTSE"]) > sterling(dax) [1] 4.726247 > sterling(ftse) [1] 3.976783 > > > > cleanEx(); ..nameEx <- "surrogate" > > ### * surrogate > > flush(stderr()); flush(stdout()) > > ### Name: surrogate > ### Title: Generate Surrogate Data and Statistics > ### Aliases: surrogate > ### Keywords: ts > > ### ** Examples > > x <- 1:10 # Simple example > surrogate(x) [1] 3 4 5 7 2 8 9 6 10 1 > > n <- 500 # Generate AR(1) process > e <- rnorm(n) > x <- double(n) > x[1] <- rnorm(1) > for(i in 2:n) { + x[i] <- 0.4 * x[i-1] + e[i] + } > x <- ts(x) > > theta <- function(x) # Autocorrelations up to lag 10 + return(acf(x, plot=FALSE)$acf[2:11]) > > surrogate(x, ns=50, fft=TRUE, statistic=theta) Call: surrogate(x = x, ns = 50, fft = TRUE, statistic = theta) Resampled Statistic(s): original bias std. error t1 0.374810 0.0011907 0.03944 t2 0.134444 -0.0030015 0.04361 t3 0.016285 -0.0037099 0.04704 t4 -0.008473 -0.0005084 0.05048 t5 0.010654 -0.0027345 0.04976 t6 -0.034255 -0.0046383 0.05218 t7 -0.013122 -0.0052239 0.05758 t8 -0.049111 -0.0053905 0.05297 t9 0.039606 -0.0022296 0.05607 t10 -0.031181 0.0003305 0.05549 > > > > cleanEx(); ..nameEx <- "terasvirta.test" > > ### * terasvirta.test > > flush(stderr()); flush(stdout()) > > ### Name: terasvirta.test > ### Title: Teraesvirta Neural Network Test for Nonlinearity > ### Aliases: terasvirta.test terasvirta.test.ts terasvirta.test.default > ### Keywords: ts > > ### ** Examples > > n <- 1000 > > x <- runif(1000, -1, 1) # Non-linear in ``mean'' regression > y <- x^2 - x^3 + 0.1*rnorm(x) > terasvirta.test(x, y) Teraesvirta Neural Network Test data: x and y X-squared = 2402.737, df = 2, p-value < 2.2e-16 > > ## Is the polynomial of order 2 misspecified? > terasvirta.test(cbind(x,x^2,x^3), y) Teraesvirta Neural Network Test data: cbind(x, x^2, x^3) and y X-squared = 13.9996, df = 16, p-value = 0.5987 > > ## Generate time series which is nonlinear in ``mean'' > x[1] <- 0.0 > for(i in (2:n)) { + x[i] <- 0.4*x[i-1] + tanh(x[i-1]) + rnorm(1, sd=0.5) + } > x <- as.ts(x) > plot(x) > terasvirta.test(x) Teraesvirta Neural Network Test data: x X-squared = 99.3426, df = 2, p-value < 2.2e-16 > > > > cleanEx(); ..nameEx <- "tsbootstrap" > > ### * tsbootstrap > > flush(stderr()); flush(stdout()) > > ### Name: tsbootstrap > ### Title: Bootstrap for General Stationary Data > ### Aliases: tsbootstrap print.resample.statistic > ### Keywords: ts > > ### ** Examples > > n <- 500 # Generate AR(1) process > a <- 0.6 > e <- rnorm(n+100) > x <- double(n+100) > x[1] <- rnorm(1) > for(i in 2:(n+100)) { + x[i] <- a * x[i-1] + e[i] + } > x <- ts(x[-(1:100)]) > > tsbootstrap(x, nb=500, statistic=mean) Call: tsbootstrap(x = x, nb = 500, statistic = mean) Resampled Statistic(s): original bias std. error -0.022423 0.001845 0.086216 > > # Asymptotic formula for the std. error of the mean > sqrt(1/(n*(1-a)^2)) [1] 0.1118034 > > acflag1 <- function(x) + { + xo <- c(x[,1], x[1,2]) + xm <- mean(xo) + return(mean((x[,1]-xm)*(x[,2]-xm))/mean((xo-xm)^2)) + } > > tsbootstrap(x, nb=500, statistic=acflag1, m=2) Call: tsbootstrap(x = x, nb = 500, statistic = acflag1, m = 2) Resampled Statistic(s): original bias std. error 0.564634 -0.002872 0.028284 > > # Asymptotic formula for the std. error of the acf at lag one > sqrt(((1+a^2)-2*a^2)/n) [1] 0.03577709 > > > > cleanEx(); ..nameEx <- "white.test" > > ### * white.test > > flush(stderr()); flush(stdout()) > > ### Name: white.test > ### Title: White Neural Network Test for Nonlinearity > ### Aliases: white.test white.test.ts white.test.default > ### Keywords: ts > > ### ** Examples > > n <- 1000 > > x <- runif(1000, -1, 1) # Non-linear in ``mean'' regression > y <- x^2 - x^3 + 0.1*rnorm(x) > white.test(x, y) White Neural Network Test data: x and y X-squared = 2311.42, df = 2, p-value < 2.2e-16 > > ## Is the polynomial of order 2 misspecified? > white.test(cbind(x,x^2,x^3), y) White Neural Network Test data: cbind(x, x^2, x^3) and y X-squared = 0.4701, df = 2, p-value = 0.7906 > > ## Generate time series which is nonlinear in ``mean'' > x[1] <- 0.0 > for(i in (2:n)) { + x[i] <- 0.4*x[i-1] + tanh(x[i-1]) + rnorm(1, sd=0.5) + } > x <- as.ts(x) > plot(x) > white.test(x) White Neural Network Test data: x X-squared = 95.9481, df = 2, p-value < 2.2e-16 > > > > ### *