ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 25 Aug 2016 17:46:29 +0200linear regression with R in sagemathhttps://ask.sagemath.org/question/34571/linear-regression-with-r-in-sagemath/Hi,
I know it is possible to do a linear regression directly inside sage. However, I was wondering if it was possible to call the lm function from R to do it as well.
I tried the following code:
reader = r.read_csv('"databrent2.csv"', header=true, sep='";"')
a = r.lm(LLCCS00 ~ OILBRNP, data = reader)
LLCCS00 and OILBRNP are my two variables. They are in row. It is time series so for each variable, there is a value at each date (dates are columns). The issue I have is that I have a syntax error. I don't understand why.Wed, 24 Aug 2016 17:49:25 +0200https://ask.sagemath.org/question/34571/linear-regression-with-r-in-sagemath/Comment by vdelecroix for <p>Hi,</p>
<p>I know it is possible to do a linear regression directly inside sage. However, I was wondering if it was possible to call the lm function from R to do it as well.
I tried the following code:</p>
<pre><code>reader = r.read_csv('"databrent2.csv"', header=true, sep='";"')
a = r.lm(LLCCS00 ~ OILBRNP, data = reader)
</code></pre>
<p>LLCCS00 and OILBRNP are my two variables. They are in row. It is time series so for each variable, there is a value at each date (dates are columns). The issue I have is that I have a syntax error. I don't understand why.</p>
https://ask.sagemath.org/question/34571/linear-regression-with-r-in-sagemath/?comment=34573#post-id-34573It would be helpful if you provide the complete error message you got.Wed, 24 Aug 2016 19:04:28 +0200https://ask.sagemath.org/question/34571/linear-regression-with-r-in-sagemath/?comment=34573#post-id-34573Comment by debian_economist for <p>Hi,</p>
<p>I know it is possible to do a linear regression directly inside sage. However, I was wondering if it was possible to call the lm function from R to do it as well.
I tried the following code:</p>
<pre><code>reader = r.read_csv('"databrent2.csv"', header=true, sep='";"')
a = r.lm(LLCCS00 ~ OILBRNP, data = reader)
</code></pre>
<p>LLCCS00 and OILBRNP are my two variables. They are in row. It is time series so for each variable, there is a value at each date (dates are columns). The issue I have is that I have a syntax error. I don't understand why.</p>
https://ask.sagemath.org/question/34571/linear-regression-with-r-in-sagemath/?comment=34581#post-id-34581File "<ipython-input-4-8b7ce4bd7df2>", line 2
a = r.lm(LLCCS00 ~ OILBRNP, data = reader)
^
SyntaxError: invalid syntaxThu, 25 Aug 2016 17:44:43 +0200https://ask.sagemath.org/question/34571/linear-regression-with-r-in-sagemath/?comment=34581#post-id-34581Answer by calc314 for <p>Hi,</p>
<p>I know it is possible to do a linear regression directly inside sage. However, I was wondering if it was possible to call the lm function from R to do it as well.
I tried the following code:</p>
<pre><code>reader = r.read_csv('"databrent2.csv"', header=true, sep='";"')
a = r.lm(LLCCS00 ~ OILBRNP, data = reader)
</code></pre>
<p>LLCCS00 and OILBRNP are my two variables. They are in row. It is time series so for each variable, there is a value at each date (dates are columns). The issue I have is that I have a syntax error. I don't understand why.</p>
https://ask.sagemath.org/question/34571/linear-regression-with-r-in-sagemath/?answer=34580#post-id-34580From the documentation at http://doc.sagemath.org/html/en/reference/interfaces/sage/interfaces/r.html, it looks like the tilde operator is not recognized. So, I think you need the following:
a = r.lm(LLCCS00.tilde(OILBRNP), data = reader)Thu, 25 Aug 2016 15:03:02 +0200https://ask.sagemath.org/question/34571/linear-regression-with-r-in-sagemath/?answer=34580#post-id-34580Comment by debian_economist for <p>From the documentation at <a href="http://doc.sagemath.org/html/en/reference/interfaces/sage/interfaces/r.html">http://doc.sagemath.org/html/en/refer...</a>, it looks like the tilde operator is not recognized. So, I think you need the following:</p>
<pre><code>a = r.lm(LLCCS00.tilde(OILBRNP), data = reader)
</code></pre>
https://ask.sagemath.org/question/34571/linear-regression-with-r-in-sagemath/?comment=34582#post-id-34582Thank you for the hint. Now, I have an other issue: name "LLCCS00" is not defined.It seems to be a Python error. EDIT: The equivalent command works in R studio.Thu, 25 Aug 2016 17:46:29 +0200https://ask.sagemath.org/question/34571/linear-regression-with-r-in-sagemath/?comment=34582#post-id-34582