0
votes

I am modeling a time-series data set (x and y) with multiple methods (cubic, 4th-degree polynomial, and exponential).

Is there a way to program matlab such that it selects the model with the maximum R-squared value, and then uses that model to predict a future outcome? I understand this can be done manually with the curve fitting toolbox and looking at the results, but even then I think I would still need to write the equation out and solve for the value of interest manually.

I would like to automate the process a bit more via code to select the optimal model and use it to predict future results. Below is the main part of my code. Any help would be appreciated.

[f3, gof] = fit(x,y,'poly3','Normalize','on');
plot(f3,x,y);
[f4, gof] = fit(x,y,'poly4','Normalize','on');
[fexp, gof] = fit(x,y,'exp1');
1
ok, but consider that r tag is for R programming language, not R^2 ! :) - Luca Braglia
If you only have a few candidate models, write a wrapper function which runs all the models and tells you which one generated the best R^2 . If you have money, you might want to buy Eureqa, which does this sort of game to the N-th degree. - Carl Witthoft
I am not familiar with wrapper functions but I will look into those. Also Eureqa is absurdly expensive for the purposes of my analysis. Ha. Thank you, though. - statisticality1

1 Answers

0
votes

See math on p12 of this working paper. You can download the PDF file from the Web site: http://www.nber.org/papers/w5027 The authors also point at some older literature.