[R] Help for Power analysis

Ass.Prof. Nikom Thanomsieng nikom at kku.ac.th
Sun Dec 9 18:29:12 CET 2001

Dear colleague,
   I not sure this R code  is correctly ?  I would to show
the number of Sample Size at  Sample Size Axis that line
draw from Power Axis (80%) from R code.
   How I show this and select the most appropriate of
this power (.79955687 - 80983575).

Thank for your help and answer.

Best Regards,
Nikom Thanomsieng,
Email: nikom at kku.ac.th


#Power analysis: Sample size for Chi-Square 2x2, RxC: R software
#Concept from SAS program to calculate power of ANOVA F-test

# and Cohen,J (1977). Statistical Power Analysis for Behavioral
#New York: Academic Press.
#Asst. Prof. Nikom Thanomsieng. 29/09/2000
#Department of Biostatistics & Demography. Faculty of Public Health.
#Khon Kaen University. Thailand.
#Email: nikom at kku.ac.th

#Modify data value of the first two line
x1 <- c(6,9)
x2 <- c(6,6)
nc <-cbind(x1)
nr  <-rbind(x2)
data1 <- rbind(x1,x2)
chi2<- chisq.test(data1,correct=F)$statistic
df<- ncol(nc-1)*nrow(nr-1)
ifelse(df==1,w<- sqrt(chi2/Ntotal), w<-sqrt(chi2/(chi2+Ntotal)))
Ntotal1<-900  #change this if power not enough
alpha  <-0.05  #change this for One tailed =0.05
for  (i in 1:Ntotal1){
       ncp[i] <- w^2 * i
power[i] <- 1-(pchisq(chicrit , df, ncp[i]))
samplesize<-cbind(n, ncp,power) }
plot(n,power,type="l",col="red", lwd=1,
panel.first = grid(10,10),
main="Power as a function of Sample Size",
xlab="Sample Size",
ylab="Power" )
segments(785, .8, 785,   0, col ="pink")
segments(785, .8,    0, 0.8, col ="pink")
mtext("Chi-Square", side = 3, line = 0.35,
    outer = FALSE, at = mean(par("usr")[1:2]), cex = 1, font = 4)

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list