Skip to content

Instantly share code, notes, and snippets.

@anirudhjayaraman
Last active September 17, 2017 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anirudhjayaraman/d7af72bd31f5598413ace1428234212d to your computer and use it in GitHub Desktop.
Save anirudhjayaraman/d7af72bd31f5598413ace1428234212d to your computer and use it in GitHub Desktop.
# assuming you have a 'ts' object in R
# 1. install package 'strucchange'
# 2. Then write down this code:
library(strucchange)
# store the breakdates
bp_ts <- breakpoints(ts ~ 1)
# this will give you the break dates and their confidence intervals
summary(bp_ts)
# store the confidence intervals
ci_ts <- confint(bp_ts)
## to plot the breakpoints with confidence intervals
plot(ts)
lines(bp_ts)
lines(ci_ts)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment