1
$\begingroup$

I have many time series(retail data). Some with trends, some seasonal, and some with neither. With period day, week or month. I need to make forecast, for each time serie.

I'm looking for the most efficient methods for forecasting in R ? Which significant things should I know for it? Maybe someone has experience with random forest forecasting and would share with me?

Any help would be truly appreciated.

UPDATE 1: For example, one of mine time series is x:

   > dput(x)
 c(1.07328072153326, 1.07385697538101, 1.10947204968944, 1.10501567398119, 
1.08808510638298, 1.07468423942889, 1.06658878504673, 1.10157194679565, 
1.10297619047619, 1.09510682288077, 1.07372549019608, 1.08457943925234, 
1.09101316542645, 1.10577472841624, 1.08926553672316, 1.0929326655537, 
1.08484848484848, 1.09699769053118, 1.10987124463519, 1.08726673984632, 
1.09157959434542, 1.10070384407147, 1.08625486922649, 1.11432506887052, 
1.0828313253012, 1.08040626322471, 1.07157157157157, 1.08369098712446, 
1.08045977011494, 1.10748560460653, 1.11616161616162, 1.08371040723982, 
1.10213414634146, 1.06835306781485, 1.07926829268293, 1.08721886999451, 
1.10216718266254, 1.1241610738255, 1.08231707317073, 1.07698961937716, 
1.08569953536396, 1.09771181199753, 1.07181984175289, 1.07288828337875, 
1.07820419985518, 1.07210031347962, 1.07450628366248, 1.06662870159453, 
1.07235494880546, 1.0979020979021, 1.08494690818239, 1.06716417910448, 
1.08305369127517, 1.08023307933662, 1.07635746606335, 1.07701786814541, 
1.08310249307479, 1.0768253968254, 1.096, 1.06787687450671, 1.07353535353535, 
1.11226993865031, 1.07641196013289, 1.08066298342541, 1.09431605246721, 
1.06678539626002, 1.06646525679758, 1.09977728285078, 1.07646420824295, 
1.0973341599504, 1.0906432748538, 1.09831824062096, 1.09302325581395, 
1.08199121522694, 1.073753605274, 1.0616937745373, 1.07997481108312, 
1.08239202657807, 1.08798283261803, 1.07748776508972, 1.0552611657835, 
1.0817746846455, 1.08978032473734, 1.08414985590778, 1.08205756276791, 
1.11405835543767, 1.11866969009826, 1.07441154138193, 1.09642703400775, 
1.07393209200438, 1.08049535603715, 1.09371428571429, 1.09732824427481, 
1.10526315789474, 1.11575091575092, 1.08680994521702, 1.10028929604629, 
1.09176340519624, 1.07464266807835, 1.10190664036818, 1.08295281582953, 
1.08928571428571, 1.09341998375305, 1.0958605664488, 1.07885714285714, 
1.07466814159292, 1.09463722397476, 1.07281903388609, 1.0812324929972, 
1.08226102941176, 1.07101616628176, 1.08390410958904, 1.08528528528529, 
1.09333333333333, 1.08073929961089, 1.09380234505863, 1.08012968967114, 
1.07717391304348, 1.07066508313539, 1.06838106370544, 1.07199032062916, 
1.08235294117647, 1.08157524613221, 1.11082474226804, 1.08620689655172, 
1.08299477655252, 1.10016420361248, 1.10140093395597, 1.08766485647789, 
1.10094850948509, 1.13925191527715, 1.11293859649123, 1.12204234122042, 
1.10141364474493, 1.11103495544894, 1.09365558912387, 1.10044313146233, 
1.11116279069767, 1.11053240740741, 1.09810671256454, 1.09899823217443, 
1.10986101919259, 1.09649805447471, 1.08765778401122, 1.09922928709056, 
1.07868303571429, 1.07439104674128, 1.08457374830852, 1.09739714525609, 
1.0873440285205, 1.07574536663981, 1.10498812351544, 1.11056105610561, 
1.09443402126329, 1.09200240529164, 1.1076573161486, 1.10090237899918, 
1.09986225895317, 1.10569105691057, 1.09090909090909, 1.10409356725146, 
1.107, 1.15349143610013, 1.08992562542258, 1.09016393442623, 
1.08549783549784, 1.07950780880265, 1.08859223300971, 1.06225680933852, 
1.08606557377049, 1.07929176289453, 1.09641873278237, 1.07554585152838, 
1.05761316872428, 1.08054085831864, 1.09245172615565, 1.09028727770178, 
1.06859756097561, 1.08278388278388, 1.06620808254514, 1.07001522070015, 
1.06319485078994, 1.06764705882353, 1.08654416123296, 1.09310113864702, 
1.06369008535785, 1.13811922753988, 1.12487100103199, 1.14294330518697, 
1.15353181552831, 1.14426229508197, 1.1380042462845, 1.16727806309611, 
1.09280544912729, 1.10660426417057, 1.13093858632677, 1.12244897959184, 
1.09134045077106, 1.10821382007823, 1.09921875, 1.12583967756382, 
1.0998268897865, 1.10657894736842, 1.12752114508783, 1.08413001912046, 
1.14484272128749, 1.0859167404783, 1.09041501976285, 1.0887537993921, 
1.05695364238411, 1.04765146358067, 1.04174820613177, 1.05854800936768, 
1.04042904290429, 1.07479752262982, 1.07179197286603, 1.05997624703088, 
1.06460369163952, 1.07920193470375, 1.081811541271, 1.08351810790835, 
1.0703933747412, 1.07135523613963, 1.0532319391635, 1.05964730290456, 
1.07206703910615, 1.07498383968972, 1.05938566552901, 1.08185840707965, 
1.06121372031662, 1.05117647058824, 1.0734494015234, 1.05576208178439, 
1.08180628272251, 1.06072555205047, 1.09534671532847, 1.08269794721408, 
1.0863453815261, 1.07660577489688, 1.11460957178841, 1.09818731117825, 
1.06873428331936, 1.08247925817472, 1.06818181818182, 1.09494725152693, 
1.11903160726295, 1.10917361637604, 1.09464701318852, 1.10445468509985, 
1.08333333333333, 1.06683804627249, 1.06380575945793, 1.07498766650222, 
1.07160253287871, 1.07565588773642, 1.05174927113703, 1.07279344858963, 
1.06560283687943, 1.06727037516171, 1.05085682697623, 1.06547285954113, 
1.08014705882353, 1.0575296108291, 1.05748725081131, 1.04852071005917, 
1.05421686746988, 1.05314846909301, 1.0538885486834, 1.04618937644342, 
1.04105344694036, 1.06053604436229, 1.06058788242352, 1.04755700325733, 
1.04994511525796, 1.05405405405405, 1.06622516556291, 1.07163323782235, 
1.07538994800693, 1.06018957345972, 1.07800751879699, 1.07815198618307, 
1.07247665629169, 1.07490217998882, 1.06998939554613, 1.05968331303289, 
1.05139565795304, 1.07414104882459, 1.09087423312883, 1.06742556917688, 
1.06096361848574, 1.07464929859719, 1.09754281459419, 1.10085400569337, 
1.08974358974359, 1.09106168694922, 1.09333865177503, 1.08897569444444, 
1.07627737226277, 1.14392723381487, 1.06422018348624, 1.07022471910112, 
1.07848837209302, 1.06617647058824, 1.0828331332533, 1.08257858284497, 
1.07761904761905, 1.06547619047619, 1.07017543859649, 1.06287069988138, 
1.09431751611013, 1.09341500765697, 1.06916019760056, 1.06135831381733, 
1.06491326245104, 1.06208955223881, 1.06825232678387, 1.06939409632315, 
1.05837912087912)

  x<-ts(x, frequency=7)

