Hi. I would like to ask You for help: I am new in R and i use R for forecasting, i have problem. I am trying to build daily time series: My data looks like this: Date | quantity ... 2012-11-01 | 142 2012-11-02 | 156 2012-11-05 | 151 2012-11-06 | 121 2012-11-07 | 118 2012-11-08 | 119 2012-11-11 | 160 ... My goal in general is to build time series, and to find "7-day" patterns, decompose data and forecast. I dont know how tu use dates to build daily time series (to convert that dates, that would be good for time series functions), notice that there is missing data on certain days (like weekends, or days when warehouse was closed, so there was no releases) so I cant just use rep function to build replacement for dates like 1-5, start from... How would You do this? Sorry for my english, if there is something more to explain, just tell me. -- View this message in context: http://r.789695.n4.nabble.com/Daily-Time-Series-patterns-tp4651569.html Sent from the R help mailing list archive at Nabble.com.
Hi Arun, thx for Your reply. thats interesting, but its not what I mean. I know that there is some patterns in data, example: the highest value of the sale is on Monday, and the smallest on Wednesday and so on, there might be trend also I am trying to build forecasting model that will include patterns like that, for example forecast to next 5 days. So i think I can say that is weekly sesonality, i believe the metod to make correct model is to decompose time series like there. http://otexts.com/fppfigs/elecequip_stl.png <http://otexts.com/fppfigs/elecequip_stl.png> Do You think I am right? In any case, I have big problem to do this in R. -- View this message in context: http://r.789695.n4.nabble.com/Daily-Time-Series-patterns-tp4651569p4651591.html Sent from the R help mailing list archive at Nabble.com.
HI, I guess you can check library(forecast). You could also use ?stl(), though not sure whether this will help you in this case. For e.g. set.seed(5) quantity<-sample(c(120:220,NA),699,replace=TRUE) Date=seq(as.Date("2011-01-01"),len=699,by="1 day") dat3<-data.frame(Date=Date,quantity=quantity) library(zoo) ?z <- zooreg(dat3[,2], frequency = 7) ?plot(stl(na.approx(z),"per")) A.K. ----- Original Message ----- From: mekbatub <mekbatub at gmail.com> To: r-help at r-project.org Cc: Sent: Saturday, December 1, 2012 8:00 PM Subject: Re: [R] Daily Time Series, patterns. Hi Arun, thx for Your reply. thats interesting, but its not what I mean. I know that there is some patterns in data, example: the highest value of the sale is on Monday, and the smallest on Wednesday and so on, there might be trend also I am trying to build forecasting model that will include patterns like that, for example forecast to next 5 days. So i think I can say that is weekly sesonality, i believe the metod to make correct model is to decompose time series like there. http://otexts.com/fppfigs/elecequip_stl.png <http://otexts.com/fppfigs/elecequip_stl.png>? Do You think I am right? In any case, I have big problem to do this in R. -- View this message in context: http://r.789695.n4.nabble.com/Daily-Time-Series-patterns-tp4651569p4651591.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help at r-project.org mailing list 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.
Hi Arun, thanks again, I think we are close. The way You gave me looks good, but I sill have one problem, look at this: Lets say, we have data like this:>head(dat3)Date quantity 2012-03-05 65.16 2012-03-06 70.67 2012-03-08 63.66 2012-03-09 70.05 2012-03-12 61.59 2012-03-13 58.98 Then we have:>z <- zooreg(dat3[,2], frequency = 5) >z1(1) 1(2) 1(3) 1(4) 1(5) 2(1) 65.16 70.67 63.66 70.05 61.59 58.98 This is for dates: 1(1) 1(2) 1(3) 1(4) 1(5) 2(1) 2012-03-05 2012-03-06 2012-03-08 2012-03-09 2012-03-12 2012-03-13 Since there was no releases in 2012-03-07 (warehouse was closed) We should have: 1(1) 1(2) *1(4) 1(5) 1(1) 2(2) * 65.16 70.67 63.66 70.05 61.59 58.98 So I can?t in that case use ?frequency=5?. I am trying to figure out how to assign correctly number of the week day to quantity. I am wondering if my way of thinking is correct, maybe I should fill out those missing values like You suggest me last time, but the problem is there are not missing values really, for ex. if the warehouse was closed, there was not supposed to be releases that day so there is nothing to fill out really. I am wondering is it at all possible to do this in R like I am trying to do ? without data continuity. What You think about that? -- View this message in context: http://r.789695.n4.nabble.com/Daily-Time-Series-patterns-tp4651569p4651836.html Sent from the R help mailing list archive at Nabble.com.
Hi, In addition, you can use ?dayOfWeek() from library(timeDate) set.seed(5) quantity<-sample(c(120:220,NA),699,replace=TRUE) Date=seq(as.Date("2011-01-01"),len=699,by="1 day") dat3<-data.frame(Date=Date,quantity=quantity) ?nrow(dat3) #[1] 699 library(timeDate) dat3$tSeq<-timeSequence(dat3$Date[1],dat3$Date[699]) dat4<-dat3[isWeekday(dat3$tSeq),] ?dat4$DayWeek<-dayOfWeek(dat4$tSeq) ?head(dat4) #???????? Date quantity?????? tSeq DayWeek #3? 2011-01-03????? 213 2011-01-03???? Mon #4? 2011-01-04????? 149 2011-01-04???? Tue #5? 2011-01-05????? 130 2011-01-05???? Wed #6? 2011-01-06????? 191 2011-01-06???? Thu #7? 2011-01-07????? 173 2011-01-07???? Fri #10 2011-01-10????? 131 2011-01-10???? Mon library(zoo) z<-zooreg(dat4[,2],frequency=5) plot(stl(na.approx(z),"per"))? A.K. ----- Original Message ----- From: mekbatub <mekbatub at gmail.com> To: r-help at r-project.org Cc: Sent: Monday, December 3, 2012 8:14 AM Subject: Re: [R] Daily Time Series, patterns. Hi Arun, thanks again, I think we are close. The way You gave me looks good, but I sill have one problem, look at this: Lets say, we have data like this:>head(dat3)? ? ? Date? ? ? quantity 2012-03-05 65.16 2012-03-06 70.67 2012-03-08 63.66 2012-03-09 70.05 2012-03-12 61.59 2012-03-13 58.98 Then we have:>z <- zooreg(dat3[,2], frequency = 5) >z1(1)? ? 1(2)? ? 1(3)? ? 1(4)? ? 1(5)? ? 2(1)? ? 65.16? 70.67? 63.66? 70.05? 61.59? 58.98 This is for dates: 1(1)? ? ? ? ? ? ? 1(2)? ? ? ? ? ? ? ? 1(3)? ? ? ? ? ? ? 1(4)? ? ? ? ? ? 1(5)? ? ? ? ? ? ? ? 2(1)? ? 2012-03-05 2012-03-06 2012-03-08 2012-03-09 2012-03-12 2012-03-13 Since there was no releases in 2012-03-07 (warehouse was closed) We should have: 1(1)? ? 1(2)? ? *1(4)? ? 1(5)? ? 1(1)? ? 2(2) *? ? 65.16? 70.67? 63.66? 70.05? 61.59? 58.98 So I can?t in that case use ?frequency=5?. I am trying to figure out how to assign correctly number of the week day to quantity. I am wondering if my way of thinking is correct, maybe I should fill out those missing values like You suggest me last time, but the problem is there are not missing values really, for ex. if the warehouse was closed, there was not supposed to be releases that day so there is nothing to fill out really. I am wondering is it at all possible to do this in R like I am trying to do ? without data continuity. What You think about that? -- View this message in context: http://r.789695.n4.nabble.com/Daily-Time-Series-patterns-tp4651569p4651836.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help at r-project.org mailing list 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.