Learn R Programming

swash (version 1.3.2)

plot_breakpoints: Calculating and plotting breakpoints in time series

Description

The function calculates breakpoints for time series and provides plots of the analysis results

Usage

plot_breakpoints(
  dataset, 
    formula,
    alpha = 0.05,
    line.col = "chocolate",
    ci.col = c(
      rgb(0, 0, 255, maxColorValue = 255, alpha = 0.5),
      rgb(0, 255, 0, maxColorValue = 255, alpha = 0.5),
      rgb(255, 0, 0, maxColorValue = 255, alpha = 0.5)
    ),
    legend.show = TRUE, 
    legend.pos = c(
      "topright", 
      "topright", 
      "topright", 
      "topright"
      ),
    xlab = "Time", 
    ylab = "Y", 
    ylim = NULL,
    plot.main = c(
      "Breakpoints", 
      "Segment model fits", 
      "BIC and Residual Sum of Squares", 
      "Model without breaks (one segment)"
    ),
    output.full = TRUE,
    separate_plots = FALSE,
    ...
  )

Value

data.frame with one row for each model segment with coefficients, \(R^2\), etc.

Arguments

dataset

data.frame object with (infections) time series

formula

formula object for linear regression formula

alpha

Significance level \(\alpha\) for 1-\(\alpha\)*100 confidence intervals

line.col

Line color in time series plot

ci.col

Colors for confidence intervals in 3 plots

legend.show

bool: Show legend?

legend.pos

Position of legend

xlab

Label of x axis

ylab

Label of y axis

ylim

Limits of y axis

plot.main

Titles for 4 plots

output.full

bool: All 4 plots or just one (breakpoints)?

separate_plots

bool: All 4 plots in one or separate?

...

Further arguments passed to breakpoints()

Author

Thomas Wieland

Details

The function uses the breakpoints() function from the strucchange package (Zeileis et al. 2003) to estimate breaks in time series given by the user. These breakpoints are visualized, confidence intervals and model diagnostics are calculated, and for \(M\) breakpoints, \(M+1\) models are estimated and returned.

References

Wieland T (2020) A phenomenological approach to assessing the effectiveness of COVID-19 related nonpharmaceutical interventions in Germany. Safety Science 131, 104924. tools:::Rd_expr_doi("https://doi.org/10.1016/j.ssci.2020.104924")

Zeileis A, Kleiber C, Krämer W, Hornik K (2003) Testing and dating of structural changes in practice. Computational Statistics & Data Analysis 44(1-2) 109–123. tools:::Rd_expr_doi("https://doi.org/10.1016/S0167-9473(03)00030-6")

See Also

logistic_growth, exponential_growth

Examples

Run this code
data(Infections)
# Confirmed SARS-CoV-2 cases in Germany

plot_breakpoints(
  Infections, 
  log(infections_daily) ~ day,
  output.full = TRUE
  )
# Breakpoints for time series

Run the code above in your browser using DataLab