[x] Response Rate and CI by Clopper-Pearson exact method
[x] Response difference and CI by Wald asymptotic
[x] Odds ratio without stratification
[x] Odds ratio is from a Cochran-Mantel-Haenszel test stratified by different factors
Regarding response rate and CI, its's a question of confidence Intervals for proportions. I prefer to utilize the functions that have been built up in existing packages.
DescTools::BinomCI(x = 54, n = 100, method = "clopper-pearson")
But how about handling the stratified Wilson? A few packages wrap it up. Such as tern::s_proportion(). However, I feel like it should remain as is and not be added because it is not often utilized.
The response difference can be computed by DescTools::BinomDiffCI() as well, so just wrap this function inside.
Regarding odds ratio and CI, it depends on if we need to add stratified variables. If not, it's a common odds ratio calculation that can be done with the DescTools::OddsRatio function.
Otherwise we can use logistic regression to calculate the odds ratio as well. And then if we use confint() to obtain the CI , that is Wald's CI actually.
set.seed(12)
dta <- data.frame(
rsp = sample(c(TRUE, FALSE), 100, TRUE),
grp = factor(rep(c("A", "B"), each = 50), levels = c("B", "A")),
strata = factor(sample(c("C", "D"), 100, TRUE))
)
fit <- glm(rsp ~ grp, data = dta, family = binomial(link = "logit"))
exp(cbind(Odds_Ratio = coef(fit), confint(fit)))[-1, , drop = FALSE]
If we want to compute the odds ratio from the Cochran-Mantel-Haenszel test with stratified variables, I know there will be two approaches to handle it. One is mantelhaen.test() function, another is conditional logistic regression like survival::clogit() function. Given the results from those two way is not same, I'm going to compare with SAS and refer the documents to decide which one will be wrapped. As I know, tern package use the survival::clogit() to deal with the stratified CMH analysis.
Create several functions below:
Regarding response rate and CI, its's a question of confidence Intervals for proportions. I prefer to utilize the functions that have been built up in existing packages.
But how about handling the stratified Wilson? A few packages wrap it up. Such as
tern::s_proportion()
. However, I feel like it should remain as is and not be added because it is not often utilized.The response difference can be computed by
DescTools::BinomDiffCI()
as well, so just wrap this function inside.Regarding odds ratio and CI, it depends on if we need to add stratified variables. If not, it's a common odds ratio calculation that can be done with the
DescTools::OddsRatio
function.Otherwise we can use logistic regression to calculate the odds ratio as well. And then if we use
confint()
to obtain the CI , that is Wald's CI actually.If we want to compute the odds ratio from the Cochran-Mantel-Haenszel test with stratified variables, I know there will be two approaches to handle it. One is
mantelhaen.test()
function, another is conditional logistic regression likesurvival::clogit()
function. Given the results from those two way is not same, I'm going to compare with SAS and refer the documents to decide which one will be wrapped. As I know,tern
package use thesurvival::clogit()
to deal with the stratified CMH analysis.Using
mantelhaen.test()
function:Using conditional logistic regression: