[R] strucchange Graph By Week and xts error

Jim Lemon drj|m|emon @end|ng |rom gm@||@com
Thu Mar 7 01:01:48 CET 2019


Hi John,
You seem to have 1569 days of data, so perhaps you can get around your
axis problem like this:

plot(Nile,xaxt="n",xlab="Week")
...
axis(1,at=seq(0,200,50),labels=seq(0,200,50)*7)
(untested)

Jim

On Thu, Mar 7, 2019 at 10:46 AM Sparks, John <jspark4 using uic.edu> wrote:
>
> 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]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list