What is the difference between Expectation and Sum formula for the slope of line in regression?

50 Views Asked by At

As book I'm reading now shows, formula for the slope of the line in linear regression is $\beta_1 = \dfrac{\displaystyle \sum_{i=1}^n(X_i - \bar{X_n})(Y_i - \bar{Y_n})}{\displaystyle \sum_{i=1}^n(X_i - \bar{X_n})^2}$
The other formula for the slope is $\dfrac{Cov(X,Y)}{Var(X,Y)} = \dfrac{\mathbf{E}((X-\mu_x)(Y-\mu_y))}{\mathbf{E}(X-\mu)^2}$
So as I can see those 2 formulas look really simillar. First uses Sums, second Expectations. First uses mean of samples, second mean of populations. But why are they equal? Expectation != Sum. Also there is a third formula for the slope which I don't really understand : $p\dfrac{\sigma_y}{\sigma_x}$