Solved – Sample size function for McNemar test of repeated proportions in R

mcnemar-testrsample-sizestatistical-power

I have been scouring CRAN and Google for a function (that I wouldn't have to code myself) that would calculate the sample size needed for a pre-post design with a dichotomous outcome – to no avail. If I'm wrong, please let me know!

I came across an R script from a university course and was wondering if someone wouldn't mind double-checking it for me – I've revised it a bit. (the URL is: http://www.statistik.lmu.de/institut/lehrstuhl/semwiso/bm-sose2009/CaCo/v8_4.pdf)

samsize.mcnemar <- function(pi.01, pi.10, alpha, beta, sided) 
                {
pi.d <- (pi.01 + pi.10)
N <- (qnorm(1 - alpha/sided) * sqrt(pi.d) + qnorm(1 - beta) *
    sqrt(pi.d - (pi.01 - pi.10)^2))^2/(pi.01 - pi.10)^2
return(ceiling(N))
}
# in my case, I am assuming that the 0 to 1 change will be 0.13 and that no 
# one will change from 1 to 0 

samsize.mcnemar(pi.01 = 0.13, pi.10 = 0, alpha = 0.05, beta = 0.2, sided = 2)

First, does this look correct?

Second, since this is not a matched-pairs design, I am not assuming that the intervention will cause people to revert back (if they are already performing the healthy behaviour). Should I be more conservative?

Thanks!

Best Answer

I compared the results I get with my function with this quick look-up table I found from StatsToDo (https://www.statstodo.com/SSizMcNemar_Tab.php#). I didn't try all combinations, but for the handful I did try, the sample size estimates were the exact same. I am pretty confident that the function is correct. Feel free though to add further comments

Related Question