# Quantile regression for Sales forecast in R

Issue: Cannot forecast sales accurately using quantile regression in R. I am using rq function from "quantreg" package which is giving me warning "Result might have Non unique solutions"

Aim: I am trying to forecast hourly sales of a store using quantile regression.

Below are the columns in my source table for forecasting.

• transaction_date : sales date (input)
• hr1 to hr24 : column with hourly sales info. (24 columns) (input)
• totala : total of 24 column hr1 to hr24 (not using currently)
• location, department, sales_type: forecasting will be done for each location, sales_type and department. (used to select data)
• f1 to f24 : columns I want to forecast for each hour (24 columns) (output)

Packages Used: forecast, quantreg, Metrics

Code: I have extracted date features from transaction_date eg. weekend, week of month and also holidays (1 if it is holiday 0 for regular days).

attach(train_data)
Y <- cbind(hr)
X <- cbind(transation_date, Years, Months, Days, WeekDay, WeekofYear, Weekend, WeekofMonth, holidays)

quantreg.all <- rq(Y ~ X, tau = seq(0.05, 0.95, by = 0.05))
prediction_train <- data.frame(predict(quantreg.all))


I have 19 models in prediction_train for each tau from 0.05 to 0.95, I select best model based on rmse value and than forecast using that tau.

rmse(actual, predicted)


transaction_date is Date type, quantreg.all is rqs class and rest are numeric.

Note: Stores are not open 24 hours, hence many hour columns will be 0 (time when store was close). Currently for most of such hours rq is predicting 0 or some negative values.

Weather does not have major impact on sales.

## migrated from stackoverflow.comAug 13 '15 at 7:26

This question came from our site for professional and enthusiast programmers.

• What is the actual problem? That you're predictions aren't very accurate? Or that you're getting the warning from rq? – scribbles Aug 12 '15 at 20:55
• @scribbles Prediction are not accurate, and I think it might be because of the warning message which says solution may be non unique. – Jainam Aug 12 '15 at 21:31

Furthermore quantile regressions will give you the value corresponding to the chosen quantile of the distribution. So, for example, regression with tau=0.25 and some specified value of X will give you y_fit that is greater than 25% of all the observations in the sample for the same X value (25% of observations will lie below y_fit). So in general you shouldn't expect the high accuracy with quantile regressions.
As for the warning, it may be not relevant to your accuracy issue at all. But changing method parameter in qr may help you get rid of the warning. For example, using method="fn" should help in the cases with a high number of observations.