I'm curious about repeatable procedures that can be used to discover the functional form of the function y = f(A, B, C) + error_term where my only input is a set of observations (y, A, B and C). Please note that the functional form of fis unknown.

Consider the following dataset:

==  ==  ==  ==  ==  ==
98  11  66  84  67  10500
71  44  48  12  47  7250
54  28  90  73  95  5463
34  95  15  45  75  2581
56  37  0   79  43  3221
68  79  1   65  9   4721
53  2   90  10  18  3095
38  75  41  97  40  4558
29  99  46  28  96  5336
22  63  27  43  4   2196
4   5   89  78  39  492
10  28  39  59  64  1178
11  59  56  25  5   3418
10  4   79  98  24  431
86  36  84  14  67  10526
80  46  29  96  7   7793
67  71  12  43  3   5411
14  63  2   9   52  368
99  62  56  81  26  13334
56  4   72  65  33  3495
51  40  62  11  52  5178
29  77  80  2   54  7001
42  32  4   17  72  1926
44  45  30  25  5   3360
6   3   65  16  87  288

In this example, assume that we know that FF = f(AA, BB, CC, DD, EE) + error term, but we're not sure about the functional form of f(...).

What procedure/what methods would you use to arrive at finding the functional form of f(...)?

(Bonus point: What is your best guess at the definiton of f given the data above? :-) And yes, there is a "correct" answer that will yield an R^2 in excess of 0.99.)

  • 1
    $\begingroup$ @OP: IrishStat's comments below remind me that without some knowledge of how your independent variables are related to each other and/or the dependent variable, in theory, leaves you "up the creek without a paddle". For example, if FF was "combustion yield" and AA was amount of fuel, and BB was the amount of oxygen, you would look for an interacting term of AA and BB $\endgroup$
    – Pete
    May 6, 2011 at 1:47
  • $\begingroup$ @Pete: Interacting terms are absolutely possible. I hope I didn't rule out that by framing my question incorrectly. $\endgroup$
    – knorv
    May 6, 2011 at 16:39
  • 2
    $\begingroup$ @Pete: This is no problem (and I would even call it realistic in a real life setting), just see my answer below. $\endgroup$
    – vonjd
    May 9, 2011 at 19:02
  • 3
    $\begingroup$ Pete: Out of the infinite number of functions that will fit the data with R^2 >= 0.99 one would like to find the one with the best performance to complexity ratio (and out of sample fit of course). Sorry for not writing that explicity, I thought that was obvious :-) $\endgroup$
    – knorv
    May 10, 2011 at 8:12
  • 1
    $\begingroup$ Also, now that the question is reasonably well answered, it would be cool to know if the data was generated by one of the suggested functions below. $\endgroup$
    – naught101
    Oct 5, 2013 at 10:17

6 Answers 6


To find the best fitting functional form (so called free-form or symbolic regression) for the data try this tool - to all of my knowledge this is the best one available (at least I am very excited about it)...and its free :-)


EDIT: I gave it a shot with Eureqa and I would go for:

$$AA + AA^2 + BB*CC$$ with $R^2=0.99988$

I would call it a perfect fit (Eureqa gives other, better fitting solutions, but these are also a little bit more complicated. Eureqa favours this one, so I chose this one) - and Eureqa did everything for me in about a few seconds on a normal laptop ;-)

  • 6
    $\begingroup$ just for reference, Eureqa's using Genetic Programming to find solutions to the symbolic regression problem. $\endgroup$ May 8, 2011 at 7:47
  • 10
    $\begingroup$ +1 Impressive performance for a mindless, automatic tool! $\endgroup$
    – whuber
    May 9, 2011 at 22:08
  • 1
    $\begingroup$ @vonjd, the link now says "free 30 day trial". Would you know of a free alternative ? $\endgroup$
    – denis
    Jan 24, 2014 at 12:27
  • 3
    $\begingroup$ @denis: You can try this R package: cran.r-project.org/web/packages/rgp/index.html - but it is not as sophisticated as the abovementioned software (not yet?) $\endgroup$
    – vonjd
    Jan 24, 2014 at 14:09
  • 3
    $\begingroup$ Eureqa is still free for academic / nonprofit organizations $\endgroup$
    – Inverse
    Mar 27, 2015 at 19:20

