I wanted to include some old-fashioned statistics in a paper recently, and did some websearching on how to calculate R^2 in Python. It’s all very touchy, it seems. Here’s what I found:

http://stackoverflow.com/questions/893657/how-do-i-calculate-r-squared-using-python-and-numpy

http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.stats.linregress.html

I eventually went with this:

%load_ext rmagic x = np.array(1/df.J) y = np.array(df.conc_rand) %Rpush x y %R print(summary(lm(y ~ x + 0)))