Online since 2002. Over 3300 puzzles, 2600 worldwide members, and 270,000 messages.

TwistyPuzzles.com Forum

It is currently Wed Jul 23, 2014 7:39 pm

All times are UTC - 5 hours



Post new topic Reply to topic  [ 25 posts ] 
Author Message
 Post subject: Can anyone find a formula to fit this data?
PostPosted: Wed Jan 01, 2014 7:11 pm 
Offline
User avatar

Joined: Mon Mar 30, 2009 5:13 pm
I have some data below, and am tring to find the best formula, y = f(x), with just 2 or 3 arbitrary constants, to give minimal discrepancy (residual) between calculated and observed y over the entire data set.

Would anyone like to have a crack at this:

x -> y

-0.9 -> 0.292326
-0.8 -> 0.274275
-0.7 -> 0.260295
-0.6 -> 0.248933
-0.5 -> 0.239433
-0.4 -> 0.231333
-0.3 -> 0.224326
-0.2 -> 0.218196
-0.1 -> 0.212786
0.0 -> 0.207978
0.1 -> 0.203679
0.2 -> 0.199818
0.3 -> 0.196335
0.4 -> 0.193183
0.5 -> 0.190323
0.6 -> 0.187722
0.7 -> 0.185354
0.8 -> 0.183193
0.9 -> 0.181221
1.0 -> 0.179432

_________________
If you want something you’ve never had, you’ve got to do something you’ve never done - Thomas Jefferson


Top
 Profile  
 
 Post subject: Re: Can anyone find a formula to fit this data?
PostPosted: Wed Jan 01, 2014 7:23 pm 
Offline
User avatar

Joined: Fri Dec 28, 2012 1:50 pm
Location: Near Las Vegas, NV
Fitting into a quadratic regression gives me this:
y=0.0323x²-0.056x+0.2075
It has very minimal error. Does this help?

_________________
My Youtube channel
My Shapeways Shop


Top
 Profile  
 
 Post subject: Re: Can anyone find a formula to fit this data?
PostPosted: Wed Jan 01, 2014 7:44 pm 
Offline
User avatar

Joined: Mon Mar 30, 2009 5:13 pm
benpuzzles wrote:
Fitting into a quadratic regression gives me this:
y=0.0323x²-0.056x+0.2075
It has very minimal error. Does this help?

Thanks, but a quadratic fit seems to be quite poor (RSQ = 0.9906):

Attachment:
Quadratic fit.png
Quadratic fit.png [ 36.43 KiB | Viewed 995 times ]

_________________
If you want something you’ve never had, you’ve got to do something you’ve never done - Thomas Jefferson


Top
 Profile  
 
 Post subject: Re: Can anyone find a formula to fit this data?
PostPosted: Wed Jan 01, 2014 7:46 pm 
Online
User avatar

Joined: Thu Dec 31, 2009 8:54 pm
Location: Bay Area, California
Looks more like an exponential curve than an conic curve. Here is what I used:

Code:
g(x) = (a * exp(-(x + 1) * b)) + c

Final set of parameters            Asymptotic Standard Error
=======================            ==========================

a               = 0.134809         +/- 0.001144     (0.849%)
b               = 1.34265          +/- 0.03847      (2.865%)
c               = 0.171799         +/- 0.001216     (0.7076%)


f(x) is Ben's proposal and g(x) is mine.


Attachments:
kevin_fit.png
kevin_fit.png [ 33.08 KiB | Viewed 991 times ]

_________________
Prior to using my real name I posted under the account named bmenrigh.
Top
 Profile  
 
 Post subject: Re: Can anyone find a formula to fit this data?
PostPosted: Wed Jan 01, 2014 7:54 pm 
Offline
User avatar

Joined: Mon Mar 30, 2009 5:13 pm
Brandon Enright wrote:
Looks more like an exponential curve than an conic curve. Here is what I used...

That's much better (RSQ = 0.998787), thanks! :D

_________________
If you want something you’ve never had, you’ve got to do something you’ve never done - Thomas Jefferson


Last edited by KelvinS on Wed Jan 01, 2014 7:55 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Can anyone find a formula to fit this data?
PostPosted: Wed Jan 01, 2014 7:54 pm 
Online
User avatar

Joined: Thu Dec 31, 2009 8:54 pm
Location: Bay Area, California
Also, you didn't specify any precision on your data. Is the y column really precise to 6 significant digits? How precise is the x column? Infinitely? One significant digit?

_________________
Prior to using my real name I posted under the account named bmenrigh.


Top
 Profile  
 
 Post subject: Re: Can anyone find a formula to fit this data?