$R^2$ alone is not a good measure of goodness of fit, but let's not get into that here except to observe that parsimony is valued in modeling.

To that end, note that standard techniques of exploratory data analysis (EDA) and regression (but not stepwise or other automated procedures) suggest using a linear model in the form

$$\sqrt{f} = a + b*c + a*b*c + \text{constant} + \text{error}$$

Using OLS, this does achieve an $R^2$ above 0.99. Heartened by such a result, one is tempted to square both sides and regress $f$ on $a$, $b*c$, $a*b*c$, and all their squares and products. This immediately produces a model

$$f = a^2 + b*c + \text{constant} + \text{error}$$

with a root MSE of under 34 and an adjusted $R^2$ of 0.9999. The estimated coefficients of 1.0112 and 0.988 suggest the data may be artificially generated with the formula

$$f = a^2 + b*c + 50$$

plus a little normally distributed error of SD approximately equal to 50.


In response to @knorv's hints, I continued the analysis. To do so I used the techniques that had been successful so far, beginning with inspecting scatterplot matrices of the residuals against the original variables. Sure enough, there was a clear indication of correlation between $a$ and the residuals (even though OLS regression of $f$ against $a$, $a^2$, and $b*c$ did not indicate $a$ was "significant"). Continuing in this vein I explored all correlations between the quadratic terms $a^2, \ldots, e^2, a*b, a*c, \ldots, d*e$ and the new residuals and found a tiny but highly significant relationship with $b^2$. "Highly significant" means that all this snooping involved looking at some 20 different variables, so my criterion for significance on this fishing expedition was approximately 0.05/20 = 0.0025: anything less stringent could easily be an artifact of the probing for fits.

This has something of the flavor of a physical model in that we expect, and therefore search for, relationships with "interesting" and "simple" coefficients. So, for instance, seeing that the estimated coefficient of $b^2$ was -0.0092 (between -0.005 and -0.013 with 95% confidence), I elected to use -1/100 for it. If this were some other dataset, such as observations of a social or political system, I would make no such changes but just use the OLS estimates as-is.

Anyway, an improved fit is given by

$$f = a + a^2 + b*c - b^2/100 + 30.5 + \text{error}$$

