Different results when calculating Deviation and standard deviation in R

Computing deviation and standard deviation based on the Wikipedia description gives different results compared to the standard var () and sd () functions in R.

Deviation: 4 vs 4.571429. Standard deviation: 2 vs 2.13809.

Any suggestions or explanations?

> df <- c(2,4,4,4,5,5,7,9)
> df.length <- length(df)
> df.length
[1] 8

> df.mean <- sum(df) / df.length
> df.mean
[1] 5

> df.difference <- (df - df.mean)**2
> df.difference
[1]  9  1  1  1  0  0  4 16

> sum(df.difference)
[1] 32

> df.variance <- sum(df.difference) / df.length
> df.variance
[1] 4

> df.standard.deviation <- sqrt(df.variance)
> df.standard.deviation
[1] 2

> # mean, var and sd (default R)

> mean(df)
[1] 5

> var(df)
[1] 4.571429

> sd(df)
[1] 2.13809
+4
source share
1 answer

This is the difference between dividing by nor (n-1)degrees of freedom.

>df <- c(2,4,4,4,5,5,7,9)
> var(df)
[1] 4.571429


> sum((df-mean(df))^2/length(df))
[1] 4

> sum((df-mean(df))^2/(length(df)-1))
[1] 4.571429

This n-1is because ... copied directly from Wikipedia ( link )

, . , , , . , , , ; , .

+2

All Articles