[R] strucchange Graph By Week and xts error

Sparks, John j@p@rk4 @end|ng |rom u|c@edu
Thu Mar 7 00:37:58 CET 2019


Hi R Helpers,

I am doing some work at identifying change points in time series data.  A very nice example is given in the R Bloggers post

https://www.r-bloggers.com/a-look-at-strucchange-and-segmented/

The data for the aswan dam in that example is yearly.  My data is weekly.  I ran the code switching the data for the analysis to my data and it worked, but the scale of the line chart is not sensible.  I have 225 weekly observations and the x-axis of the line graph shows numbers from 0 to over 1500.  The information on the ts object is

Start=1
End=1569
Frequency=0.1428...

I can't share the data because it is proprietary.

Wanting to be a good member of the list, I attempted to put weekly increments on the Nile data so I could reproduce the x axis of the chart with the axis scale that I am seeing.  Unfortunately, in doing so I got another error that I don't understand.



library(strucchange)
library(lubridate)
library(xts)

# example from R-Blog runs fine
data(�Nile�)
plot(Nile)
bp.nile <- breakpoints(Nile ~ 1)
ci.nile <- confint(bp.nile, breaks = 1)
lines(ci.nile)

#problem comes in here
dfNile<-data.frame(Nile)
dfNile$week<-seq(ymd('2012-01-01'),ymd('2013-11-30'),by='weeks')
tsNile<-as.xts(x=dfNile[,-2],order.by=dfNile$week)

Error in xts(x.mat, order.by = order.by, frequency = frequency(x), ...) :
  formal argument "order.by" matched by multiple actual arguments


Can somebody help me to put together the ts object with weeks so that I can demonstrate the problem with the scale on the x-axis and then try to get some help with that original problem?

Much appreciated.
--John Sparks








	[[alternative HTML version deleted]]



More information about the R-help mailing list