with mean residual $0$, standard deviation 26.8, all residuals between -50 and +43, and no evidence of non-normality (although with such a small dataset the errors could even be uniformly distributed and one couldn't really tell the difference). The reduction in residual standard deviation from around 50 to around 25 would often be expressed as "explaining 75% of the residual variance."

I make no claim that this is the formula used to generate the data. The residuals are large enough to allow some fairly large changes in a few of the coefficients. For instance, 95% CIs for the coefficients of $a$, $b^2$, and the constant are [-0.4, 2.7], [-0.013, -0.003], and [-7, 61] respectively. The point is that if any random error has actually been introduced in the data-generation procedure (and that is true of all real-world data), that would preclude definitive identification of the coefficients (and even of all the variables that might be involved). That's not a limitation of statistical methods: it's just a mathematical fact.

BTW, using robust regression I can fit the model

$$f = 1.0103 a^2 + 0.99493 b*c - 0.007 b^2 + 46.78 + \text{error}$$

with residual SD of 27.4 and all residuals between -51 and +47: essentially as good as the previous fit but with one less variable. It is more parsimonious in that sense, but less parsimonious in the sense that I haven't rounded the coefficients to "nice" values. Nevertheless, this is the form I would usually favor in a regression analysis absent any rigorous theories about what kinds of values the coefficients ought to have and which variables ought to be included.

It is likely that additional strong relationships are lurking here, but they would have to be fairly complicated. Incidentally, taking data whose original SD is 3410 and reducing their variation to residuals with an SD of 27 is a 99.99384% reduction in variance (the $R^2$ of this new fit). One would continue looking for additional effects only if the residual SD is too large for the intended purpose. In the absence of any purpose besides second-guessing the OP, it's time to stop.

  • 1
    $\begingroup$ Good work! So far this seems like the best answer. $\endgroup$
    – Zach
    May 9, 2011 at 1:06
  • $\begingroup$ @whuber: Nice work -- you're getting close! :-) It is true that the data was artifically generated with a formula plus an error term. But the formula is not exactly the one you've found - you're missing out on a couple of terms. But you're close and you're currently in the lead :-) $\endgroup$
    – knorv
    May 9, 2011 at 9:46
  • 4
    $\begingroup$ @whuber I already gave my +1, but I'd like to add that this is very instructive to read one's approach to such a problem. You're worth the bounty in any manner whatsoever. $\endgroup$
    – chl
    May 9, 2011 at 20:52
  • 1
    $\begingroup$ @bill I did try it, early on. I trust my explanation provides room for your proposal as well as the two I have included. There's more than one right answer. I continued the analysis and included those extra terms because it was clear there are patterns in the residuals and that accounting for them materially reduces the residual variance. (I will confess that I have spent very little time and attention on this, though: the total time for the initial analysis, including writing the answer, was 17 minutes. More time often translates to more insight...) $\endgroup$
    – whuber
    May 13, 2011 at 17:47
  • 1
    $\begingroup$ @naught It would be interesting to begin with such a long formula and apply an Elastic Net (or some similar variable-elimination algorithm). I suspect the success of any such approach would depend on keeping the number of functions relatively small and including the correct functions among them--which sounds more like a matter of good luck and good guessing than of any principled investigation. But if blindly throwing a huge number of functional forms at the problem results in success, that would be worth knowing. $\endgroup$
    – whuber
    Dec 29, 2016 at 15:41

Your question needs refining because the function f is almost certainly not uniquely defined by the sample data. There are many different functions which could generate the same data.

That being said, Analysis of Variance (ANOVA) or a "sensitivity study" can tell you a lot about how your inputs (AA..EE) affect your output (FF).

I just did a quick ANOVA and found a reasonably good model: FF = 101*A + 47*B + 49*C - 4484. The function does not seem to depend on DD or EE linearly. Of course, we could go further with the model and add quadratic and mixture terms. Eventually you will have a perfect model that over-fits the data and has no predictive value. :)

  • $\begingroup$ @Pete As you said you could add quadratic,cubic,quartic ....and mixture terms but that would just be just nonsense. There is nonsense and there is non-sensical nonsense bot the most non-sensicle nonsense is "statistical nonsense ". $\endgroup$
    – IrishStat
    May 5, 2011 at 20:59
  • 2
    $\begingroup$ @IrishStat it is not generally nonsense to add mixture and higher order terms; only bad when it is done without restraint and without regard to theory $\endgroup$
    – Pete
    May 5, 2011 at 23:07
  • 2
    $\begingroup$ @Pete . Correct! The absence of a pre-existing theory makes it silly. $\endgroup$
    – IrishStat
    May 6, 2011 at 0:32
  • $\begingroup$ @Pete: What R^2 do you get for your model? $\endgroup$
    – knorv
    May 6, 2011 at 10:08
  • $\begingroup$ @knorv: I don't quite remember but it was > 0.90. When plotted about the regression line the points appeared to have a little bit of an "S"/cubic shape so I'm guessing the function "f" was a mathematical creation where someone typed 100A + 50(B+C) + higher order terms involving D & E. $\endgroup$
    – Pete
    May 6, 2011 at 12:39

Broadly speaking, there's no free lunch in machine learning:

