バートレットの球面性検定 Last modified: Jun 21, 2011
目的
因子分析の適切性を判断する,バートレットの球面性検定を行う
psych パッケージの cortest.bartlett も同じ検定を行う
使用法
kmo(x)
引数
x データ行列(行がケース,列が変数)
ソース
インストールは,以下の 1 行をコピーし,R コンソールにペーストする
source("http://aoki2.si.gunma-u.ac.jp/R/src/Bartlett.sphericity.test.R", encoding="euc-jp")
# バートレットの球面性検定
Bartlett.sphericity.test <- function(x) # データ行列
{
method <- "Bartlett's test of sphericity"
data.name <- deparse(substitute(x))
x <- subset(x, complete.cases(x)) # 欠損値を持つケースを除く
n <- nrow(x)
p <- ncol(x)
chisq <- (1-n+(2*p+5)/6)*log(det(cor(x)))
df <- p*(p-1)/2
p.value <- pchisq(chisq, df, lower.tail=FALSE)
names(chisq) <- "X-squared"
names(df) <- "df"
return(structure(list(statistic=chisq, parameter=df, p.value=p.value,
method=method, data.name=data.name), class="htest"))
}
使用例
x <- matrix(c( # 5ケース,4変数のデータ行列例(ファイルから読んでも良い)
1, 5, 6, 4,
2, 14, 5, 3,
3, 3, 4, 2,
4, 2, 6, 6,
3, 4, 3, 5
), ncol=4, byrow=TRUE)
Bartlett.sphericity.test(x)
Bartlett.sphericity.test(iris[1:4])
出力結果例
> Bartlett.sphericity.test(x)
Bartlett's test of sphericity
data: x
X-squared = 1.3618, df = 6, p-value = 0.9681
> Bartlett.sphericity.test(iris[1:4])
Bartlett's test of sphericity
data: iris[1:4]
X-squared = 706.9592, df = 6, p-value < 2.2e-16
直前のページへ戻る
E-mail to Shigenobu AOKI