Can Non-linear regression be used for time series forecasting?

Hey,
Matlab has an example on analyzing a sample time series: Airline passenger data ( link ). In the end of the page, the presented code works very well in incorporating the most relevant information from the input data in constructing a non-linear regression model.
My question is can I use the created model to predict the future data? How?

Answers (1)

The short answer is yes. At this point in the example:
[b,bint,resid] = regress(logts.data, X);
They've returned a set of coefficients for the independent variables in X. When they plot the fitted data they do the following: X*b.
You can do the same for future, or out of sample data. Set up a new matrix X_f which is the dependent variables for the future times, whatever those might be; in their example it would be time and month dummies. Then, get the predicted values Y_f = X_f*b.

4 Comments

Thanks jgg for the answer. But the regression model in the line you mentioned, only takes into account the trend and seasonality. As they also explain in that page, the resid variable shows that still there are information in the residuals of this model that are not taken into consideration. In the last code snippet in the BOTTOM of that page, they incorporate this information into the regression model and get a very accurate model.
I want to be able to use that final, accurate model.
They use an anonymous function which implements the equation below:
Yfit(t) = rho*Y(t-1) + (X(t,:) - rho*X(t-1,:))*b
As you can see to forecast model value at time t, it uses actual values of Y(1:t-1) and predictor values X(1:t). But I cannot get it to work out for me, to predict new values. The YFit and Y variables are of the same size, while one would expect that YFit will have one more element.
Any help?
I'm unclear why you want to fit an autoregessive model, though. This is a modeling decision which needs to be made for your actual data. If you want to do this:
X = [dummyvar(mo(:)), logts.time];
Y = logts.data;
f = @(c,x) [Y(1); c(1)*Y(1:end-1) + (x(2:end,:)- c(1)*x(1:end-1,:))*c(2:end)];
c = nlinfit(X,Y,f,[r;b]);
This code generates, exactly as before, a coefficient vector c which you can use to predict future values. The only issue is that now you need to do it iteratively.
Y_fit = @(X,Y_l,X_l)(c(1)*Y_l + (X - rho*X_l)*b)
Create a vector of future X_values X_f with the last actuals in the first place. Then, if X_last and Y_last are the last actual data you observed, compute for each future time period:
Y_f(2) = Y_fit(X_f(2),Y_f(1),X_f(1))
And repeat the process for each time period using a loop. The only issue here is you have to "kickstart" this process by setting Y_f(1) = Y_last and X_f(1) = X_last.
Accept this answer if you think it solves your problem so other people can see it.

Sign in to comment.

Asked:

on 14 Jan 2016

Commented:

jgg
on 18 Jan 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!