Hello,

mtesche wrote:
Hello,

I am trying to write a script with the end goal of graphing power (y) as a
result of sample size (x) at a variety of effects sizes.  I am new to loops,
and I think my problem is there.  Here's the script, which is modified from
the script found at the bootom of
http://www.statmethods.net/stats/power.html.  ANy help would be much
appreciated!mtes...@ualberta.ca

library(pwr)
library(lattice)

# range of sample sizes
r <- seq(5,300,5)
nr <- length(r)

# effect sizes
p <- seq(.4,1.2,.2)
np <- length(p)

# obtain power
power <- array(numeric(nr*np), dim=c(nr,np))
for (i in 1:np){
  for (j in 1:nr){
    result <- pwr.t.test(n = r[j], d = p[i],
    sig.level = .05, power = NULL,
    alternative = "two.sided")
    power[j,i] <- ceiling(result$power)
  }
}

First problem. Why are you calling ceiling, which will return 1 for any value of a power? What were you thinking that line was doing?

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to