Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@msjo1 msjo1 commented May 29, 2020

Hi..Please can you share your rice data

@msjo1

This comment has been minimized.

Copy link

@msjo1 msjo1 commented Jul 17, 2020

Thanks for sharing!

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