简体   繁体   中英

Time series forecasting using Regression Analysis in R

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM