HansDieter88 - 1 year ago 87

R Question

I´m trying to understand all the formulas around regression and am trying to calculate basically sum(xi-mean(x))^2 for a dataset.

Tried this:

`sum(pubs$pubs-mean(pubs$pubs))^2`

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

Usually you do the square first before summing, eg `sum((y - yhat)^2)`

; otherwise, you should get zero because `mean(x) = sum(x)/n`

and `sum(x-mean(x)) = sum(x) - n*mean(x)`

.

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**