```
> x <- c(-8.5, 1.2, 1.5, 5.6, 2.4, 6.54, 25.21)
> sum((x - mean(x))^2) / length(x)
[1] 89.53117
> var(x)
[1] 104.453
```

Why the result is not match?

```
> x <- c(-8.5, 1.2, 1.5, 5.6, 2.4, 6.54, 25.21)
> sum((x - mean(x))^2) / length(x)
[1] 89.53117
> var(x)
[1] 104.453
```

Why the result is not match?

R uses the sample version of variance, i.e. the one with denominator `n - 1`

instead of `n`

. It's preferable as it gives unbiased estimate to population variance. See below:

```
x <- c(-8.5, 1.2, 1.5, 5.6, 2.4, 6.54, 25.21)
sum((x - mean(x)) ^ 2) / length(x)
#> [1] 89.53117
sum((x - mean(x)) ^ 2) / (length(x) - 1)
#> [1] 104.453
var(x)
#> [1] 104.453
```

^{Created on 2019-07-05 by the reprex package (v0.3.0)}

Hope this helps.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.