# SET THE SIMULATION SAMPLE SIZE m <- 10000000 # GENERATE m NORMALS WITH MEAN 0.6 AND STANDARD DEVIATION sqrt(0.6*(1-0.6)/96) p.hat <- rnorm(m,0.6,sqrt(0.6*(1-0.6)/96)) # CREATE A CONFIDENCE INTERVAL MATRIX THAT IS m * 2 BIG p.ci <- cbind(p.hat - 1.96*0.5/sqrt(96),p.hat + 1.96*0.5/sqrt(96)) # GET THE PROPORTION OF LOWER BOUNDS GREATER THAN ONE-HALF sum(p.ci[,1] > 0.5)/m [1] 0.4997 n <- 196 m <- 10000000 p.hat <- rnorm(m,0.6,sqrt(0.6*0.4/n)) p.ci <- cbind(p.hat - 1.96*0.5/sqrt(n),p.hat + 1.96*0.5/sqrt(n)) sum(p.ci[,1] > 0.5)/m [1] 0.80417 ( delta <- 354*1.20 - 354 ) [1] 70.8 ( sigma <- sqrt(18357*1.5) ) [1] 165.94 #1.5 MULTIPLIER TO BE MORE CONSERVATIVE ( n <- (sigma/(delta/2.8))^2 ) [1] 43.067 p <- c(0.25,0.20,0.10,0.45); q <- c(0.20,0.15,0.15,0.50) n.wilcox.ord(power = 0.8, alpha = 0.05, t = 0.45, p, q) [1] 1446 $m [1] 795 $n [1] 651 ( obs <- data.frame("freq"=c(8,6,6,10,8,23,21,59), "PtDry.12mos"=gl(n=2,k=4,labels=c("no","yes")), "Status"=c("obese.inactive","obese.active", "nonobese.inactive","nonobese.active")) ) freq PtDry.12mos Status 1 8 no obese.inactive 2 6 no obese.active 3 6 no nonobese.inactive 4 10 no nonobese.active 5 8 yes obese.inactive 6 23 yes obese.active 7 21 yes nonobese.inactive 8 59 yes nonobese.active xtabs(freq ~ PtDry.12mos + Status, data=obs) Status PtDry.12mos nonobese.active nonobese.inactive obese.active obese.inactive no 10 6 6 8 yes 59 21 23 8 summary(xtabs(freq ~ PtDry.12mos + Status, data=obs)) Call: xtabs(formula = freq ~ PtDry.12mos + Status, data = obs) Number of cases in table: 141 Number of factors: 2 Test for independence of all factors: Chisq = 9.8, df = 3, p-value = 0.020 p.1 <- 6/(6+23); p.2 <- 8/(8+8) ( sigma.sq <- (6+23)*(6/(6+23))*(23/(6+23)) ) [1] 4.7586 ( log.HR <- log(log(p.1)/log(p.2)) ) [1] 0.82111 ( n.1 <- (qnorm(0.8)-qnorm(0.025))^2 * sigma.sq/(log.HR^2) ) [1] 55.397 ( n.needed.obese.nonobese <- n.1*(1+96/45) ) [1] 173.58 s.2 <- 1; d <- 0.3; r <- 1 # NORMAL APPROXIMATION sample.size <- function(r,alpha,beta,d,S2) ((r+1)*(qnorm(beta)+qnorm(1-alpha/2))^2*S2)/(r*d^2)+qnorm(1-alpha/2) ( n <- sample.size(r,0.05,0.8,d,s.2) ) [1] 176.38 power.size <- function(r,alpha,beta,d,S2,N) { DF <- N*(r+1)-2 NCP <- sqrt((r*N*d^2)/((r+1)*s.2)) TVAL <- qt(1-alpha/2,DF) 1-pt(q=TVAL, df=DF, ncp=NCP) } power.size(r,0.05,0.8,d,s.2,n) [1] 0.80138 s.2 <- 3; d <- 0.1; r <- 1.5 ( n <- sample.size(r,0.05,0.8,d,s.2) ) [1] 3926.4 power.size(r,0.05,0.8,d,s.2,n) [1] 0.80012