Standard Deviation in R Seems to be Returning the Wrong Answer - Am I Doing Something Wrong?

后端 未结 4 1954
迷失自我
迷失自我 2020-11-29 06:18

A simple example of calculating standard dev:

d <- c(2,4,4,4,5,5,7,9)
sd(d)

yields

[1] 2.13809

but

4条回答
  •  被撕碎了的回忆
    2020-11-29 06:30

    When I want the population variance or standard deviation (n as denominator), I define these two vectorized functions.

      pop.var <- function(x) var(x) * (length(x)-1) / length(x)
    
      pop.sd <- function(x) sqrt(pop.var(x))
    

    BTW, Khan Academy has a good discussion of population and sample standard deviation here.

提交回复
热议问题