[R] Problem with Loops

Erik Iverson eriki at ccbr.umn.edu
Fri Apr 9 05:30:36 CEST 2010


>>
>> # 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?
>

Ah, after visiting the link you posted, I see why.  Ceiling makes sense when 
computing sample sizes, since you can't sample fractions of units, but not here. 
  Just get rid of that ceiling call wrapping the results, and see if it does 
what you want.



More information about the R-help mailing list