4
$\begingroup$

I have hourly login data for a web site. Certain hours of the day for example between 09:00 and 12:00, there are heavy traffic on the site. I would like to forecast the hourly data for about one year.

I have seen the usage of forecast package for monthly data, but I need to do forecast of the hourly data so that I can create what-if scenarios for the hourly CPU utilization.

Is it possible to perform forecast on the hourly data?

My data points are as follows:

dput(head(tt,100))

structure(list(DATETIME = structure(c(1362114000, 1362117600, 
1362121200, 1362124800, 1362128400, 1362132000, 1362135600, 1362139200, 
1362142800, 1362146400, 1362150000, 1362153600, 1362157200, 1362160800, 
1362164400, 1362168000, 1362171600, 1362175200, 1362178800, 1362182400, 
1362186000, 1362189600, 1362193200, 1362196800, 1362200400, 1362204000, 
1362207600, 1362211200, 1362214800, 1362218400, 1362222000, 1362225600, 
1362229200, 1362232800, 1362236400, 1362240000, 1362243600, 1362247200, 
1362250800, 1362254400, 1362258000, 1362261600, 1362265200, 1362268800, 
1362272400, 1362276000, 1362279600, 1362283200, 1362286800, 1362290400, 
1362294000, 1362297600, 1362301200, 1362304800, 1362308400, 1362312000, 
1362315600, 1362319200, 1362322800, 1362326400, 1362330000, 1362333600, 
1362337200, 1362340800, 1362344400, 1362348000, 1362351600, 1362355200, 
1362358800, 1362362400, 1362366000, 1362369600, 1362373200, 1362376800, 
1362380400, 1362384000, 1362387600, 1362391200, 1362394800, 1362398400, 
1362402000, 1362405600, 1362409200, 1362412800, 1362416400, 1362420000, 
1362423600, 1362427200, 1362430800, 1362434400, 1362438000, 1362441600, 
1362445200, 1362448800, 1362452400, 1362456000, 1362459600, 1362463200, 
1362466800, 1362470400), class = c("POSIXct", "POSIXt"), tzone = ""), 
    LOGINS = c(432576L, 358379L, 347103L, 333591L, 271118L, 332924L, 
    522028L, 841686L, 953788L, 1084630L, 1243345L, 1327191L, 
    1257679L, 1261271L, 1093757L, 1009539L, 918686L, 817274L, 
    731382L, 657496L, 653997L, 632712L, 499769L, 434182L, 333138L, 
    252089L, 213827L, 195443L, 155659L, 167594L, 235485L, 382961L, 
    543660L, 721460L, 791414L, 790107L, 748118L, 728592L, 683574L, 
    643504L, 614126L, 571742L, 528514L, 386003L, 356637L, 332419L, 
    296185L, 272693L, 215263L, 225642L, 175703L, 120502L, 88052L, 
    80048L, 106441L, 186326L, 293553L, 413201L, 501498L, 540321L, 
    540622L, 582647L, 567774L, 555800L, 547662L, 541056L, 523127L, 
    521416L, 521093L, 511747L, 466803L, 408279L, 312245L, 229661L, 
    175773L, 152918L, 134578L, 165888L, 262662L, 432163L, 618198L, 
    790108L, 861403L, 894266L, 851507L, 847954L, 809230L, 785501L, 
    783844L, 765385L, 720353L, 695988L, 666363L, 628106L, 553925L, 
    467805L, 350987L, 242916L, 207419L, 180090L)), .Names = c("DATETIME", 
"LOGINS"), row.names = c(NA, 100L), class = "data.frame")
$\endgroup$

1 Answer 1

7
$\begingroup$

Is something like this what you're looking for?

In the example below, I've tentatively identified an AR(3) model, but I'm sure you can do a thorough analysis of the data to identify the appropriate model. I just want to get the idea across!

Note also that I used the predict() function to generate point forecasts. To create the interval forecasts I used the formula: point forecast $\pm$ 1.28 (standard error). That is, an 80% confidence interval. Change this to 1.96 for a 95% confidence interval.

To create more or fewer forecasts, change the value of n.ahead=12.

# Plot the data
plot(dataframe$LOGINS, type="l")
# Fit an AR(3) model
fit <- arima(x=dataframe$LOGINS, order=c(3,0,0))
# Get point forecasts (12 of them)
forecasts <- predict(fit, n.ahead=12)
# Concatenate LOGINS and the point forecasts (for plotting purposes)
series <- c(dataframe$LOGINS, forecasts$pred)
# Plot LOGINS & the point forecasts
plot(series, type="l")
# Add to the plot the upper 80% forecast C.I.
lines(forecasts$pred+1.28*forecasts$se)
# Add to the plot the lower 80% forecast C.I.
lines(forecasts$pred-1.28*forecasts$se)

You should get something that looks similar to this: enter image description here

Obviously, you can play around with the plot and make it look the way you want it to.

Let us know if this helps. If it doesn't, tell us why and we'll try to find a solution.

$\endgroup$
3
  • $\begingroup$ how would you format x-axis to show the date? other than, I think I am good. Thank you. $\endgroup$ May 14, 2013 at 20:05
  • $\begingroup$ Glad it helped! I'm no expert when plotting in R, but I can make two suggestions that might work. Create a ts object out of dataframe\$LOGINS and specify the start, end, and frequency arguments. Then replace the ts object in the above code wherever dataframe\$LOGINS appears. The second option would be to specify xaxt="n" in plot() and then use axis(1, at=, labels=) to add the labels to the x-axis. For examples, perhaps it would be worth visiting: statmethods.net/advgraphs/axes.html $\endgroup$ May 14, 2013 at 20:21
  • 1
    $\begingroup$ @user1471980: I believe all you need to do to plot the date is to change plot(dataframe$LOGINS, type="l") to plot(dataframe$DATETIME, dataframe$LOGINS, type="l") $\endgroup$
    – Wayne
    May 23, 2013 at 13:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.