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("dynlm-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('dynlm') Loading required package: zoo > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "M1Germany" > > ### * M1Germany > > flush(stderr()); flush(stdout()) > > ### Encoding: latin1 > > ### Name: M1Germany > ### Title: German M1 Money Demand > ### Aliases: M1Germany > ### Keywords: datasets > > ### ** Examples > > data(M1Germany) > ## fit the model of Lütkepohl et al. (1999) on the history period > ## before the monetary unification > histfm <- dynlm(d(logm1) ~ d(L(loggnp, 2)) + d(interest) + d(L(interest)) + d(logprice) + + L(logm1) + L(loggnp) + L(interest) + + season(logm1), + data = M1Germany, start = c(1961, 1), end = c(1990, 2)) > > ## fit on extended sample period > fm <- update(histfm, end = c(1995, 4)) > > if(require(strucchange)) { + scus <- gefp(fm, fit = NULL) + plot(scus, functional = supLM(0.1)) + } Loading required package: strucchange Loading required package: sandwich > > > > cleanEx(); ..nameEx <- "dynlm" Warning in detach("package:sandwich") : package:sandwich is required by package:strucchange (still attached) > > ### * dynlm > > flush(stderr()); flush(stdout()) > > ### Name: dynlm > ### Title: Dynamic Linear Models and Time-Series Regression > ### Aliases: dynlm > ### Keywords: regression > > ### ** Examples > > ## multiplicative SARIMA(1,0,0)(1,0,0)_12 model fitted > ## to UK seatbelt data > uk <- log10(UKDriverDeaths) > dfm <- dynlm(uk ~ L(uk, 1) + L(uk, 12)) > dfm Call: dynlm(formula = uk ~ L(uk, 1) + L(uk, 12)) Coefficients: (Intercept) L(uk, 1) L(uk, 12) 0.1826 0.4310 0.5112 > ## explicitely set start and end > dfm <- dynlm(uk ~ L(uk, 1) + L(uk, 12), start = c(1975, 1), end = c(1982, 12)) > dfm Call: dynlm(formula = uk ~ L(uk, 1) + L(uk, 12), start = c(1975, 1), end = c(1982, 12)) Coefficients: (Intercept) L(uk, 1) L(uk, 12) 0.5418 0.2072 0.6228 > > ## remove lag 12 > dfm0 <- update(dfm, . ~ . - L(uk, 12)) > anova(dfm0, dfm) Analysis of Variance Table Model 1: uk ~ L(uk, 1) Model 2: uk ~ L(uk, 1) + L(uk, 12) Res.Df RSS Df Sum of Sq F Pr(>F) 1 94 0.24019 2 93 0.13598 1 0.10421 71.272 4.007e-13 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > > ## add season term > dfm1 <- dynlm(uk ~ 1, start = c(1975, 1), end = c(1982, 12)) > dfm2 <- dynlm(uk ~ season(uk), start = c(1975, 1), end = c(1982, 12)) > anova(dfm1, dfm2) Analysis of Variance Table Model 1: uk ~ 1 Model 2: uk ~ season(uk) Res.Df RSS Df Sum of Sq F Pr(>F) 1 95 0.32151 2 84 0.07277 11 0.24874 26.102 < 2.2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > > plot(uk) > lines(fitted(dfm0), col = 2) > lines(fitted(dfm2), col = 4) > > ## Examples 7.11/7.12 from Greene (1993) > if(require(lmtest)) { + data(USDistLag) + dfm1 <- dynlm(consumption ~ gnp + L(consumption), data = USDistLag) + dfm2 <- dynlm(consumption ~ gnp + L(gnp), data = USDistLag) + plot(USDistLag[, "consumption"]) + lines(fitted(dfm1), col = 2) + lines(fitted(dfm2), col = 4) + encomptest(dfm1, dfm2) + } Loading required package: lmtest Encompassing test Model 1: consumption ~ gnp + L(consumption) Model 2: consumption ~ gnp + L(gnp) Model E: consumption ~ gnp + L(consumption) + L(gnp) Res.Df Df F Pr(>F) M1 vs. ME 15 1 12.569 0.0029371 ** M2 vs. ME 15 1 27.093 0.0001067 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > > > > ### *