In particular, if algorithm A outperforms algorithm B on some cost functions, then loosely speaking there must exist exactly as many other functions where B outperforms A

/edit: also, a radial SVM with C = 4 and sigma = 0.206 easily yields an R2 of .99. Extracting the actual equation used to derive this dataset is left as an exercise to the class. Code is in R.

Data <- read.csv("CV.csv", header=TRUE)
FL <- as.formula("FF ~ AA+BB+CC+DD+EE")
model <- train(FL,data=Data,method='svmRadial',tuneGrid = expand.grid(.C=4,.sigma=0.206))
R2( predict(model, Data), Data$FF)

All Models are wrong but some are useful : G.E.P.Box

Y(T)= - 4709.7
+ 102.60*AA(T)- 17.0707*AA(T-1)
+ 62.4994*BB(T) + 41.7453*CC(T) + 965.70*ZZ(T)

where ZZ(T)=0 FOR T=1,10 =1 OTHERWISE

There appears to be a "lagged relationship" between Y and AA AND an explained shift in the mean for observations 11-25 .

Curious results if this is not chronological or spatial data.

  • $\begingroup$ @IrishStats What is "G.E.P. Box"? $\endgroup$
    – knorv
    May 6, 2011 at 9:40
  • $\begingroup$ IrishStat: The data is not chronological. So the ordering of the observations is not of importance. The shift in the mean for observations #11-25 is merely a side-effect on how I retrieved the dataset. $\endgroup$
    – knorv
    May 6, 2011 at 10:07
  • 1
    $\begingroup$ @IrishStat: I meant that I just happened to retrieve the records in a certain order (think ORDER BY). The rows have no inherent special order. So you can safely re-arrange them without losing any information. Sorry if I confused you :-) $\endgroup$
    – knorv
    May 6, 2011 at 16:35
  • 1
    $\begingroup$ IrishStat: The dataset is unordered. The AA(T-1) term in your equation makes no sense in this context. $\endgroup$
    – naught101
    Oct 5, 2013 at 10:18
  • 2
    $\begingroup$ @naught That is correct. It means that the finding of any "significant" coefficient for the lagged variable AA(T-1) or of any "mean shift" introduces spurious variables: overfitting. What is interesting in this example is that although I have tended to think of overfitting as producing optimistically (and incorrectly) high $R^2$ values, in this circumstance it has produced a huge increase in the residual variance, because it has not found several important variables, either. $\endgroup$
    – whuber
    Oct 5, 2013 at 14:39

r square of 97.2

Estimation/Diagnostic Checking for Variable Y Y

Number of Residuals (R) =n 25
Number of Degrees of Freedom =n-m 20
Residual Mean =Sum R / n -.141873E-05
Sum of Squares =Sum R2 .775723E+07
Variance =SOS/(n) 310289.
Adjusted Variance =SOS/(n-m) 387861.
Standard Deviation RMSE =SQRT(Adj Var) 622.785
Standard Error of the Mean =Standard Dev/ (n-m) 139.259
Mean / its Standard Error =Mean/SEM -.101877E-07
Mean Absolute Deviation =Sum(ABS(R))/n 455.684
AIC Value ( Uses var ) =nln +2m 326.131
SBC Value ( Uses var ) =nln +m*lnn 332.226
BIC Value ( Uses var ) =see Wei p153 340.388
R Square = .972211
Durbin-Watson Statistic =[-A(T-1)]**2/A
2 1.76580


1CONSTANT                         -.381E+04   466.       .0000    -8.18


2Omega (input) -Factor #  1    0   .983       .410E-01   .0000    23.98


3Omega (input) -Factor #  2    0   108.       14.9       .0000     7.27


4Omega (input) -Factor #  3    0  -.577       .147       .0008    -3.93


5Omega (input) -Factor #  4    0   49.9       4.67       .0000    10.67

 Residual PLOT


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.