PostPosted: Wed Jan 01, 2014 7:58 pm 
Offline
User avatar

Joined: Mon Mar 30, 2009 5:13 pm
Brandon Enright wrote:
Also, you didn't specify any precision on your data. Is the y column really precise to 6 significant digits? How precise is the x column? Infinitely? One significant digit?

x column is indefinitely precise, y column is precise to 6 decimals (as given), I think.

_________________
If you want something you’ve never had, you’ve got to do something you’ve never done - Thomas Jefferson


Top
 Profile  
 
 Post subject: Re: Can anyone find a formula to fit this data?
PostPosted: Wed Jan 01, 2014 8:06 pm 
Offline
User avatar

Joined: Mon Mar 30, 2009 5:13 pm
Brandon, what program are you using, and what do you get if you fit with 4 constants:

g(x) = (a * exp(-(x + d) * b)) + c

Where d may not be exactly 1 ?

_________________
If you want something you’ve never had, you’ve got to do something you’ve never done - Thomas Jefferson


Top
 Profile  
 
 Post subject: Re: Can anyone find a formula to fit this data?
PostPosted: Wed Jan 01, 2014 8:23 pm 
Online
User avatar

Joined: Thu Dec 31, 2009 8:54 pm
Location: Bay Area, California
KelvinS wrote:
Brandon, what program are you using, and what do you get if you fit with 4 constants:

g(x) = (a * exp(-(x + d) * b)) + c

Where d may not be exactly 1 ?

I'm using gnuplot which is a pretty awesome tool.

Code:
gnuplot> g(x) = (a * exp(-(x + d) * b)) + c
gnuplot> fit g(x) 'data.txt' via a,b,c,d
gnuplot> plot 'data.txt' using 1:2 with lines, g(x) with lines


Code:
Final set of parameters            Asymptotic Standard Error
=======================            ==========================

a               = 0.302054         +/- 4.572e+09    (1.514e+12%)
b               = 1.34265          +/- 0.03977      (2.962%)
c               = 0.171799         +/- 0.001255     (0.7302%)
d               = 1.60086          +/- 1.128e+10    (7.049e+11%)

correlation matrix of the fit parameters:

               a      b      c      d     
a               1.000
b               0.068  1.000
c               0.047  0.926  1.000
d               1.000  0.068  0.047  1.000

Attachment:
kevin_fit_2.png
kevin_fit_2.png [ 18.04 KiB | Viewed 958 times ]

_________________
Prior to using my real name I posted under the account named bmenrigh.


Top
 Profile  
 
 Post subject: Re: Can anyone find a formula to fit this data?
PostPosted: Wed Jan 01, 2014 8:33 pm 
Offline
User avatar

Joined: Mon Mar 30, 2009 5:13 pm
Wow, that is a very cool program, thanks!

Interesting that fitting with 4 parameters does not improve the fit (no change in RSQ) even though d is changed from 1 to 1.6.

Doesn't seem right, but what do you think?

_________________
If you want something you’ve never had, you’ve got to do something you’ve never done - Thomas Jefferson


Top
 Profile  
 
 Post subject: Re: Can anyone find a formula to fit this data?
PostPosted: Wed Jan 01, 2014 8:36 pm 
Online
User avatar

Joined: Thu Dec 31, 2009 8:54 pm
Location: Bay Area, California
Notice that d and a have perfect correlation in the correlation matrix? You can set d to anything and find an appropriate a to make it work.

Here are some examples:

Code:
a               = 6.531e-08        +/- 1209         (1.851e+12%)
b               = 1.34266          +/- 0.04359      (3.247%)
c               = 0.171799         +/- 0.001369     (0.7967%)
d               = -9.82944         +/- 1.37e+10     (1.393e+11%)

a               = 0.479834         +/- 6.738e+09    (1.404e+12%)
b               = 1.34264          +/- 0.03996      (2.976%)
c               = 0.171798         +/- 0.001267     (0.7372%)
d               = 1.94558          +/- 1.047e+10    (5.383e+11%)

a               = 0.169406         +/- 1.778e+09    (1.05e+12%)
b               = 1.34266          +/- 0.0438       (3.262%)
c               = 0.171799         +/- 0.001366     (0.795%)
d               = 1.17014          +/- 7.824e+09    (6.687e+11%)

This is because the shape of an exp() curve is scale invariant modulo some appropriate perspective adjustments.

_________________
Prior to using my real name I posted under the account named bmenrigh.


Top
 Profile  
 
 Post subject: Re: Can anyone find a formula to fit this data?
PostPosted: Wed Jan 01, 2014 8:47 pm 
Offline
User avatar

