[R-sig-eco] Plotting power graph for one sample proportion test
Paul Johnson
paul.johnson at glasgow.ac.uk
Thu Mar 17 11:11:26 CET 2016
Hi Kristen,
As an alternative to simulations you could just run pwr.p.test through the data frame suggested by Roman:
library(pwr)
parameters <-
expand.grid(
p.h0 = 0.5,
p.h1 = c(0.6, 0.7, 0.8),
n = c(50, 100),
sig.level = c(0.05, 0.01, 0.001))
parameters$h <- ES.h(parameters$p.h1, parameters$p.h0)
parameters
parameters$power <-
sapply(1:nrow(parameters), function(i) {
pwr.p.test(
h = parameters$h[i],
n = parameters$n[i],
sig.level = parameters$sig.level[i])$power
})
parameters
That just leaves the plotting.
However if you want to use simulations there’s lots of guidance available, including:
* Chapter 5 of Ben Bolker’s book Ecological Models and Data in R.
* We have have written an tutorial which covers GLMMs but starts with a simple power.t.test example, in the supplementary info here: dx.doi.org/10.1111/2041-210X.12306
Good luck,
Paul
> On 17 Mar 2016, at 08:27, Roman Luštrik <roman.lustrik at gmail.com> wrote:
>
> Hi,
>
> you're looking for a simulation approach of sorts. What I would do is set
> up a data.frame of all combination of parameters (with e.g. `expand.grid`)
> you're interested in and use for example `apply` to go through each
> combination and calculate power. You save that as a new variable and plot
> it.
>
> If you can provide us with parameters and their ranges perhaps we can be of
> further service.
>
> Cheers,
> Roman
>
> On Wed, Mar 16, 2016 at 10:47 PM, Kristen Gorman <kgorman at pwssc.org> wrote:
>
>> Dear all,
>> I am looking for help in plotting a power analysis using library(pwr).
>> Specifically, I am using the following test:
>>
>> pwr.p.test ()
>>
>> I would like to produce a sample size vs power plot for varying alpha
>> levels and differences between the null proportion and alternative
>> proportion.
>>
>> Thanks for any guidance,
>> Kristen Gorman
>>
>>
>>
>> [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-ecology mailing list
>> R-sig-ecology at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>>
>
>
>
> --
> In God we trust, all others bring data.
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-ecology mailing list
> R-sig-ecology at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
More information about the R-sig-ecology
mailing list