Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can call R from within Sage as follows. The command r.cor does require that you give it two lists containing the coordinates from your data set. In the example below, I'll use a list comprehension in Python to do that.

data=[[1,3],[1.5,2],[5,7]]
xdata=[a[0] for a in data]
ydata=[a[1] for a in data]
r.cor(xdata,ydata)

You can also get the regression line easily.

var('a,b')
f(x)=a*x+b
ans=find_fit(data,f)
g(x)=ans[0].rhs()*x+ans[1].rhs()
plot(g(x),(x,0,10))+list_plot(data)