Ask Your Question

linear regression with R in sagemath

asked 2016-08-24 17:49:25 +0200

debian_economist gravatar image

updated 2016-08-24 17:55:25 +0200


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 19:04:28 +0200 )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 17:44:43 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2016-08-25 15:03:02 +0200

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 17:46:29 +0200 )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 17:49:25 +0200

Seen: 617 times

Last updated: Aug 25 '16