[R] one-way anova power calculations

Peter Dalgaard p.dalgaard at biostat.ku.dk
Tue Feb 19 17:32:46 CET 2008


Will Holcomb wrote:
> I have been attempting some basic power calculations using R and I am not
> getting the results I expect. I had a homework assignment in SAS, but I want
> to learn R as well, so I was attempting to reproduce my result. (No one else
> in the class is doing R, so there's no need to obsfucate the answer, the SAS
> code is what I get my grade for.) The code I am using is:
>
> # You assume that the within-population standard deviations all equal 9. You
> set the Type 1 error rate at
> # alpha = .05. You presume that the population means will have the following
> values: 17.5, 19, 25, 20.5.
> # You intend to run 80 subjects in all, with equal n's across all 4 groups.
> Compute your power to reject
> # the null hypothesis under these conditions.
>
> means = c(17.5, 19, 25, 20.5)
> power.anova.test(groups = length(means), n = 80 / length(means),
>                  between.var = var(means), within.var = 9,
>                  sig.level = 0.05)
>
> The result I'm getting is:
>
>      Balanced one-way analysis of variance power calculation
>
>          groups = 4
>               n = 20
>     between.var = 10.5
>      within.var = 9
>       sig.level = 0.05
>           power = 1
>
>  NOTE: n is number in each group
>
> I've already done the calculation in SAS with the following code:
>
> data Dep;
> Input cue $ mean weight;
> datalines;
> A 17.5  1
> B 19    1
> C 25    1
> D 20.5  1
> ;
>
> proc glmpower;
> class cue;
> model mean = cue;
> weight weight;
> power
>     stddev = 9
>     alpha = 0.05
>     ntotal= 80
>     power = .;
> run;
>
> This produces a power of 0.616 which is the answer I was supposed to get.
> Any idea what I need to change?
>
>   
Using the _variance_ rather than the standard deviation for within.var 
seems to help quite a bit!

> Will
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.
>   


-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907



More information about the R-help mailing list