1 2> library("strucchange") 3Loading required package: zoo 4 5Attaching package: 'zoo' 6 7The following objects are masked from 'package:base': 8 9 as.Date, as.Date.numeric 10 11Loading required package: sandwich 12 13> data("USIncExp") 14 15> plot(USIncExp, plot.type = "single", col = 1:2, ylab = "billion US$") 16 17> legend(1960, max(USIncExp), c("income", "expenditures"), 18+ lty = c(1, 1), col = 1:2, bty = "n") 19 20> library("strucchange") 21 22> data("USIncExp") 23 24> USIncExp2 <- window(USIncExp, start = c(1985, 12)) 25 26> coint.res <- residuals(lm(expenditure ~ income, data = USIncExp2)) 27 28> coint.res <- lag(ts(coint.res, start = c(1985, 12), 29+ freq = 12), k = -1) 30 31> USIncExp2 <- cbind(USIncExp2, diff(USIncExp2), coint.res) 32 33> USIncExp2 <- window(USIncExp2, start = c(1986, 1), 34+ end = c(2001, 2)) 35 36> colnames(USIncExp2) <- c("income", "expenditure", 37+ "diff.income", "diff.expenditure", "coint.res") 38 39> ecm.model <- diff.expenditure ~ coint.res + diff.income 40 41> plot(USIncExp2[, 3:5], main = "") 42 43> ocus <- efp(ecm.model, type = "OLS-CUSUM", data = USIncExp2) 44 45> me <- efp(ecm.model, type = "ME", data = USIncExp2, 46+ h = 0.2) 47 48> bound.ocus <- boundary(ocus, alpha = 0.05) 49 50> plot(ocus) 51 52> plot(me, functional = NULL) 53 54> sctest(ecm.model, type = "OLS-CUSUM", data = USIncExp2) 55 56 OLS-based CUSUM test 57 58data: ecm.model 59S0 = 1.5511, p-value = 0.01626 60 61 62> fs <- Fstats(ecm.model, from = c(1990, 1), to = c(1999, 63+ 6), data = USIncExp2) 64 65> plot(fs) 66 67> sctest(ecm.model, type = "expF", from = 49, to = 162, 68+ data = USIncExp2) 69 70 expF test 71 72data: ecm.model 73exp.F = 8.9955, p-value = 0.001311 74 75 76> USIncExp3 <- window(USIncExp2, start = c(1986, 1), 77+ end = c(1989, 12)) 78 79> me.mefp <- mefp(ecm.model, type = "ME", data = USIncExp3, 80+ alpha = 0.05) 81 82> USIncExp3 <- window(USIncExp2, start = c(1986, 1), 83+ end = c(1990, 12)) 84 85> me.mefp <- monitor(me.mefp) 86 87> USIncExp3 <- window(USIncExp2, start = c(1986, 1)) 88 89> me.mefp <- monitor(me.mefp) 90Break detected at observation # 72 91 92> me.mefp 93Monitoring with ME test (moving estimates test) 94 95Initial call: 96 mefp.formula(formula = ecm.model, type = "ME", data = USIncExp3, alpha = 0.05) 97 98Last call: 99 monitor(obj = me.mefp) 100 101Significance level : 0.05 102Critical value : 3.109524 103History size : 48 104Last point evaluated : 182 105Structural break at : 72 106 107Parameter estimate on history : 108(Intercept) coint.res diff.income 109 18.9299679 -0.3893141 0.3156597 110Last parameter estimate : 111(Intercept) coint.res diff.income 11227.94869106 0.00983451 0.13314662 113 114> plot(me.mefp) 115 116> USIncExp3 <- window(USIncExp2, start = c(1986, 1), 117+ end = c(1989, 12)) 118 119> me.efp <- efp(ecm.model, type = "ME", data = USIncExp3, 120+ h = 0.5) 121 122> me.mefp <- mefp(me.efp, alpha = 0.05) 123 124> USIncExp3 <- window(USIncExp2, start = c(1986, 1)) 125 126> me.mefp <- monitor(me.mefp) 127Break detected at observation # 70 128 129> plot(me.mefp) 130 131 *** Run successfully completed *** 132> proc.time() 133 user system elapsed 134 1.50 0.06 1.56 135