When I calculate the variance by hand I get something different than Rstudio.
They guy in the video however, did calculate it as I did, wrong. Why is that?
My calculations:
Observations $=1,2,3,4,5,6,7,8,9$
Calculation by hand: $$E[X] = \frac{1}{n}*\sum^n_1 x_i = \frac{45}{9} = 5 \\\text{or}\\ E[X] = \sum x_i *\frac{1}{9} = 5 \\ Var(X) = E[(X-\mu)^2]=\sum (x_i - \mu)^2* \frac{1}{9} = \frac{20}{3} \\\text{or}\\ Var(X) = \left(\frac{1}{n} * \sum x_i^2\right)-\mu^2 = \frac{20}{3}$$
However when I use the following code in R i get different results.
a <- c(1:9)
mean(a) % = 5
var(a) % = 7.5
Questions:
What is happening here\Why are the results different?
Are the formulas I used for the calculation by hand correct?