@@ -295,114 +295,72 @@ knitr::kable(caption = "Power analysis for means results table (partial)",
...
@@ -295,114 +295,72 @@ knitr::kable(caption = "Power analysis for means results table (partial)",
## Proportions
## Proportions
Does not require a sample.
Does not require a sample. As a relatively simple example, suppose we were interested in the adoption of heat pumps in two equal sized samples. Suppose we thought in one sample (say, home owners) we thought it might be 40% and in rental properties it would be 25% (ref BRANZ 2015). What sample size would we need to conclude a significant difference with power = 0.8 and at various p values?
`pwr::pwr.tp.test()` (ref pwr) can give us the answer...
We can repeat this for other values of p1 and p2. For example, suppose both were much smaller (e.g. 10% and 15%)... Clearly we need _much_ larger samples.
```{r propTable1}
dt <- getPropN(p1 =0.1, p2 =0.15)
knitr::kable(dt, caption = "Samples required if p1 = 10% and p2 = 15%", digits = 2)
```
```
Figure \@ref(fig:propSampleSizeFig80all) shows the plot for all results.
# add vline at 0.01 effect size for p = 0.05, n = 1000
* p = 0.4 (40%)
p001Ref <- propPowerDT[pValue == "p = 0.01" &
* n = 151
effectSize < ceiling(p005Ref$effectSize) &
effectSize > floor(p005Ref$effectSize)] # for reference line
```{r proportionErrorMargin151}
x001 <- mean(p001Ref$sampleN)
p <- 0.4
p <- p + geom_segment(x = x001, y = y005, xend = x001, yend = 0, alpha = vLineAlpha,
n <- 151
colour = cbPalette[1])
em <- qnorm(0.975) * sqrt(p*(1-p)/n)
emr <- round(em,3)
# add vline at 0.1 effect size for p = 0.05, n = 1000
```
p01Ref <- propPowerDT[pValue == "p = 0.1" &
effectSize < ceiling(p005Ref$effectSize) &
effectSize > floor(p005Ref$effectSize)] # for reference line
x01 <- mean(p01Ref$sampleN)
p <- p + geom_segment(x = x01, y = y005, xend = x01, yend = 0, alpha = vLineAlpha,
colour = cbPalette[3])
# add vline at 0.2 effect size for p = 0.05, n = 1000
then the margin of error = +/- `r emr` (`r 100*emr`%). So we could quote the Heat Pump uptake for owner-occupiers as 40% (+/- `r 100*emr`% [or `r 40 - 100*emr` - `r 40 + 100*emr`] with p = 0.05).
p02Ref <- propPowerDT[pValue == "p = 0.2" &
effectSize < ceiling(p005Ref$effectSize) &
effectSize > floor(p005Ref$effectSize)] # for reference line
x02 <- mean(p02Ref$sampleN)
p <- p + geom_segment(x = x02, y = y005, xend = x02, yend = 0, alpha = vLineAlpha,
This may be far too wide an error margin for our purposes so we may instead have recruited 500 per sample. Now the margin of error is +/- `r emr` (`r 100*emr`%) so we can now quote the Heat Pump uptake for owner-occupiers as 40% (+/- `r 100*emr`% [or `r 40 - 100*emr` - `r 40 + 100*emr`] with p = 0.05).
```{r propPowerTable}
In much the same way as we did for means, we can calculate error margins