R Under development (unstable) (2024-09-01 r87083 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 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 an HTML browser interface to help. Type 'q()' to quit R. > library("strucchange") Loading required package: zoo Attaching package: 'zoo' The following objects are masked from 'package:base': as.Date, as.Date.numeric Loading required package: sandwich > > ## Nile data > data("Nile") > > Nile.rcus <- efp(Nile ~ 1, type = "Rec-CUSUM") > Nile.ocus <- efp(Nile ~ 1, type = "OLS-CUSUM") > Nile.re <- efp(Nile ~ 1, type = "RE") > Nile.rmos <- efp(Nile ~ 1, type = "Rec-MOSUM", h = 0.5) > Nile.omos <- efp(Nile ~ 1, type = "OLS-MOSUM", h = 0.5) > Nile.me <- efp(Nile ~ 1, type = "ME", h = 0.5) > sctest(Nile.rcus) Recursive CUSUM test data: Nile.rcus S = 2.0669, p-value = 7.487e-08 > sctest(Nile.ocus) OLS-based CUSUM test data: Nile.ocus S0 = 2.9518, p-value = 5.409e-08 > sctest(Nile.ocus, alt = TRUE) OLS-based CUSUM test with alternative boundaries data: Nile.ocus S0 = 6.5741, p-value = 1e-04 > sctest(Nile.re) RE test (recursive estimates test) data: Nile.re RE = 2.9518, p-value = 5.409e-08 > sctest(Nile.re, alt = TRUE) RE test (recursive estimates test) with alternative boundaries data: Nile.re RE = 6.5741, p-value = 1e-04 > sctest(Nile.re, fun = "range") RE test (recursive estimates test) with range norm data: Nile.re RE = 2.9518, p-value = 1.831e-06 > sctest(Nile.rmos) Recursive MOSUM test data: Nile.rmos M = 5.097, p-value = 0.01 > sctest(Nile.omos) OLS-based MOSUM test data: Nile.omos M0 = 2.4237, p-value = 0.01 > sctest(Nile.omos, fun = "range") OLS-based MOSUM test with range norm data: Nile.omos M0 = 4.3433, p-value = 5.615e-05 > sctest(Nile.me) ME test (moving estimates test) data: Nile.me ME = 2.4237, p-value = 0.01 > sctest(Nile.me, fun = "range") ME test (moving estimates test) with range norm data: Nile.me ME = 4.3433, p-value = 5.615e-05 > > Nile.fs <- Fstats(Nile ~ 1) > sctest(Nile.fs, type = "supF") supF test data: Nile.fs sup.F = 75.93, p-value = 2.22e-16 > sctest(Nile.fs, type = "aveF") aveF test data: Nile.fs ave.F = 21.215, p-value < 2.2e-16 > sctest(Nile.fs, type = "expF") expF test data: Nile.fs exp.F = 33.759, p-value < 2.2e-16 > breakpoints(Nile.fs) Optimal 2-segment partition: Call: breakpoints.Fstats(obj = Nile.fs) Breakpoints at observation number: 28 Corresponding to breakdates: 1898 > > ## Seatbelt data > data("UKDriverDeaths") > seatbelt <- log10(UKDriverDeaths) > seatbelt <- cbind(seatbelt, lag(seatbelt, k = -1), lag(seatbelt, k = -12)) > colnames(seatbelt) <- c("y", "ylag1", "ylag12") > seatbelt <- window(seatbelt, start = c(1970, 1), end = c(1984,12)) > > seat.rcus <- efp(y ~ ylag1 + ylag12, data = seatbelt, type = "Rec-CUSUM") > seat.ocus <- efp(y ~ ylag1 + ylag12, data = seatbelt, type = "OLS-CUSUM") > seat.re <- efp(y ~ ylag1 + ylag12, data = seatbelt, type = "RE") > seat.rmos <- efp(y ~ ylag1 + ylag12, data = seatbelt, type = "Rec-MOSUM", h = 0.5) > seat.omos <- efp(y ~ ylag1 + ylag12, data = seatbelt, type = "OLS-MOSUM", h = 0.5) > seat.me <- efp(y ~ ylag1 + ylag12, data = seatbelt, type = "ME", h = 0.5) > sctest(seat.rcus) Recursive CUSUM test data: seat.rcus S = 1.1599, p-value = 0.008572 > sctest(seat.ocus) OLS-based CUSUM test data: seat.ocus S0 = 1.4866, p-value = 0.02407 > sctest(seat.ocus, alt = TRUE) OLS-based CUSUM test with alternative boundaries data: seat.ocus S0 = 3.4082, p-value = 0.04502 > sctest(seat.re) RE test (recursive estimates test) data: seat.re RE = 1.6311, p-value = 0.02904 > sctest(seat.re, alt = TRUE) RE test (recursive estimates test) with alternative boundaries data: seat.re RE = 4.7365, p-value = 3e-04 > sctest(seat.re, fun = "range") RE test (recursive estimates test) with range norm data: seat.re RE = 1.9303, p-value = 0.04762 > sctest(seat.rmos) Recursive MOSUM test data: seat.rmos M = 2.0539, p-value = 0.04259 > sctest(seat.omos) OLS-based MOSUM test data: seat.omos M0 = 0.91616, p-value = 0.4004 > sctest(seat.omos, fun = "range") OLS-based MOSUM test with range norm data: seat.omos M0 = 1.4949, p-value = 0.5175 > sctest(seat.me) ME test (moving estimates test) data: seat.me ME = 1.7107, p-value = 0.04712 > sctest(seat.me, fun = "range") ME test (moving estimates test) with range norm data: seat.me ME = 2.1956, p-value = 0.3007 > > seat.fs <- Fstats(y ~ ylag1 + ylag12, data = seatbelt, from = 0.1) > sctest(seat.fs, type = "supF") supF test data: seat.fs sup.F = 19.333, p-value = 0.006721 > sctest(seat.fs, type = "aveF") aveF test data: seat.fs ave.F = 7.458, p-value = 0.01461 > sctest(seat.fs, type = "expF") expF test data: seat.fs exp.F = 6.4247, p-value = 0.008093 > breakpoints(seat.fs) Optimal 2-segment partition: Call: breakpoints.Fstats(obj = seat.fs) Breakpoints at observation number: 46 Corresponding to breakdates: 1973(10) > > ## German M1 data > data("GermanM1") > LTW.model <- dm ~ dy2 + dR + dR1 + dp + m1 + y1 + R1 + season > M1.model <- dm ~ dy2 + dR + dR1 + dp + ecm.res + season > > M1.ocus <- efp(LTW.model, data = GermanM1, type = "OLS-CUSUM") > M1.re <- efp(LTW.model, data = GermanM1, type = "RE") > M1.fs <- Fstats(LTW.model, data = GermanM1, from = 0.1) > sctest(M1.ocus) OLS-based CUSUM test data: M1.ocus S0 = 0.50881, p-value = 0.958 > sctest(M1.ocus, alt = TRUE) OLS-based CUSUM test with alternative boundaries data: M1.ocus S0 = 1.6288, p-value = 0.9704 > sctest(M1.re) RE test (recursive estimates test) data: M1.re RE = 1.9821, p-value = 0.008475 > sctest(M1.re, fun = "range") RE test (recursive estimates test) with range norm data: M1.re RE = 2.2386, p-value = 0.01844 > sctest(M1.re, alt = TRUE) RE test (recursive estimates test) with alternative boundaries data: M1.re RE = 5.4937, p-value = 0.001099 > sctest(M1.fs, type = "supF") supF test data: M1.fs sup.F = 108.83, p-value = 4.441e-16 > sctest(M1.fs, type = "aveF") aveF test data: M1.fs ave.F = 35.551, p-value = 2.007e-07 > sctest(M1.fs, type = "expF") expF test data: M1.fs exp.F = 49.74, p-value < 2.2e-16 > > M1 <- historyM1 > ols.efp <- efp(M1.model, type = "OLS-CUSUM", data = M1) > newborder <- function(k) 1.5778*k/118 > ols.mefp <- mefp(ols.efp, period = 2) > ols.mefp2 <- mefp(ols.efp, border = newborder) > M1 <- GermanM1 > ols.mon <- monitor(ols.mefp) Break detected at observation # 128 > ols.mon2 <- monitor(ols.mefp2) Break detected at observation # 135 > ols.mon Monitoring with OLS-based CUSUM test Initial call: mefp.efp(obj = ols.efp, period = 2) Last call: monitor(obj = ols.mefp) Significance level : 0.05 Critical value : 2.795483 History size : 118 Last point evaluated : 140 Structural break at : 128 Parameter estimate on history : (Intercept) dy2 dR dR1 dp ecm.res -0.05025441 -0.29729418 -0.67278600 -0.99950033 -0.52786586 1.00000000 seasonQ1 seasonQ2 seasonQ3 -0.13330148 -0.01559447 -0.10906796 > ols.mon2 Monitoring with OLS-based CUSUM test Initial call: mefp.efp(obj = ols.efp, border = newborder) Last call: monitor(obj = ols.mefp2) Significance level : 0.05 Critical value : 2.795483 History size : 118 Last point evaluated : 140 Structural break at : 135 Parameter estimate on history : (Intercept) dy2 dR dR1 dp ecm.res -0.05025441 -0.29729418 -0.67278600 -0.99950033 -0.52786586 1.00000000 seasonQ1 seasonQ2 seasonQ3 -0.13330148 -0.01559447 -0.10906796 > > ## Grossarl data > data("Grossarl") > Grossarl.bp <- breakpoints(fraction ~ 1, data = Grossarl, h = 0.1) > summary(Grossarl.bp) Optimal (m+1)-segment partition: Call: breakpoints.formula(formula = fraction ~ 1, h = 0.1, data = Grossarl) Breakpoints at observation number: m = 1 127 m = 2 55 122 m = 3 55 124 180 m = 4 55 122 157 179 m = 5 54 86 122 157 179 m = 6 35 55 86 122 157 179 m = 7 35 55 80 101 122 157 179 m = 8 35 55 79 99 119 139 159 179 Corresponding to breakdates: m = 1 1826 m = 2 1754 1821 m = 3 1754 1823 1879 m = 4 1754 1821 1856 1878 m = 5 1753 1785 1821 1856 1878 m = 6 1734 1754 1785 1821 1856 1878 m = 7 1734 1754 1779 1800 1821 1856 1878 m = 8 1734 1754 1778 1798 1818 1838 1858 1878 Fit: m 0 1 2 3 4 5 6 RSS 1.1088 0.8756 0.6854 0.6587 0.6279 0.6019 0.5917 BIC -460.8402 -497.4625 -535.8459 -533.1857 -532.1789 -530.0501 -522.8510 m 7 8 RSS 0.5934 0.6084 BIC -511.7017 -496.0924 > confint(Grossarl.bp) Confidence intervals for breakpoints of optimal 3-segment partition: Call: confint.breakpointsfull(object = Grossarl.bp) Breakpoints at observation number: 2.5 % breakpoints 97.5 % 1 52 55 61 2 116 122 124 Corresponding to breakdates: 2.5 % breakpoints 97.5 % 1 1751 1754 1760 2 1815 1821 1823 > > > proc.time() user system elapsed 0.84 0.21 1.04