寻找在R中计算样本数量大于10的总体标准差的方法。目前无法提取R中的源代码以查找计算方法。
# Sample Standard Deviation
# Note: All the below match with 10 or less samples
n <- 10 # 10 or greater it shifts calculation
set.seed(1)
x <- rnorm(n, 10)
# Sample Standard Deviation
sd(x)
# [1] 0.780586
sqrt(sum((x - mean(x))^2)/(n - 1))
# [1] 0.780586
sqrt(sum(x^2 - 2*mean(x)*x + mean(x)^2)/(n - 1)) # # Would like the Population Standard Deviation equivalent using this.
# [1] 0.780586
sqrt( (n/(n-1)) * ( ( (sum(x^2)/(n)) ) - (sum(x)/n) ^2 ) )
# [1] 0.780586
现在,人口标准差需要与 100 个观测值的样本标准差 sd(x) 相匹配。
# Population Standard Deviation
n <- 100
set.seed(1)
x <- rnorm(x, 10)
sd(x)
# [1] 0.780586
sqrt(sum((x - mean(x))^2)/(n))
# [1] 0.2341758
sqrt(sum(x^2 - 2*mean(x)*x + mean(x)^2)/(n))
# [1] 0.2341758
# Got this to work above using (eventual goal, to fix the below):
# https://en.wikipedia.org/wiki/Algebraic_formula_for_the_variance
sqrt( (n/(n-1)) * ( ( (sum(x^2)/(n)) ) - (sum(x)/n) ^2 ) ) # Would like the Population Standard Deviation equivalent using this.
# [1] 3.064027