標準偏差の不偏推定値 Last modified: Jun 28, 2004
目的
標準偏差の不偏推定値を求める。
参考文献
R. R. Sokal and F. J. Rohlf: Biometry - Third Edition, p.53, W. H. Freeman and company.
使用法
unbiased.sd(x)
引数
x データベクトル
ソース
インストールは,以下の 1 行をコピーし,R コンソールにペーストする
source("http://aoki2.si.gunma-u.ac.jp/R/src/unbiased_sd.R", encoding="euc-jp")
# 不偏標準偏差(不偏分散の平方根ではない)
unbiased.sd <- function(x)
{
x <- x[!is.na(x)] # 欠損値データを除く
n <- length(x) # 有効なデータの個数
return(sd(x)*sqrt((n-1)/2)*gamma((n-1)/2)/gamma(n/2))
}
使用例
> x <- rep(c(3.4, 3.7, 4.0, 4.3, 4.6), c(2, 8, 5, 8, 2)) # 右と同じ c(rep(3.4, 2), rep(3.7, 8), rep(4.0, 5), rep(4.3, 8), rep(4.6, 2))
# 上のデータは,3.4 が 2 個,3.7 が 8 個...等を意味する
> unbiased.sd(x)
[1] 0.3500364
> unbiased.sd(c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10))
[1] 3.112755
解説ページ
直前のページへ戻る
E-mail to Shigenobu AOKI