Joined: Mon Mar 30, 2009 5:13 pm
Ah yes, of course, thanks!

Then how/where would you add a fourth constant to get a much better fit?

What about:

g(x) = a * exp(x * b) + c + d * x

_________________
If you want something you’ve never had, you’ve got to do something you’ve never done - Thomas Jefferson


Last edited by KelvinS on Wed Jan 01, 2014 8:48 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Can anyone find a formula to fit this data?
PostPosted: Wed Jan 01, 2014 8:47 pm 
Online
User avatar

Joined: Thu Dec 31, 2009 8:54 pm
Location: Bay Area, California
I probably shouldn't have shifted the curve at all. Using g(x) = (a * exp(-x * b)) + c results in:

Code:
Final set of parameters            Asymptotic Standard Error
=======================            ==========================

a               = 0.0352053        +/- 0.001413     (4.014%)
b               = 1.34266          +/- 0.03841      (2.861%)
c               = 0.171799         +/- 0.001216     (0.7076%)


As I said before, shifting the curve with d is completely redundant because of the use of a for scale.

_________________
Prior to using my real name I posted under the account named bmenrigh.


Top
 Profile  
 
 Post subject: Re: Can anyone find a formula to fit this data?
PostPosted: Wed Jan 01, 2014 8:49 pm 
Offline
User avatar

Joined: Mon Mar 30, 2009 5:13 pm
What about:

g(x) = a * exp(b * x) + c + d * x

_________________
If you want something you’ve never had, you’ve got to do something you’ve never done - Thomas Jefferson


Top
 Profile  
 
 Post subject: Re: Can anyone find a formula to fit this data?
PostPosted: Wed Jan 01, 2014 8:57 pm 
Online
User avatar

Joined: Thu Dec 31, 2009 8:54 pm
Location: Bay Area, California
KelvinS wrote:
Ah yes, of course, thanks!

Then how/where would you add a fourth constant to get a much better fit?

What about:

g(x) = a * exp(x * b) + c + d * x


Whoa I wouldn't have thought of adding a linear term but that's a way better fit (still with -x although you could just do -b instead):

Code:
Final set of parameters            Asymptotic Standard Error
=======================            ==========================

a               = 0.0126512        +/- 0.001062     (8.395%)
b               = 2.05477          +/- 0.06713      (3.267%)
c               = 0.195112         +/- 0.001144     (0.5865%)
d               = -0.0178764       +/- 0.001092     (6.107%)

Attachment:
kevin_fit_3.png
kevin_fit_3.png [ 16.84 KiB | Viewed 931 times ]

_________________
Prior to using my real name I posted under the account named bmenrigh.


Top
 Profile  
 
 Post subject: Re: Can anyone find a formula to fit this data?
PostPosted: Wed Jan 01, 2014 9:00 pm 
Offline
User avatar

Joined: Mon Mar 30, 2009 5:13 pm
Superb, thank you!

I may need your help at some point to help me learn this great tool!

Cheers,
K.

_________________
If you want something you’ve never had, you’ve got to do something you’ve never done - Thomas Jefferson


Top
 Profile  
 
 Post subject: Re: Can anyone find a formula to fit this data?
PostPosted: Wed Jan 01, 2014 9:02 pm 
Online
User avatar

Joined: Thu Dec 31, 2009 8:54 pm
Location: Bay Area, California
What is this data from? What made you guess adding a linear term to the exponential term?

_________________
Prior to using my real name I posted under the account named bmenrigh.


Top
 Profile  
 
 Post subject: Re: Can anyone find a formula to fit this data?
PostPosted: Wed Jan 01, 2014 9:08 pm 
Offline
User avatar

Joined: Mon Mar 30, 2009 5:13 pm
Brandon Enright wrote:
What is this data from? What made you guess adding a linear term to the exponential term?

The data is from a work project. I guessed adding the linear term purely by seeing that the right side of the curve tended towards a slope/gradient rather than a flat/horizontal line. So it seemed to be a composition of exponential and linear. Make sense?

_________________
If you want something you’ve never had, you’ve got to do something you’ve never done - Thomas Jefferson


Top
 Profile  
 
 Post subject: Re: Can anyone find a formula to fit this data?
PostPosted: Wed Jan 01, 2014 9:18 pm 
Offline
User avatar

Joined: Fri Mar 06, 2009 9:23 pm
A quick minitab analysis yielded the following results, which looks like it conforms to what has already been posted.

an r^2 value of 99% is typically a lot higher than what I see whenever I'm running tests. Depending on the accuracy of your equipment/ repeatability of your study, I'd say this is a slam dunk, but I'm looking at this like an engineer.