When I try to:

  plot(forecast(ets(x),h=60))
  plot(forecast(x,h=60))

plot

I get the same results. Maybe someone could explain, why exponential smoothing in this case makes no difference?

Also I have tryed to use

 > plot(forecast(auto.arima(x),h=60))

 Warning message:
In auto.arima(x) :
  Unable to fit final model using maximum likelihood. AIC value approximated
$\endgroup$
  • $\begingroup$ There are many threads here on forecasting that can help you. Have you looked at any of them? $\endgroup$ – Nick Cox Mar 10 '14 at 10:05
  • $\begingroup$ Hi, Nick, I have updated question $\endgroup$ – Jurgita Mar 10 '14 at 10:08
  • $\begingroup$ Please replace your first block of code with the output of dput(x). $\endgroup$ – Zach Mar 10 '14 at 23:26
  • $\begingroup$ @Zach, I've replaced, thank you for suggestion and idea of function dput() usage $\endgroup$ – Jurgita Mar 12 '14 at 8:14
  • $\begingroup$ Thanks Marta! That makes it easier for people to load your dataset. You can also upload images directly to cross-validated, which is preferable to hosting screenshots on external sites. $\endgroup$ – Zach Mar 12 '14 at 12:40
6
$\begingroup$

There is NO such a thing as "most efficient methods for forecasting in R". You as a forecaster need to figure it out which model is good for the question you are answering. First of all, what is vek2? Let's first use the auto.arima in the package forecast:

> x<-ts(x, frequency=7)
> y=auto.arima(x)
> plot(forecast(y,h=60))
> lines(fitted(y), col="blue")

enter image description here

The model fits reasonably well the data. Note that we are seeing the seanoality parameter that has been estimated by auto.arima. Don't forget to double check the residual and model adequacy before using it. Now lets try ets as well.

> fit <- ets(x)
> plot(forecast(fit,h=60))
> lines(fitted(fit), col="red")

enter image description here

This model fits well too. If all the assumptions are hold, then you need to compare these two models.

$\endgroup$
  • $\begingroup$ thank you a lot for the such good answer. Maybe could you explain, what do you mean after: " Don't forget to double check the residual and model adequancy before using" it. $\endgroup$ – Jurgita Mar 10 '14 at 21:47
  • $\begingroup$ After fitting any model, you need to check the assumptions of that model to see if they are correct or not. For example, when modeling time series data, you look the the residuals $e_t=y_t-\hat{y_t}$. They should be uncorrelated, normally distributed, with constant mean and variance. $\endgroup$ – Stat Mar 11 '14 at 18:29
  • 2
    $\begingroup$ The reason the first plot looks like a bad fit is that you plot the fitted values against the wrong time index. Use lines(fitted(fit), col='red') in every case and the results will be corrected. $\endgroup$ – Rob Hyndman Apr 2 '14 at 20:44
  • $\begingroup$ Further, the data are clearly seasonal and you need a seasonal model. $\endgroup$ – Rob Hyndman Apr 2 '14 at 20:46
  • $\begingroup$ Dear Prof. @RobHyndman, thanks a lot for correcting me. I have updated the codes and graphs as well. $\endgroup$ – Stat Apr 4 '14 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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