Reputation: 37
As part of my work, I need to evaluate different forecasting models on the time series data using R and pick the one with lowest error. For this, I want to know how to use the Linear Regression(LR) method to forecast on the time series. In the time series, we normally have only 1 column with continuous data but to use LR, we need at least 2 variables, like y=Beta0+Beta1*x. I have the sales figure monthly(x) but how to get the y variable to use LR.
Upvotes: 1
Views: 1034
Reputation: 434
Praveen, I don't think we are focusing the problem right here.I understand you are trying to forecast sales in the future based on past data.
Let's suppose you have defined a data.frame
sales
, with revenue
and time_period
data.
At this moment, I would personally do some data exploration to check there might be some kind of correlation between the variables.
xyplot(revenue ~ time_period, data = sales)
Then, fit the model
sales_model = lm(revenue ~ time_period, data = sales)
Now the model is built and the coefficients you are looking for should be calculated. To get them, just run summary(sales_model)
The first column of the coefficients matrix should give you both the intercept and the slope of your model, which are the betas you were looking for.
Upvotes: 0