ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 06 Oct 2017 16:31:49 -0500How-to: (Linear ...) regression in Sagehttps://ask.sagemath.org/question/8002/how-to-linear-regression-in-sage/Suppose I have the following set of points r = [(1,2),(3.45,4),(6,5),(4,3)]. How do I implement in Sage a (linear) regression with "bord tools"?Tue, 15 Mar 2011 08:42:53 -0500https://ask.sagemath.org/question/8002/how-to-linear-regression-in-sage/Comment by Laurent Claessens for <p>Suppose I have the following set of points r = [(1,2),(3.45,4),(6,5),(4,3)]. How do I implement in Sage a (linear) regression with "bord tools"?</p>
https://ask.sagemath.org/question/8002/how-to-linear-regression-in-sage/?comment=21979#post-id-21979I bet it is a translation from French: "avec les outils du bord". It means : using only what already exists in Sage.Wed, 16 Mar 2011 07:51:16 -0500https://ask.sagemath.org/question/8002/how-to-linear-regression-in-sage/?comment=21979#post-id-21979Comment by benjaminfjones for <p>Suppose I have the following set of points r = [(1,2),(3.45,4),(6,5),(4,3)]. How do I implement in Sage a (linear) regression with "bord tools"?</p>
https://ask.sagemath.org/question/8002/how-to-linear-regression-in-sage/?comment=21988#post-id-21988I don't know what "bord tools" means, but you can do all kinds of regression analysis, including linear regression, using the Sage interface to R. There are experts lurking here that I'm sure can give you an example.Tue, 15 Mar 2011 09:53:46 -0500https://ask.sagemath.org/question/8002/how-to-linear-regression-in-sage/?comment=21988#post-id-21988Comment by kcrisman for <p>Suppose I have the following set of points r = [(1,2),(3.45,4),(6,5),(4,3)]. How do I implement in Sage a (linear) regression with "bord tools"?</p>
https://ask.sagemath.org/question/8002/how-to-linear-regression-in-sage/?comment=21989#post-id-21989Can you clarify 'bord tools'? I'm not familiar with this phrase.Tue, 15 Mar 2011 09:45:49 -0500https://ask.sagemath.org/question/8002/how-to-linear-regression-in-sage/?comment=21989#post-id-21989Answer by kcrisman for <p>Suppose I have the following set of points r = [(1,2),(3.45,4),(6,5),(4,3)]. How do I implement in Sage a (linear) regression with "bord tools"?</p>
https://ask.sagemath.org/question/8002/how-to-linear-regression-in-sage/?answer=12196#post-id-12196It turns out that this has even showed up on [Stack Overflow](http://stackoverflow.com/questions/454606/how-can-i-do-regression-analysis-in-sage).
Luckily, that page refers to the function I had completely forgotten about - `find_fit`.
sage: find_fit?
String Form: <function find_fit at 0x10bee5cf8>
Namespace: Interactive
File: /Applications/MathApps/sage/local/lib/python2.6/site-packages/sage/numerical/optimize.py
Definition: find_fit(data, model, initial_guess=None, parameters=None, variables=None, solution_dict=False)
Docstring:
Finds numerical estimates for the parameters of the function model
to give a best fit to data.
So this might work, and looks decent.
sage: R = [[1,2],[3.45,4],[6,5],[4,3]]
sage: var('a,b')
(a, b)
sage: model(x) = a*x+b
sage: find_fit(R,model)
[a == 0.56881365890949054, b == 1.445160655902004]
sage: points(R)+plot(model(a=find_fit(R,model)[0].rhs(),b=find_fit(R,model)[1].rhs()),(x,0,10),color='red')
If you are serious about your needs, though, you should probably use some of the tools in [Scipy](http://www.scipy.org/Cookbook/LinearRegression) or R (numerous YouTube videos on this, though for reason I can't watch them right now.
Wed, 16 Mar 2011 10:18:35 -0500https://ask.sagemath.org/question/8002/how-to-linear-regression-in-sage/?answer=12196#post-id-12196Comment by DSM for <p>It turns out that this has even showed up on <a href="http://stackoverflow.com/questions/454606/how-can-i-do-regression-analysis-in-sage">Stack Overflow</a>.</p>
<p>Luckily, that page refers to the function I had completely forgotten about - <code>find_fit</code>.</p>
<pre><code>sage: find_fit?
String Form: <function find_fit at 0x10bee5cf8>
Namespace: Interactive
File: /Applications/MathApps/sage/local/lib/python2.6/site-packages/sage/numerical/optimize.py
Definition: find_fit(data, model, initial_guess=None, parameters=None, variables=None, solution_dict=False)
Docstring:
Finds numerical estimates for the parameters of the function model
to give a best fit to data.
</code></pre>
<p>So this might work, and looks decent.</p>
<pre><code>sage: R = [[1,2],[3.45,4],[6,5],[4,3]]
sage: var('a,b')
(a, b)
sage: model(x) = a*x+b
sage: find_fit(R,model)
[a == 0.56881365890949054, b == 1.445160655902004]
sage: points(R)+plot(model(a=find_fit(R,model)[0].rhs(),b=find_fit(R,model)[1].rhs()),(x,0,10),color='red')
</code></pre>
<p>If you are serious about your needs, though, you should probably use some of the tools in <a href="http://www.scipy.org/Cookbook/LinearRegression">Scipy</a> or R (numerous YouTube videos on this, though for reason I can't watch them right now.</p>
https://ask.sagemath.org/question/8002/how-to-linear-regression-in-sage/?comment=21975#post-id-21975See also the answers to http://ask.sagemath.org/question/348/plotting-and-fitting Wed, 16 Mar 2011 16:39:45 -0500https://ask.sagemath.org/question/8002/how-to-linear-regression-in-sage/?comment=21975#post-id-21975Comment by niles for <p>It turns out that this has even showed up on <a href="http://stackoverflow.com/questions/454606/how-can-i-do-regression-analysis-in-sage">Stack Overflow</a>.</p>
<p>Luckily, that page refers to the function I had completely forgotten about - <code>find_fit</code>.</p>
<pre><code>sage: find_fit?
String Form: <function find_fit at 0x10bee5cf8>
Namespace: Interactive
File: /Applications/MathApps/sage/local/lib/python2.6/site-packages/sage/numerical/optimize.py
Definition: find_fit(data, model, initial_guess=None, parameters=None, variables=None, solution_dict=False)
Docstring:
Finds numerical estimates for the parameters of the function model
to give a best fit to data.
</code></pre>
<p>So this might work, and looks decent.</p>
<pre><code>sage: R = [[1,2],[3.45,4],[6,5],[4,3]]
sage: var('a,b')
(a, b)
sage: model(x) = a*x+b
sage: find_fit(R,model)
[a == 0.56881365890949054, b == 1.445160655902004]
sage: points(R)+plot(model(a=find_fit(R,model)[0].rhs(),b=find_fit(R,model)[1].rhs()),(x,0,10),color='red')
</code></pre>
<p>If you are serious about your needs, though, you should probably use some of the tools in <a href="http://www.scipy.org/Cookbook/LinearRegression">Scipy</a> or R (numerous YouTube videos on this, though for reason I can't watch them right now.</p>
https://ask.sagemath.org/question/8002/how-to-linear-regression-in-sage/?comment=21976#post-id-21976nice find @kcrisman!Wed, 16 Mar 2011 10:41:45 -0500https://ask.sagemath.org/question/8002/how-to-linear-regression-in-sage/?comment=21976#post-id-21976Comment by tmaxara for <p>It turns out that this has even showed up on <a href="http://stackoverflow.com/questions/454606/how-can-i-do-regression-analysis-in-sage">Stack Overflow</a>.</p>
<p>Luckily, that page refers to the function I had completely forgotten about - <code>find_fit</code>.</p>
<pre><code>sage: find_fit?
String Form: <function find_fit at 0x10bee5cf8>
Namespace: Interactive
File: /Applications/MathApps/sage/local/lib/python2.6/site-packages/sage/numerical/optimize.py
Definition: find_fit(data, model, initial_guess=None, parameters=None, variables=None, solution_dict=False)
Docstring:
Finds numerical estimates for the parameters of the function model
to give a best fit to data.
</code></pre>
<p>So this might work, and looks decent.</p>
<pre><code>sage: R = [[1,2],[3.45,4],[6,5],[4,3]]
sage: var('a,b')
(a, b)
sage: model(x) = a*x+b
sage: find_fit(R,model)
[a == 0.56881365890949054, b == 1.445160655902004]
sage: points(R)+plot(model(a=find_fit(R,model)[0].rhs(),b=find_fit(R,model)[1].rhs()),(x,0,10),color='red')
</code></pre>
<p>If you are serious about your needs, though, you should probably use some of the tools in <a href="http://www.scipy.org/Cookbook/LinearRegression">Scipy</a> or R (numerous YouTube videos on this, though for reason I can't watch them right now.</p>
https://ask.sagemath.org/question/8002/how-to-linear-regression-in-sage/?comment=21941#post-id-21941Thank you for your answerSat, 26 Mar 2011 11:45:09 -0500https://ask.sagemath.org/question/8002/how-to-linear-regression-in-sage/?comment=21941#post-id-21941Answer by calcpage for <p>Suppose I have the following set of points r = [(1,2),(3.45,4),(6,5),(4,3)]. How do I implement in Sage a (linear) regression with "bord tools"?</p>
https://ask.sagemath.org/question/8002/how-to-linear-regression-in-sage/?answer=39045#post-id-39045Any way to find the Correlation Coefficient r and the Coefficient of Determination r^2 using find_fit()?
TIA,
AJG
calcpage@gmail.com
shadowfaxrant.blogspot.com
www.youtube.com/calcpage2009Fri, 06 Oct 2017 09:44:29 -0500https://ask.sagemath.org/question/8002/how-to-linear-regression-in-sage/?answer=39045#post-id-39045Comment by slelievre for <p>Any way to find the Correlation Coefficient r and the Coefficient of Determination r^2 using find_fit()?
TIA,
AJG
<a href="mailto:calcpage@gmail.com">calcpage@gmail.com</a>
http://shadowfaxrant.blogspot.com
http://www.youtube.com/calcpage2009 (www.youtube.com/calcpage2009)</p>
https://ask.sagemath.org/question/8002/how-to-linear-regression-in-sage/?comment=39056#post-id-39056Welcome to Ask Sage. Please post this as a new question rather than as an answer here (then delete the answer here). Avoid checking the "community wiki" checkbox on Ask Sage.Fri, 06 Oct 2017 16:31:49 -0500https://ask.sagemath.org/question/8002/how-to-linear-regression-in-sage/?comment=39056#post-id-39056Answer by Andre Mikulec for <p>Suppose I have the following set of points r = [(1,2),(3.45,4),(6,5),(4,3)]. How do I implement in Sage a (linear) regression with "bord tools"?</p>
https://ask.sagemath.org/question/8002/how-to-linear-regression-in-sage/?answer=13896#post-id-13896 mydata = [[1,3],[2,7],[3,13],[4,24]]
var('a,b,c')
mymodel(x) = a*x^2 + b*x + c
myfit = find_fit(mydata,mymodel,solution_dict=True)
myfit
points(mydata,color='purple') + plot(
mymodel(
a=myfit[a],
b=myfit[b],
c=myfit[c]
),
(x,0,4,),
color='red'
)Sat, 04 Aug 2012 08:07:56 -0500https://ask.sagemath.org/question/8002/how-to-linear-regression-in-sage/?answer=13896#post-id-13896