Ask Your Question

linear regression with R in sagemath

asked 2016-08-24 10:49:25 -0500

updated 2016-08-24 10:55:25 -0500


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.

edit retag flag offensive close merge delete


It would be helpful if you provide the complete error message you got.

vdelecroix gravatar imagevdelecroix ( 2016-08-24 12:04:28 -0500 )edit

File "<ipython-input-4-8b7ce4bd7df2>", line 2 a = r.lm(LLCCS00 ~ OILBRNP, data = reader) ^ SyntaxError: invalid syntax

debian_economist gravatar imagedebian_economist ( 2016-08-25 10:44:43 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2016-08-25 08:03:02 -0500

calc314 gravatar image

From the documentation at, it looks like the tilde operator is not recognized. So, I think you need the following:

a =  r.lm(LLCCS00.tilde(OILBRNP), data = reader)
edit flag offensive delete link more


Thank 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.

debian_economist gravatar imagedebian_economist ( 2016-08-25 10:46:29 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-08-24 10:49:25 -0500

Seen: 73 times

Last updated: Aug 25 '16