簡體   English   中英

Hotelling 的 T^2 檢驗的冪

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM