0

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');
Carl Witthoft
  • 20,573
  • 9
  • 43
  • 73
  • ok, but consider that `r` tag is for `R` programming language, not R^2 ! :) – Luca Braglia Apr 24 '14 at 17:36
  • 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 Apr 24 '14 at 17:55
  • 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 Apr 24 '14 at 19:50

1 Answers1

0

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.

  • 1
    Try not to simply include a link as an answer. Post the pertinent sections of the document as your answer and include the link. – Chris Barlow May 08 '14 at 21:08