Skip to content

Instantly share code, notes, and snippets.

@anirudhjayaraman
Last active July 17, 2020 12:35
Show Gist options
  • Select an option

  • Save anirudhjayaraman/b7d65f7e0da510c69946cd714160a11b to your computer and use it in GitHub Desktop.

Select an option

Save anirudhjayaraman/b7d65f7e0da510c69946cd714160a11b to your computer and use it in GitHub Desktop.
library(xlsx)
library(forecast)
library(tseries)
library(strucchange)
## load the data from a CSV or Excel file. This example is done with an Excel sheet.
prod_df <- read.xlsx(file = 'agricultural_productivity.xls', sheetIndex = 'Sheet1', rowIndex = 8:65, colIndex = 2, header = FALSE)
colnames(prod_df) <- c('Rice')
## store rice data as time series objects
rice <- ts(prod_df$Rice, start=c(1951, 1), end=c(2008, 1), frequency=1)
# store the breakpoints
bp.rice <- breakpoints(rice ~ 1)
summary(bp.rice)
## the BIC chooses 5 breakpoints; plot the graph with breakdates and their confidence intervals
plot(bp.rice)
plot(rice)
lines(bp.rice)
## confidence intervals
ci.rice <- confint(bp.rice)
ci.rice
lines(ci.rice)
@msjo1

msjo1 commented May 29, 2020

Copy link
Copy Markdown

Hi..Please can you share your rice data

@anirudhjayaraman

Copy link
Copy Markdown
Author

@msjo1

msjo1 commented Jul 17, 2020

Copy link
Copy Markdown

Thanks for sharing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment