Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
手动计算R中配对t检验的幂_R_T Test_Hypothesis Test_Power Analysis - Fatal编程技术网

手动计算R中配对t检验的幂

手动计算R中配对t检验的幂,r,t-test,hypothesis-test,power-analysis,R,T Test,Hypothesis Test,Power Analysis,作为练习,我想在R中手动执行配对t检验,以刷新我过去的演讲。一切都进行得很顺利,但后来我想计算一下配对t检验的功效,这就是问题的根源 我知道功率是替代分布下的面积减去II型错误的面积,该面积由临界值分隔。基本上,在这个例子中,我需要找到1-P(X≤ alpha | mean=obsMean),但坦率地说,我不确定如何在R中构造该分布。我尝试使用与空值下t统计相同的过程。但这是没有意义的,因为预期的平均值和观察到的平均值是相同的,因此整个术语将等于0(1-pt((expMean-obseman)*

作为练习,我想在R中手动执行配对t检验,以刷新我过去的演讲。一切都进行得很顺利,但后来我想计算一下配对t检验的功效,这就是问题的根源

我知道功率是替代分布下的面积减去II型错误的面积,该面积由临界值分隔。基本上,在这个例子中,我需要找到1-P(X≤ alpha | mean=obsMean),但坦率地说,我不确定如何在R中构造该分布。我尝试使用与空值下t统计相同的过程。但这是没有意义的,因为预期的平均值和观察到的平均值是相同的,因此整个术语将等于0(
1-pt((expMean-obseman)*stdError,df
)。从这里开始,我只是越来越困惑,我想我遗漏了一些明显的东西

我使用了来自pwr包的pwr.t.test函数来比较我的结果

如果有人能帮我手动做这样的测试,那将是非常有帮助的,因为我在别处找到的大多数解决方案都跳过了我试图手动做的部分,而只是使用某种功率计算器

我使用的代码是:

# data
aP <- c(0.5331039, 0.4578532, 0.3129205, 0.5144858, 0.8149759, 0.4136268)
aM <- c(0.2750040, 0.5056830, 0.4828734, 0.4439654, 0.2738658, 0.3081768)

# difference between P and M
Diff <- aM - aP

# INIT t test
obsMean <- mean(Diff)
expMean <- 0

stdError <- (sqrt(length(Diff))/sd(Diff))

df <- n - 1
alpha = 0.05

# T-statistic

T_stat <- (obsMean-expMean)*stdError; T_stat


# critical value
crit_values <- qt(c(0.025,0.975),df) # lower bound = -2.570582


p_value <- 2*(pt(T_stat, df)); p_value
p_value < alpha

# comparison
t.test(aM, aP, paired = TRUE, alternative = "two.sided")


# INIT power
obsMean <- mean(Diff)
expMean <- mean(Diff)

# power???

power <- 1-pt((expMean - obsMean)*stdError, df); power

# comparison

cohensD <- (mean(aM)-mean(aP))/(sqrt((sd(aM)^2+sd(aP)^2)/2))

pwr.t.test(n = 6,d = cohensD, type = "paired", alternative = "two.sided")

# power = 0.4210006 
#数据

美联社也许你有更多的统计问题,而不是代码问题,如果是这样的话,最好把它贴出来