ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 23 Sep 2017 04:59:10 -0500Weird resulting values with an exponential regressionhttp://ask.sagemath.org/question/34680/weird-resulting-values-with-an-exponential-regression/I have this model:
var('a,b')
R = [[100, 0.0489], [110, 0.0633], [120, 0.1213],[130, 0.1244], [140, 0.1569], [150, 0.1693], [160, 0.3154], [170, 0.6146], [180, 0.9118], [190, 01.7478], [200, 2.4523], [210, 4.7945], [230, 17.9766], [240, 29.3237], [250, 52.4374], [260, 94.6463], [270, 173.3447], [280, 396.0443], [290, 538.6976], [300, 1118.9984], [310, 1442.3694], [320, 4151.9089], [330, 6940.7322]]
model(x) = a*exp(b*x)
find_fit(R,model)
(which is the results of factorization time of an algorithm for people interested)
But I get weird values, obviously not in accordance with the points, when plotting all this. I was extremely surprised.
That's what I get:
[a=(2.3863359829×10^−15),b=1.0000000003]
Then I had the idea to try to get a formula with LibreOffice calc, just to have something to compare (I wasn't about to do this work on libreoffice initially), the result is different, but still so weird. In both cases, if I apply the formula given, it returns unthinkable values (very high).
Seems to be a problem with these values, no? Impossible to compute? Does sb have a solution? Thank you.Thu, 01 Sep 2016 09:50:40 -0500http://ask.sagemath.org/question/34680/weird-resulting-values-with-an-exponential-regression/Comment by Romuald_314 for <p>I have this model:</p>
<pre><code>var('a,b')
R = [[100, 0.0489], [110, 0.0633], [120, 0.1213],[130, 0.1244], [140, 0.1569], [150, 0.1693], [160, 0.3154], [170, 0.6146], [180, 0.9118], [190, 01.7478], [200, 2.4523], [210, 4.7945], [230, 17.9766], [240, 29.3237], [250, 52.4374], [260, 94.6463], [270, 173.3447], [280, 396.0443], [290, 538.6976], [300, 1118.9984], [310, 1442.3694], [320, 4151.9089], [330, 6940.7322]]
model(x) = a*exp(b*x)
find_fit(R,model)
</code></pre>
<p>(which is the results of factorization time of an algorithm for people interested)</p>
<p>But I get weird values, obviously not in accordance with the points, when plotting all this. I was extremely surprised.
That's what I get:</p>
<pre><code>[a=(2.3863359829×10^−15),b=1.0000000003]
</code></pre>
<p>Then I had the idea to try to get a formula with LibreOffice calc, just to have something to compare (I wasn't about to do this work on libreoffice initially), the result is different, but still so weird. In both cases, if I apply the formula given, it returns unthinkable values (very high).</p>
<p>Seems to be a problem with these values, no? Impossible to compute? Does sb have a solution? Thank you.</p>
http://ask.sagemath.org/question/34680/weird-resulting-values-with-an-exponential-regression/?comment=34703#post-id-34703Absolutely, I had understood. As exponentials are usually "delicate" to process. ;)Sat, 03 Sep 2016 01:19:08 -0500http://ask.sagemath.org/question/34680/weird-resulting-values-with-an-exponential-regression/?comment=34703#post-id-34703Comment by kcrisman for <p>I have this model:</p>
<pre><code>var('a,b')
R = [[100, 0.0489], [110, 0.0633], [120, 0.1213],[130, 0.1244], [140, 0.1569], [150, 0.1693], [160, 0.3154], [170, 0.6146], [180, 0.9118], [190, 01.7478], [200, 2.4523], [210, 4.7945], [230, 17.9766], [240, 29.3237], [250, 52.4374], [260, 94.6463], [270, 173.3447], [280, 396.0443], [290, 538.6976], [300, 1118.9984], [310, 1442.3694], [320, 4151.9089], [330, 6940.7322]]
model(x) = a*exp(b*x)
find_fit(R,model)
</code></pre>
<p>(which is the results of factorization time of an algorithm for people interested)</p>
<p>But I get weird values, obviously not in accordance with the points, when plotting all this. I was extremely surprised.
That's what I get:</p>
<pre><code>[a=(2.3863359829×10^−15),b=1.0000000003]
</code></pre>
<p>Then I had the idea to try to get a formula with LibreOffice calc, just to have something to compare (I wasn't about to do this work on libreoffice initially), the result is different, but still so weird. In both cases, if I apply the formula given, it returns unthinkable values (very high).</p>
<p>Seems to be a problem with these values, no? Impossible to compute? Does sb have a solution? Thank you.</p>
http://ask.sagemath.org/question/34680/weird-resulting-values-with-an-exponential-regression/?comment=34698#post-id-34698I think paulmasson's point was that it means this is the kind of data that standard regression models don't do well with in general...Fri, 02 Sep 2016 14:45:06 -0500http://ask.sagemath.org/question/34680/weird-resulting-values-with-an-exponential-regression/?comment=34698#post-id-34698Comment by Romuald_314 for <p>I have this model:</p>
<pre><code>var('a,b')
R = [[100, 0.0489], [110, 0.0633], [120, 0.1213],[130, 0.1244], [140, 0.1569], [150, 0.1693], [160, 0.3154], [170, 0.6146], [180, 0.9118], [190, 01.7478], [200, 2.4523], [210, 4.7945], [230, 17.9766], [240, 29.3237], [250, 52.4374], [260, 94.6463], [270, 173.3447], [280, 396.0443], [290, 538.6976], [300, 1118.9984], [310, 1442.3694], [320, 4151.9089], [330, 6940.7322]]
model(x) = a*exp(b*x)
find_fit(R,model)
</code></pre>
<p>(which is the results of factorization time of an algorithm for people interested)</p>
<p>But I get weird values, obviously not in accordance with the points, when plotting all this. I was extremely surprised.
That's what I get:</p>
<pre><code>[a=(2.3863359829×10^−15),b=1.0000000003]
</code></pre>
<p>Then I had the idea to try to get a formula with LibreOffice calc, just to have something to compare (I wasn't about to do this work on libreoffice initially), the result is different, but still so weird. In both cases, if I apply the formula given, it returns unthinkable values (very high).</p>
<p>Seems to be a problem with these values, no? Impossible to compute? Does sb have a solution? Thank you.</p>
http://ask.sagemath.org/question/34680/weird-resulting-values-with-an-exponential-regression/?comment=34693#post-id-34693That doesn't really help -- and th'at's also false.Fri, 02 Sep 2016 13:43:19 -0500http://ask.sagemath.org/question/34680/weird-resulting-values-with-an-exponential-regression/?comment=34693#post-id-34693Comment by paulmasson for <p>I have this model:</p>
<pre><code>var('a,b')
R = [[100, 0.0489], [110, 0.0633], [120, 0.1213],[130, 0.1244], [140, 0.1569], [150, 0.1693], [160, 0.3154], [170, 0.6146], [180, 0.9118], [190, 01.7478], [200, 2.4523], [210, 4.7945], [230, 17.9766], [240, 29.3237], [250, 52.4374], [260, 94.6463], [270, 173.3447], [280, 396.0443], [290, 538.6976], [300, 1118.9984], [310, 1442.3694], [320, 4151.9089], [330, 6940.7322]]
model(x) = a*exp(b*x)
find_fit(R,model)
</code></pre>
<p>(which is the results of factorization time of an algorithm for people interested)</p>
<p>But I get weird values, obviously not in accordance with the points, when plotting all this. I was extremely surprised.
That's what I get:</p>
<pre><code>[a=(2.3863359829×10^−15),b=1.0000000003]
</code></pre>
<p>Then I had the idea to try to get a formula with LibreOffice calc, just to have something to compare (I wasn't about to do this work on libreoffice initially), the result is different, but still so weird. In both cases, if I apply the formula given, it returns unthinkable values (very high).</p>
<p>Seems to be a problem with these values, no? Impossible to compute? Does sb have a solution? Thank you.</p>
http://ask.sagemath.org/question/34680/weird-resulting-values-with-an-exponential-regression/?comment=34684#post-id-34684The result of FindFit[] in Mathematica 10 is `{a -> 0., b -> 1.}`Thu, 01 Sep 2016 14:30:04 -0500http://ask.sagemath.org/question/34680/weird-resulting-values-with-an-exponential-regression/?comment=34684#post-id-34684Comment by Romuald_314 for <p>I have this model:</p>
<pre><code>var('a,b')
R = [[100, 0.0489], [110, 0.0633], [120, 0.1213],[130, 0.1244], [140, 0.1569], [150, 0.1693], [160, 0.3154], [170, 0.6146], [180, 0.9118], [190, 01.7478], [200, 2.4523], [210, 4.7945], [230, 17.9766], [240, 29.3237], [250, 52.4374], [260, 94.6463], [270, 173.3447], [280, 396.0443], [290, 538.6976], [300, 1118.9984], [310, 1442.3694], [320, 4151.9089], [330, 6940.7322]]
model(x) = a*exp(b*x)
find_fit(R,model)
</code></pre>
<p>(which is the results of factorization time of an algorithm for people interested)</p>
<p>But I get weird values, obviously not in accordance with the points, when plotting all this. I was extremely surprised.
That's what I get:</p>
<pre><code>[a=(2.3863359829×10^−15),b=1.0000000003]
</code></pre>
<p>Then I had the idea to try to get a formula with LibreOffice calc, just to have something to compare (I wasn't about to do this work on libreoffice initially), the result is different, but still so weird. In both cases, if I apply the formula given, it returns unthinkable values (very high).</p>
<p>Seems to be a problem with these values, no? Impossible to compute? Does sb have a solution? Thank you.</p>
http://ask.sagemath.org/question/34680/weird-resulting-values-with-an-exponential-regression/?comment=34683#post-id-34683Really? That's annoying... By the way the SageMathCell gives the same thing.
I think it must be the programs, not powerful enough (or the algorithms) to work with exponentials, big amount of data... that's delicate as a function. I've experienced similar problems in python (not with math and regressions): it was supposed to work fine and there were errors no one could understand. Weird problems, in short...Thu, 01 Sep 2016 12:48:14 -0500http://ask.sagemath.org/question/34680/weird-resulting-values-with-an-exponential-regression/?comment=34683#post-id-34683Comment by kcrisman for <p>I have this model:</p>
<pre><code>var('a,b')
R = [[100, 0.0489], [110, 0.0633], [120, 0.1213],[130, 0.1244], [140, 0.1569], [150, 0.1693], [160, 0.3154], [170, 0.6146], [180, 0.9118], [190, 01.7478], [200, 2.4523], [210, 4.7945], [230, 17.9766], [240, 29.3237], [250, 52.4374], [260, 94.6463], [270, 173.3447], [280, 396.0443], [290, 538.6976], [300, 1118.9984], [310, 1442.3694], [320, 4151.9089], [330, 6940.7322]]
model(x) = a*exp(b*x)
find_fit(R,model)
</code></pre>
<p>(which is the results of factorization time of an algorithm for people interested)</p>
<p>But I get weird values, obviously not in accordance with the points, when plotting all this. I was extremely surprised.
That's what I get:</p>
<pre><code>[a=(2.3863359829×10^−15),b=1.0000000003]
</code></pre>
<p>Then I had the idea to try to get a formula with LibreOffice calc, just to have something to compare (I wasn't about to do this work on libreoffice initially), the result is different, but still so weird. In both cases, if I apply the formula given, it returns unthinkable values (very high).</p>
<p>Seems to be a problem with these values, no? Impossible to compute? Does sb have a solution? Thank you.</p>
http://ask.sagemath.org/question/34680/weird-resulting-values-with-an-exponential-regression/?comment=34681#post-id-34681This seems to be the same problem in Scipy as http://ask.sagemath.org/question/26430/find_fit-possible-bug/Thu, 01 Sep 2016 10:55:43 -0500http://ask.sagemath.org/question/34680/weird-resulting-values-with-an-exponential-regression/?comment=34681#post-id-34681Answer by Emmanuel Charpentier for <p>I have this model:</p>
<pre><code>var('a,b')
R = [[100, 0.0489], [110, 0.0633], [120, 0.1213],[130, 0.1244], [140, 0.1569], [150, 0.1693], [160, 0.3154], [170, 0.6146], [180, 0.9118], [190, 01.7478], [200, 2.4523], [210, 4.7945], [230, 17.9766], [240, 29.3237], [250, 52.4374], [260, 94.6463], [270, 173.3447], [280, 396.0443], [290, 538.6976], [300, 1118.9984], [310, 1442.3694], [320, 4151.9089], [330, 6940.7322]]
model(x) = a*exp(b*x)
find_fit(R,model)
</code></pre>
<p>(which is the results of factorization time of an algorithm for people interested)</p>
<p>But I get weird values, obviously not in accordance with the points, when plotting all this. I was extremely surprised.
That's what I get:</p>
<pre><code>[a=(2.3863359829×10^−15),b=1.0000000003]
</code></pre>
<p>Then I had the idea to try to get a formula with LibreOffice calc, just to have something to compare (I wasn't about to do this work on libreoffice initially), the result is different, but still so weird. In both cases, if I apply the formula given, it returns unthinkable values (very high).</p>
<p>Seems to be a problem with these values, no? Impossible to compute? Does sb have a solution? Thank you.</p>
http://ask.sagemath.org/question/34680/weird-resulting-values-with-an-exponential-regression/?answer=38948#post-id-38948Being a) a statistician and b) lazy to the extreme, I tend to use well-validated tools that I know... R being in Sage, my minimal-effort solution is :
sage: Data=[[100, 0.0489], [110, 0.0633], [120, 0.1213],[130, 0.1244], [140, 0.1569], [150, 0.1693], [160, 0.3154], [170
....: , 0.6146], [180, 0.9118], [190, 01.7478], [200, 2.4523], [210, 4.7945], [230, 17.9766], [240, 29.3237], [250, 52.4
....: 374], [260, 94.6463], [270, 173.3447], [280, 396.0443], [290, 538.6976], [300, 1118.9984], [310, 1442.3694], [320,
....: 4151.9089], [330, 6940.7322]]
sage: RData=r.data_frame(X=[t[0] for t in Data], Y=[t[1] for t in Data])
sage: RModel=r.as_formula("log(Y)~X")
sage: r.summary(r.lm(RModel, data=RData))
Call:
lm(formula = sage103, data = sage166)
Residuals:
Min 1Q Median 3Q Max
-0.55634 -0.34349 -0.09318 0.25851 0.86680
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -9.214846 0.283884 -32.46 <2e-16 ***
X 0.053301 0.001255 42.45 <2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.4257 on 21 degrees of freedom
Multiple R-squared: 0.9885, Adjusted R-squared: 0.9879
F-statistic: 1802 on 1 and 21 DF, p-value: < 2.2e-16
This is in good concordance with ```paulmason```' results (I would have been **quite** surprised if this was not the case...), and gives ```Romuald_314``` the $R^2$ he asked for.
Sat, 23 Sep 2017 04:59:10 -0500http://ask.sagemath.org/question/34680/weird-resulting-values-with-an-exponential-regression/?answer=38948#post-id-38948Answer by qgfreire for <p>I have this model:</p>
<pre><code>var('a,b')
R = [[100, 0.0489], [110, 0.0633], [120, 0.1213],[130, 0.1244], [140, 0.1569], [150, 0.1693], [160, 0.3154], [170, 0.6146], [180, 0.9118], [190, 01.7478], [200, 2.4523], [210, 4.7945], [230, 17.9766], [240, 29.3237], [250, 52.4374], [260, 94.6463], [270, 173.3447], [280, 396.0443], [290, 538.6976], [300, 1118.9984], [310, 1442.3694], [320, 4151.9089], [330, 6940.7322]]
model(x) = a*exp(b*x)
find_fit(R,model)
</code></pre>
<p>(which is the results of factorization time of an algorithm for people interested)</p>
<p>But I get weird values, obviously not in accordance with the points, when plotting all this. I was extremely surprised.
That's what I get:</p>
<pre><code>[a=(2.3863359829×10^−15),b=1.0000000003]
</code></pre>
<p>Then I had the idea to try to get a formula with LibreOffice calc, just to have something to compare (I wasn't about to do this work on libreoffice initially), the result is different, but still so weird. In both cases, if I apply the formula given, it returns unthinkable values (very high).</p>
<p>Seems to be a problem with these values, no? Impossible to compute? Does sb have a solution? Thank you.</p>
http://ask.sagemath.org/question/34680/weird-resulting-values-with-an-exponential-regression/?answer=38855#post-id-38855var('b')
R = [[100, 0.0489], [110, 0.0633], [120, 0.1213],[130, 0.1244], [140, 0.1569], [150, 0.1693], [160, 0.3154], [170, 0.6146], [180, 0.9118], [190, 01.7478], [200, 2.4523], [210, 4.7945], [230, 17.9766], [240, 29.3237], [250, 52.4374], [260, 94.6463], [270, 173.3447], [280, 396.0443], [290, 538.6976], [300, 1118.9984], [310, 1442.3694], [320, 4151.9089], [330, 6940.7322]]
Ro=150
mo=0.1693
model(x) = mo*exp(b*(x-Ro))
fit=find_fit(R,model,solution_dict=True)
plot(model.subs(fit),(x,100,330))+points(R,size=20,color='red',figsize=3)
![plot](http://virtualabs.ist.utl.pt/test.png)Tue, 19 Sep 2017 07:45:13 -0500http://ask.sagemath.org/question/34680/weird-resulting-values-with-an-exponential-regression/?answer=38855#post-id-38855Answer by paulmasson for <p>I have this model:</p>
<pre><code>var('a,b')
R = [[100, 0.0489], [110, 0.0633], [120, 0.1213],[130, 0.1244], [140, 0.1569], [150, 0.1693], [160, 0.3154], [170, 0.6146], [180, 0.9118], [190, 01.7478], [200, 2.4523], [210, 4.7945], [230, 17.9766], [240, 29.3237], [250, 52.4374], [260, 94.6463], [270, 173.3447], [280, 396.0443], [290, 538.6976], [300, 1118.9984], [310, 1442.3694], [320, 4151.9089], [330, 6940.7322]]
model(x) = a*exp(b*x)
find_fit(R,model)
</code></pre>
<p>(which is the results of factorization time of an algorithm for people interested)</p>
<p>But I get weird values, obviously not in accordance with the points, when plotting all this. I was extremely surprised.
That's what I get:</p>
<pre><code>[a=(2.3863359829×10^−15),b=1.0000000003]
</code></pre>
<p>Then I had the idea to try to get a formula with LibreOffice calc, just to have something to compare (I wasn't about to do this work on libreoffice initially), the result is different, but still so weird. In both cases, if I apply the formula given, it returns unthinkable values (very high).</p>
<p>Seems to be a problem with these values, no? Impossible to compute? Does sb have a solution? Thank you.</p>
http://ask.sagemath.org/question/34680/weird-resulting-values-with-an-exponential-regression/?answer=34685#post-id-34685Rather than trying to fit the data directly, how about fitting its logarithm:
var('a,b')
R = [[100, 0.0489], [110, 0.0633], [120, 0.1213],[130, 0.1244], [140, 0.1569], [150, 0.1693], [160, 0.3154], [170, 0.6146], [180, 0.9118], [190, 01.7478], [200, 2.4523], [210, 4.7945], [230, 17.9766], [240, 29.3237], [250, 52.4374], [260, 94.6463], [270, 173.3447], [280, 396.0443], [290, 538.6976], [300, 1118.9984], [310, 1442.3694], [320, 4151.9089], [330, 6940.7322]]
logR = []
for r in R:
logR.append( [ r[0], log(r[1]) ] )
model(x) = a*x + b
fit = find_fit(logR, model)
print fit
p = scatter_plot(R)
p += plot( exp(a*x+b).subs(fit[0],fit[1]), (x,0,340) )
show(p)
The result of fitting the logarithm is
[a == 0.053300682674800925, b == -9.214845890267727]
which of course needs to be exponentiated to compare to the original data.
Here's a [live example](http://sagecell.sagemath.org/?z=eJwtkE2O2zAMRvcBcgfuRm4MQRRpyRpgLpGtYQycJpkGSGPD8bQ5fkmq3tiPP58f-Gda3dvUnt6a_e4IHzAMGEILwQfuy9jCgFgxERlGQ4woOCD9J2ZrcsUu1dWuYip1NRkSdnU4GybkZNgbFsTesCiiz5yNo1pFz120rKhW7HPhzlA9MPuSk4VFFYnFU6RsrCadrFO2f0dVKewTpxqXbZ88MdcFtaGS5AxcJ9Sno94n-YcWSIVQbH0pvYWSOiFz9JRKreixGDv0JdRrkopKN_hMMY7jfrff3ecvu7zAdV5hhdsDju_7HcijPT8ty-VxdjDAOgRJkaJbBxwbGKHRhN_z-XJ3r0ZSph8vOMBJq9fbJoXr7XH-lE-nUS3YqCwt6-2xSXPTyUXmnj-nbbusn8t93txRJ-DwAUZweS1Ogg-nxj-_T08nayqiL7Fowb3a0BKHRnWev-a_bmn-AarmjOU=&lang=sage) showing plots of the original data and the fit.Thu, 01 Sep 2016 14:55:24 -0500http://ask.sagemath.org/question/34680/weird-resulting-values-with-an-exponential-regression/?answer=34685#post-id-34685Comment by Romuald_314 for <p>Rather than trying to fit the data directly, how about fitting its logarithm:</p>
<pre><code>var('a,b')
R = [[100, 0.0489], [110, 0.0633], [120, 0.1213],[130, 0.1244], [140, 0.1569], [150, 0.1693], [160, 0.3154], [170, 0.6146], [180, 0.9118], [190, 01.7478], [200, 2.4523], [210, 4.7945], [230, 17.9766], [240, 29.3237], [250, 52.4374], [260, 94.6463], [270, 173.3447], [280, 396.0443], [290, 538.6976], [300, 1118.9984], [310, 1442.3694], [320, 4151.9089], [330, 6940.7322]]
logR = []
for r in R:
logR.append( [ r[0], log(r[1]) ] )
model(x) = a*x + b
fit = find_fit(logR, model)
print fit
p = scatter_plot(R)
p += plot( exp(a*x+b).subs(fit[0],fit[1]), (x,0,340) )
show(p)
</code></pre>
<p>The result of fitting the logarithm is</p>
<pre><code>[a == 0.053300682674800925, b == -9.214845890267727]
</code></pre>
<p>which of course needs to be exponentiated to compare to the original data.</p>
<p>Here's a <a href="http://sagecell.sagemath.org/?z=eJwtkE2O2zAMRvcBcgfuRm4MQRRpyRpgLpGtYQycJpkGSGPD8bQ5fkmq3tiPP58f-Gda3dvUnt6a_e4IHzAMGEILwQfuy9jCgFgxERlGQ4woOCD9J2ZrcsUu1dWuYip1NRkSdnU4GybkZNgbFsTesCiiz5yNo1pFz120rKhW7HPhzlA9MPuSk4VFFYnFU6RsrCadrFO2f0dVKewTpxqXbZ88MdcFtaGS5AxcJ9Sno94n-YcWSIVQbH0pvYWSOiFz9JRKreixGDv0JdRrkopKN_hMMY7jfrff3ecvu7zAdV5hhdsDju_7HcijPT8ty-VxdjDAOgRJkaJbBxwbGKHRhN_z-XJ3r0ZSph8vOMBJq9fbJoXr7XH-lE-nUS3YqCwt6-2xSXPTyUXmnj-nbbusn8t93txRJ-DwAUZweS1Ogg-nxj-_T08nayqiL7Fowb3a0BKHRnWev-a_bmn-AarmjOU=&lang=sage">live example</a> showing plots of the original data and the fit.</p>
http://ask.sagemath.org/question/34680/weird-resulting-values-with-an-exponential-regression/?comment=34704#post-id-34704I see.
Actually, I tried to calculate that coefficient before, without any conclusive outcome. I'll have to be looking for a formula.Sat, 03 Sep 2016 01:22:13 -0500http://ask.sagemath.org/question/34680/weird-resulting-values-with-an-exponential-regression/?comment=34704#post-id-34704Comment by kcrisman for <p>Rather than trying to fit the data directly, how about fitting its logarithm:</p>
<pre><code>var('a,b')
R = [[100, 0.0489], [110, 0.0633], [120, 0.1213],[130, 0.1244], [140, 0.1569], [150, 0.1693], [160, 0.3154], [170, 0.6146], [180, 0.9118], [190, 01.7478], [200, 2.4523], [210, 4.7945], [230, 17.9766], [240, 29.3237], [250, 52.4374], [260, 94.6463], [270, 173.3447], [280, 396.0443], [290, 538.6976], [300, 1118.9984], [310, 1442.3694], [320, 4151.9089], [330, 6940.7322]]
logR = []
for r in R:
logR.append( [ r[0], log(r[1]) ] )
model(x) = a*x + b
fit = find_fit(logR, model)
print fit
p = scatter_plot(R)
p += plot( exp(a*x+b).subs(fit[0],fit[1]), (x,0,340) )
show(p)
</code></pre>
<p>The result of fitting the logarithm is</p>
<pre><code>[a == 0.053300682674800925, b == -9.214845890267727]
</code></pre>
<p>which of course needs to be exponentiated to compare to the original data.</p>
<p>Here's a <a href="http://sagecell.sagemath.org/?z=eJwtkE2O2zAMRvcBcgfuRm4MQRRpyRpgLpGtYQycJpkGSGPD8bQ5fkmq3tiPP58f-Gda3dvUnt6a_e4IHzAMGEILwQfuy9jCgFgxERlGQ4woOCD9J2ZrcsUu1dWuYip1NRkSdnU4GybkZNgbFsTesCiiz5yNo1pFz120rKhW7HPhzlA9MPuSk4VFFYnFU6RsrCadrFO2f0dVKewTpxqXbZ88MdcFtaGS5AxcJ9Sno94n-YcWSIVQbH0pvYWSOiFz9JRKreixGDv0JdRrkopKN_hMMY7jfrff3ecvu7zAdV5hhdsDju_7HcijPT8ty-VxdjDAOgRJkaJbBxwbGKHRhN_z-XJ3r0ZSph8vOMBJq9fbJoXr7XH-lE-nUS3YqCwt6-2xSXPTyUXmnj-nbbusn8t93txRJ-DwAUZweS1Ogg-nxj-_T08nayqiL7Fowb3a0BKHRnWev-a_bmn-AarmjOU=&lang=sage">live example</a> showing plots of the original data and the fit.</p>
http://ask.sagemath.org/question/34680/weird-resulting-values-with-an-exponential-regression/?comment=34697#post-id-34697Alternately, you could use R fitting tools - if you are really interested in that kind of stuff you should probably be using pandas or R in any case. But a lot of times theoretical bounds end up not being so close to the actual performance for "small" values that today's computers can access :)Fri, 02 Sep 2016 14:43:53 -0500http://ask.sagemath.org/question/34680/weird-resulting-values-with-an-exponential-regression/?comment=34697#post-id-34697Comment by paulmasson for <p>Rather than trying to fit the data directly, how about fitting its logarithm:</p>
<pre><code>var('a,b')
R = [[100, 0.0489], [110, 0.0633], [120, 0.1213],[130, 0.1244], [140, 0.1569], [150, 0.1693], [160, 0.3154], [170, 0.6146], [180, 0.9118], [190, 01.7478], [200, 2.4523], [210, 4.7945], [230, 17.9766], [240, 29.3237], [250, 52.4374], [260, 94.6463], [270, 173.3447], [280, 396.0443], [290, 538.6976], [300, 1118.9984], [310, 1442.3694], [320, 4151.9089], [330, 6940.7322]]
logR = []
for r in R:
logR.append( [ r[0], log(r[1]) ] )
model(x) = a*x + b
fit = find_fit(logR, model)
print fit
p = scatter_plot(R)
p += plot( exp(a*x+b).subs(fit[0],fit[1]), (x,0,340) )
show(p)
</code></pre>
<p>The result of fitting the logarithm is</p>
<pre><code>[a == 0.053300682674800925, b == -9.214845890267727]
</code></pre>
<p>which of course needs to be exponentiated to compare to the original data.</p>
<p>Here's a <a href="http://sagecell.sagemath.org/?z=eJwtkE2O2zAMRvcBcgfuRm4MQRRpyRpgLpGtYQycJpkGSGPD8bQ5fkmq3tiPP58f-Gda3dvUnt6a_e4IHzAMGEILwQfuy9jCgFgxERlGQ4woOCD9J2ZrcsUu1dWuYip1NRkSdnU4GybkZNgbFsTesCiiz5yNo1pFz120rKhW7HPhzlA9MPuSk4VFFYnFU6RsrCadrFO2f0dVKewTpxqXbZ88MdcFtaGS5AxcJ9Sno94n-YcWSIVQbH0pvYWSOiFz9JRKreixGDv0JdRrkopKN_hMMY7jfrff3ecvu7zAdV5hhdsDju_7HcijPT8ty-VxdjDAOgRJkaJbBxwbGKHRhN_z-XJ3r0ZSph8vOMBJq9fbJoXr7XH-lE-nUS3YqCwt6-2xSXPTyUXmnj-nbbusn8t93txRJ-DwAUZweS1Ogg-nxj-_T08nayqiL7Fowb3a0BKHRnWev-a_bmn-AarmjOU=&lang=sage">live example</a> showing plots of the original data and the fit.</p>
http://ask.sagemath.org/question/34680/weird-resulting-values-with-an-exponential-regression/?comment=34696#post-id-34696That coefficient is not exposed by SageMath. You'll have to calculate it yourself.Fri, 02 Sep 2016 14:42:38 -0500http://ask.sagemath.org/question/34680/weird-resulting-values-with-an-exponential-regression/?comment=34696#post-id-34696Comment by Romuald_314 for <p>Rather than trying to fit the data directly, how about fitting its logarithm:</p>
<pre><code>var('a,b')
R = [[100, 0.0489], [110, 0.0633], [120, 0.1213],[130, 0.1244], [140, 0.1569], [150, 0.1693], [160, 0.3154], [170, 0.6146], [180, 0.9118], [190, 01.7478], [200, 2.4523], [210, 4.7945], [230, 17.9766], [240, 29.3237], [250, 52.4374], [260, 94.6463], [270, 173.3447], [280, 396.0443], [290, 538.6976], [300, 1118.9984], [310, 1442.3694], [320, 4151.9089], [330, 6940.7322]]
logR = []
for r in R:
logR.append( [ r[0], log(r[1]) ] )
model(x) = a*x + b
fit = find_fit(logR, model)
print fit
p = scatter_plot(R)
p += plot( exp(a*x+b).subs(fit[0],fit[1]), (x,0,340) )
show(p)
</code></pre>
<p>The result of fitting the logarithm is</p>
<pre><code>[a == 0.053300682674800925, b == -9.214845890267727]
</code></pre>
<p>which of course needs to be exponentiated to compare to the original data.</p>
<p>Here's a <a href="http://sagecell.sagemath.org/?z=eJwtkE2O2zAMRvcBcgfuRm4MQRRpyRpgLpGtYQycJpkGSGPD8bQ5fkmq3tiPP58f-Gda3dvUnt6a_e4IHzAMGEILwQfuy9jCgFgxERlGQ4woOCD9J2ZrcsUu1dWuYip1NRkSdnU4GybkZNgbFsTesCiiz5yNo1pFz120rKhW7HPhzlA9MPuSk4VFFYnFU6RsrCadrFO2f0dVKewTpxqXbZ88MdcFtaGS5AxcJ9Sno94n-YcWSIVQbH0pvYWSOiFz9JRKreixGDv0JdRrkopKN_hMMY7jfrff3ecvu7zAdV5hhdsDju_7HcijPT8ty-VxdjDAOgRJkaJbBxwbGKHRhN_z-XJ3r0ZSph8vOMBJq9fbJoXr7XH-lE-nUS3YqCwt6-2xSXPTyUXmnj-nbbusn8t93txRJ-DwAUZweS1Ogg-nxj-_T08nayqiL7Fowb3a0BKHRnWev-a_bmn-AarmjOU=&lang=sage">live example</a> showing plots of the original data and the fit.</p>
http://ask.sagemath.org/question/34680/weird-resulting-values-with-an-exponential-regression/?comment=34695#post-id-34695Just one question about regressions: can we have the coefficient R^2 ??Fri, 02 Sep 2016 14:17:46 -0500http://ask.sagemath.org/question/34680/weird-resulting-values-with-an-exponential-regression/?comment=34695#post-id-34695Comment by Romuald_314 for <p>Rather than trying to fit the data directly, how about fitting its logarithm:</p>
<pre><code>var('a,b')
R = [[100, 0.0489], [110, 0.0633], [120, 0.1213],[130, 0.1244], [140, 0.1569], [150, 0.1693], [160, 0.3154], [170, 0.6146], [180, 0.9118], [190, 01.7478], [200, 2.4523], [210, 4.7945], [230, 17.9766], [240, 29.3237], [250, 52.4374], [260, 94.6463], [270, 173.3447], [280, 396.0443], [290, 538.6976], [300, 1118.9984], [310, 1442.3694], [320, 4151.9089], [330, 6940.7322]]
logR = []
for r in R:
logR.append( [ r[0], log(r[1]) ] )
model(x) = a*x + b
fit = find_fit(logR, model)
print fit
p = scatter_plot(R)
p += plot( exp(a*x+b).subs(fit[0],fit[1]), (x,0,340) )
show(p)
</code></pre>
<p>The result of fitting the logarithm is</p>
<pre><code>[a == 0.053300682674800925, b == -9.214845890267727]
</code></pre>
<p>which of course needs to be exponentiated to compare to the original data.</p>
<p>Here's a <a href="http://sagecell.sagemath.org/?z=eJwtkE2O2zAMRvcBcgfuRm4MQRRpyRpgLpGtYQycJpkGSGPD8bQ5fkmq3tiPP58f-Gda3dvUnt6a_e4IHzAMGEILwQfuy9jCgFgxERlGQ4woOCD9J2ZrcsUu1dWuYip1NRkSdnU4GybkZNgbFsTesCiiz5yNo1pFz120rKhW7HPhzlA9MPuSk4VFFYnFU6RsrCadrFO2f0dVKewTpxqXbZ88MdcFtaGS5AxcJ9Sno94n-YcWSIVQbH0pvYWSOiFz9JRKreixGDv0JdRrkopKN_hMMY7jfrff3ecvu7zAdV5hhdsDju_7HcijPT8ty-VxdjDAOgRJkaJbBxwbGKHRhN_z-XJ3r0ZSph8vOMBJq9fbJoXr7XH-lE-nUS3YqCwt6-2xSXPTyUXmnj-nbbusn8t93txRJ-DwAUZweS1Ogg-nxj-_T08nayqiL7Fowb3a0BKHRnWev-a_bmn-AarmjOU=&lang=sage">live example</a> showing plots of the original data and the fit.</p>
http://ask.sagemath.org/question/34680/weird-resulting-values-with-an-exponential-regression/?comment=34694#post-id-34694Thank you paulmasson, seems to work fine now ! Now I can have a line such as
ln(y) = a*x+bFri, 02 Sep 2016 13:46:23 -0500http://ask.sagemath.org/question/34680/weird-resulting-values-with-an-exponential-regression/?comment=34694#post-id-34694