The normality test of the residuals show that the residuals are not normally distributed, which might be indicative of the fact that the nature of the data is not actually quadratic. Another possible reason of the non normally distributed residuals could just be the fact that there is a relatively small sample size. Reading through the thread (I know I missed the boat a little bit)it looks like you are going through and adding terms to make the regression fit better. Knowing how the data is generated might lead to some theory that could drive the regression instead of just throwing stuff in and making it fit.


Attachments:
Screenshot_5.png
Screenshot_5.png [ 39.79 KiB | Viewed 907 times ]

_________________
--Eric Vergo

My Shapeways shop
Top
 Profile  
 
 Post subject: Re: Can anyone find a formula to fit this data?
PostPosted: Wed Jan 01, 2014 9:26 pm 
Offline

Joined: Fri Dec 20, 2013 11:47 pm
I would have said 42, but I'm also bad at math :D


Top
 Profile  
 
 Post subject: Re: Can anyone find a formula to fit this data?
PostPosted: Fri Jan 03, 2014 7:16 am 
Offline

Joined: Mon Dec 16, 2013 7:13 am
A neat tool I have used for stuff like this is the function finder at http://zunzun.com/. The top ranked result for your data was this:
Code:
y = 1.0 / exp(((x-a)/b)^c) + Offset

Fitting target of lowest sum of squared absolute error = 2.2126873197635119E-07

a = -1.3826027651964967E+00
b =  7.4496380258280037E-02
c =  3.3644155009905519E-01
Offset =  1.3882881100890193E-01

which could be written as
Code:
y = exp(-2.3958553356389 * (x + 1.38260276519649)^0.336441550099055) + 0.138828811008901

If you have an idea what type of equation you're looking for, there are many equally good matches returned by the function finder.


// Per.


Top
 Profile  
 
 Post subject: Re: Can anyone find a formula to fit this data?
PostPosted: Fri Jan 03, 2014 8:17 am 
Offline
User avatar

Joined: Mon Mar 30, 2009 5:13 pm
Very cool, thank you!

In fact I see this tool can also fit surface functions to 2D data arrays (i.e., z = f(x,y)?), which is actually what I have been trying to do, by fitting curves to individual slices of data, then fitting curves to the parameters of those first curves.

Wow, this is fantastic! AND, it's completely web-based! I wish I had known about zunzun earlier!

And now I sound like one of those very annoying canned actors endorsing the product as a "real" customer in a commercial! :lol:

_________________
If you want something you’ve never had, you’ve got to do something you’ve never done - Thomas Jefferson


Top
 Profile  
 
 Post subject: Re: Can anyone find a formula to fit this data?
PostPosted: Fri Jan 03, 2014 5:56 pm 
Offline

Joined: Mon Dec 16, 2013 7:13 am
Yes, it's cool, isn't it.

I have also used this site when I wanted to fit a custom equation to data: http://statpages.org/nonlin.html

I ended up making my own program based on the code from that site, though.


// Per.


Top
 Profile  
 
 Post subject: Re: Can anyone find a formula to fit this data?
PostPosted: Fri Jan 03, 2014 8:03 pm 
Online
User avatar

Joined: Thu Dec 31, 2009 8:54 pm
Location: Bay Area, California
Kevin, can you get more data points? And can you get them to a higher precision? I'd like to see how various functions stack up and the more data the better.

_________________
Prior to using my real name I posted under the account named bmenrigh.


Top
 Profile  
 
 Post subject: Re: Can anyone find a formula to fit this data?
PostPosted: Fri Jan 03, 2014 9:02 pm 
Offline
User avatar

Joined: Mon Mar 30, 2009 5:13 pm
Yes, in fact what I've been trying to do is find a formula to solve the following function for p, since it does not have a closed solution, to avoid calculating it numerically:

Code:
g = (p ^k - (1 - p) ^k) / (p ^k + (1 - p) ^ k - 2 / (k + 1)), where:

0 <= p <= 1, -0.9 <= k <=1, and k <> 0

Basically, I fit curves to individual slices of data at different values of k, fit another curve to the parameters of the first set of curves, and then substitute in the formulae for the individual parameters to get the surface function, p = f(g,k).

So far, the best fit (RSQ = 0.999992) I have found is:

Code:
p = 0.5 + x * Arctan(g * Tan((0.5 - (k + 1) ^ (-1 / k)) / x)), where:

x = 0.0127 * Exp(-2.0856 * k) - 0.0168 * k + 0.1941

But I haven't tried zunzun yet...

_________________
If you want something you’ve never had, you’ve got to do something you’ve never done - Thomas Jefferson


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 25 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Forum powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group