1

I am reading the online textbook "Forecasting: Principles and Practice Textbook by George Athanasopoulos and Rob J. Hyndman" which has examples in R code.

A section on calendar adjustments explaisn that it is often useful to "look at average daily production instead of average monthly production, we effectively remove the variation due to the different month lengths. Simpler patterns are usually easier to model and lead to more accurate forecasts.

This is the example data sets with accompanying plots:

monthly -> daily

I don't understand the second line of the given example code:

monthdays <- rep(c(31,28,31,30,31,30,31,31,30,31,30,31),14)
monthdays[26 + (4*12)*(0:2)] <- 29
par(mfrow=c(2,1))
plot(milk, main="Monthly milk production per cow",
ylab="Pounds",xlab="Years")
plot(milk/monthdays, main="Average milk production per cow per day", 
ylab="Pounds", xlab="Years")

I understand that the first line creates a vector of the # of days in each month and repeats it 14 times because the data set is 14 years. But I have no idea what the second line is doing and where those numbers and calculations are coming from?

Jake Yu
  • 11
  • 1
  • 1
    2nd month will have 29 days every 4 years. The second line is correcting for this based on the date of begining of measurement. – mt1022 Oct 09 '16 at 13:36

0 Answers0