I'm using model trees to forecast sales data. I've developed a pretty good model but I'm concerned about some of the models predictions. I'm working with R and using the M5P algo in the RWeka package.

I'm forecasting revenues so I never have negative numbers but my model predicts negative numbers. That makes me think I'm doing something incorrectly. Here is the shape of my dataenter image description here

What should I do to make sure my model doesn't predict meaningless values?

  • $\begingroup$ describe your data. what's sample size? sampling frequency? some time series graphs etc. $\endgroup$
    – Aksakal
    Oct 1, 2015 at 19:01
  • $\begingroup$ Negative numbers can be forecasted because there is no embedded logic to restrict that from happening.AUTOBOX a piece of software I wrote simply allows that unless a control file called POSITIVE.AFS exists which acts as a truncater. Similar things happen when you have a history of integers and the forecast delivered is xx.yyy . I wouldn't worry about the existence of negative forecasts but I would adjust them. If you post your data I will be glad to show you how to proceed or at least how I would proceed with the tools that I have on hand. $\endgroup$
    – IrishStat
    Oct 1, 2015 at 19:24
  • $\begingroup$ There are hourly observations. Sorry I'm not cool enough to make graphs in R yet. That said, it's pretty cyclical. It's not a sample It's 3 years worth of data which is the total dataset. $\endgroup$
    – Bob
    Oct 1, 2015 at 19:34
  • $\begingroup$ Min. 0 1st Qu. 15.5 Median 52.6 Mean 71.80738 3rd Qu. 104.5 Max. 299.86 $\endgroup$
    – Bob
    Oct 1, 2015 at 19:34
  • $\begingroup$ If it's just a matter of writing some logic so I don't get negative numbers then problem solved. I was more concerned about using an inappropriate distribution or the wrong modeling technique. For instance this summer I had to create a forecast of how much a project was going to cost. I started with a normal curve but got better results when I switched to a Poisson. That said, I don't think a Poisson would work here because we're talking about a continuous value and not integer counts. $\endgroup$
    – Bob
    Oct 1, 2015 at 19:37

1 Answer 1


One possibility for modeling continuous nonnegative data is the gamma distribution. You can include covariates by running a gamma regression, e.g., using glm(). Since you have time series, you may want to create harmonics or (Gaussian or other) dummies as predictors to model seasonalities.

Then again, your data seems to have a suspicious bump at zero. This would argue for a Tweedie distribution, which is a kind of "zero-inflated gamma distribution". You can run a "Tweedie regression" in R by using the Tweedie and the statmod packages.

I don't know whether you could model autoregressive behavior in some reasonable way. Then again, you may not even need it if you use useful regressors.

  • $\begingroup$ Mr. Kolassa, I also have one time series which is right-skewed as the amount of sales dropped significantly through time. May I ask if we could use arima models to fit this kind of cases as I get a very good result in Ljung-Box test and every thing looks ok. $\endgroup$ Dec 2, 2021 at 20:15
  • 1
    $\begingroup$ @AnoushiravanR: the overall distribution is not very important. If you have promotions, you might even have a multimodal overall distribution - but if you can model the peaks with predictors, everything is fine. So yes, ARIMA can be used to model sales that drop over time. (I am not a big fan of ARIMA in any case.) $\endgroup$ Dec 3, 2021 at 8:59
  • $\begingroup$ Thank you very much Mr. Kolassa, I appreciate your response. $\endgroup$ Dec 3, 2021 at 10:30

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.