楼主的妹子是学统计的,以下代码是她们老师今天在课堂上讲的,求power的function。
老师留的作业是用power反推somple size,妹子已经哭得做不出来了,来这求大神们帮忙给点思路!!!!万分感谢!!!
###Example 1
#Let P(D|X=0) = 0.17 & P(D|X=1) = 0.34
#Let proposed n1. = 50 and let n2. = 50
n1. <- 50
n2. <- 50
reps <- 10000 #how many times we will resample and conduct hypothesis test
p0 <- 0.17
p1 <- 0.34
alpha = 0.05
pvals <- rep(NA, reps) #vector that will store the p-values
seed <- 1234 #ensure reproducible results
#now conducting the simulation
chisq.power <- function(n1., n2., reps, p0, p1, alpha, pvals, seed){
set.seed(seed)