I don't think a single function exists for your specific case. In fact once you move beyond the basics (those in your list above) any simple function would need to make several assumptions that you may or may not be happy with.
For more complex studies like this you can estimate power using simulation, and that way you control all the assumptions made instead of having to live with the assumptions of others.
The basic steps are:
- decide what you think your data will look like
- decide how you will analyze your data
- write a function that simulates your data and analyzes it and returns the p-value of interest (things that you want to explore, like sample size, should be arguments to the function)
- run your function a bunch of times for a given set of conditions
- the power is just the proportion of times that the p-value is less than alpha.
- repeat step 4 for a new set of conditions.
Here is an answer to a similar question with examples of calculating power by simulation using R.
To calculate power for the difference in proportions between two populations, you need to find the standard error of this difference: $\sqrt{p_1 (1 - p_1) / n_1 + p_2 (1 - p_2) / n_2}$
To make this simple, let's assume equal sample size and variance. A little algebra gives us the following conservative bound for the standard error: $ se = 1 / \sqrt(n)$.
Let's assume an effect size of 0.1. Now for power of 80 percent and a significance level of 0.05, you need an effect that's 2.8 standard errors from zero. This gives us the following equation: $2.8 \times 1/ \sqrt{n} = 0.1$ A little algebra gives us: $n = (2.8 / 0.1)^2$ So utilizing this conservative bound on the variance, to detect an effect size 80 percent of the time at the significance level of 0.05, you'd need a sample size of 784 (392 for each population).
Now let's extend this to the case of a difference in the difference between two populations. Again, assuming equal sample sizes and variance, we have:
$$\sqrt{p(1 - p) / (n/4) + p(1 - p) / (n/4) +p(1 - p) / (n/4) +p(1 - p) / (n/4)}$$
This simplifies to $2 / \sqrt{n}$.
So if we replace the standard error for the difference between two proportions with the standard error of the difference in the difference between two proportions, we have: $n = (2.8 \times 2 ) / 0.1)^2$ again assuming an effect size of 0.1. This gives us a required sample of 3136 meaning that for the first survey, you'd need a sample of 1568 (784 for each population) and for the second survey, you'd also need a sample of 1568 (784 for each population).
For a very nice explanation of sample size, see chapter 16 of Regression and Other Stories by Gelmen, Hill, and Vehtari (available on line for free). For the case of difference-in-difference, look at the section on interactions.
Best Answer
The relative risk, $RR$, is simply $RR = \pi_1/\pi_2$ for group probabilities $\pi_i$. This means that $\pi_1 = RR \pi_2$.
Thus, a power analysis to detect a relative risk of $RR$ is equivalent to a power analysis to detect a risk difference between $\pi_1$ and $RR \pi_2$. See chapter 3 in Biostatistical Methods 2e by John Lachin for more.