Tag Archives: R^2

Statistics in Python: Calculating R^2

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://stats.stackexchange.com/questions/36064/calculating-r-squared-coefficient-of-determination-with-centered-vs-un-center
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
http://forums.udacity.com/questions/100154896/why-is-r-squared-from-formula-different-than-scipy-functions-one

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)))

Comments Off on Statistics in Python: Calculating R^2

Filed under statistics