[英]How to perform a bootstrapped paired t-test in R?
我想在 R 中執行引導配對 t 檢驗。我已經嘗試了使用參數配對 t 檢驗時返回 p<.05 的多個數據集,但是當我運行引導時,我得到 0.4 和 0.5 之間的 p 值. 我運行這個錯誤嗎?
differences<-groupA-groupB
t.test(differences) #To get the t-statistic e.g. 1.96
Repnumber <- 10000
tstat.values <- numeric(Repnumber)
for (i in 1:Repnumber) {
group1 = sample(differences, size=length(differences), replace=T)
tstat.values[i] = t.test(group1)$statistic
}
#### To get the bootstrap p-value compare the # of tstat.values
greater (or lesser) than or equal to the original t-statistic divided
by # of reps:
sum(tstat.values<=-1.96)/Repnumber
謝謝!
看起來你在比較蘋果和橘子。 對於differences
的單一 t 檢驗,您將獲得 t 統計量,如果大於臨界值,則表明group1
和group2
之間的差異是否顯着不同於零。 您的引導代碼執行相同的操作,但對於 10,000 個differences
引導樣本,您可以估計差異總體中differences
隨機樣本的 t 統計量differences
。 如果您取這些自舉 t-statistics ( mean(tstat.values)
) 的mean(tstat.values)
您會發現它與來自完整differences
樣本的單個 t-statistic 大致相同。
sum(tstat.values<=-1.96)/Repnumber
為您提供小於 -1.96 的自舉 t 統計量的百分比。 這是對在來自總體的重復隨機樣本中獲得小於 -1.96 的 t 統計量的時間百分比的估計值。 我認為這本質上是對在給定樣本量和顯着性水平下檢測group1
和group2
之間給定大小差異的檢驗group2
的估計,盡管我不確定這種功效分析的穩健性。
就正確引導 t 檢驗而言,我認為您實際需要做的是某種排列測試,與反復改組數據上的標簽並在每個打亂的數據集。 您可能想在CrossValidated上提問,以獲得有關如何正確處理數據的建議。 這些 CrossValidated 答案可能會有所幫助: here 、 here和here 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.