Skip to content

Instantly share code, notes, and snippets.

@ysaito8015
Last active August 29, 2015 14:01
Show Gist options
  • Save ysaito8015/a28e7632aa23feeb2d8e to your computer and use it in GitHub Desktop.
Save ysaito8015/a28e7632aa23feeb2d8e to your computer and use it in GitHub Desktop.
対症例対照研究(Matched Case-Control Study) Mantel-Haenszel のオッズ比計算スクリプト
calcMHRatio <- function(mymatrix, alpha=0.05)
{
caseExposedControlUnexposed <- mymatrix[1, 2]
caseUnexposedControlExposed <- mymatrix[2, 1]
MHRatio <- caseExposedControlUnexposed / caseUnexposedControlExposed
print(paste("Mantel-Haenszelのオッズ比 =", MHRatio))
# 信頼区間の計算
confidenceLevel <- (1 - alpha) * 100
sigma <- sqrt((1 / caseExposedControlUnexposed) + (1 / caseUnexposedControlExposed))
# sigmaは,オッズ比の対数の推定値の標準誤差
z <- qnorm(1 - (alpha / 2))
lowervalue <- MHRatio * exp(-z * sigma)
uppervalue <- MHRatio * exp( z * sigma)
print(paste(confidenceLevel, "% confidence interval = [", lowervalue,", ",uppervalue,"]"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment