# Calculating standard error in linear regression

I have seen in a couple of places that the following expression gives the standard error in linear regression:

$$se = \sqrt{\frac{1-r^2}{N-2}}$$

where $r$ is the correlation coefficient. I was calculating this quantity by hand, and by scipy's linregress, and I saw the two numbers differed. I checked the source code, and I found that the expression linregress uses for the standard error is the following:

$$se =\sqrt{\frac{1-r^2}{N-2}\frac{\sum (y_i-\bar{y})^2}{\sum (x_i-\bar{x})^2}}$$

What is the difference between these two expressions? What do they correspond to? How should I interpret them?

Edit: I forgot to specifiy that the data I'm concerned with is bivariate. I.e., I'm fitting a line on ${(x_i,y_i)}$.

Edit 2: I want to calculate the standard error on the correlation coefficient, $r$.

• Welcome to our site! You probably should specify the context you mean - are you specifically interested in simple linear regression ("y on x", the bivariate case) rather than multiple regression? – Silverfish May 14 '16 at 0:29
• @Silverfish Thank you :) I meant bivariate, and I edited the post accordingly. – sodiumnitrate May 14 '16 at 0:37
• The formula for s.e. in linear regression ? ? There is a formula for s.e. of correlation coefficient which is s.e. of r = (1- r square)/sqr of (n-2). – Subhash C. Davar May 14 '16 at 1:45
• 1. What specifically are you computing the standard error of? 2. When you say "bivariate" you mean that the y-variable is a vectore has two components? Or do you mean you have one-DV and one IV (i.e. one y and one x)? – Glen_b May 14 '16 at 1:58
• that is to say, the first equation is the se for r, the second the se for b – mandata May 14 '16 at 3:47