![](/img/trans.png)
[英]Is there an R package for modified 2-sample Hotelling's T2 test (unequal covariance matrices)?
[英]Power for Hotelling's T^2 test
我试图估计hotelling 的T^2 测试的性能。 我根据正态性假设和等协方差矩阵模拟各种测试。 我成功地用下面的公式计算了测试的水平。
#Generate two groups with equal multivariate vector of means but different covariances
## From the multivariate normal distributions
library(MASS)
set.seed(123)
X<-mvrnorm(50,rep(0,10),diag(rep(1,10)))
Y<-mvrnorm(50,rep(0,10),diag(rep(3,10)))
#Two sample Hotelling T^2 test
library(ICSNP)
HotellingsT2(X, Y)
# Performance of the test
## Significant level
n=10000 # testing 10,000 times
t1err=0
for (i in 1:n){
X<-mvrnorm(50,rep(0,10),diag(rep(1,10)))
Y<-mvrnorm(50,rep(0,10),diag(rep(3,10)))
if (((HotellingsT2(X, Y))$p.value)<=0.05) (t1err=t1err+1)
}
cat("The significance level in percentage is", (t1err/n)*100,"%")
现在我的目标是计算测试的功效。 我注意到在电源 package 中没有酒店的 T^2 选项。 那么如何手动计算该测试的功效或计算测试 II 型错误的任何提示?
这是一种模拟 Hotelling 的 T 平方幂的方法。 该问题的 I 类错误率代码是对这个 Cross Validated post中代码的改编。 我还修改了该代码,稍微简化了一点。
等多元均值的 null 为假,一个是rep(0, 10)
另一个是rep(2, 10)
。 与问题的代码不同,协方差矩阵是相等的。
set.seed(123)
pval <- replicate(n, {
X <- mvrnorm(50, rep(0, 10), diag(rep(1, 10)))
Y <- mvrnorm(50, rep(2, 10), diag(rep(1, 10)))
HotellingsT2(X, Y)$p.value
})
t2err <- mean(pval > 0.05)
cat("The test power in percentage is", (1 - t2err)*100,"%\n")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.