[R] Confidence Interval for SMR
Terry Therneau
therneau at mayo.edu
Wed Feb 20 14:55:57 CET 2008
> Hello,
>
> I am looking for a function which allows to calculate the confidence
> interval for a standard mortality ratio. I do have vectors with the
> number of observed and expected death. Has anybody a hint where to
> look?
> Best,
> Stefan
We find the following function useful for an SMR
cipoisson(observed, expected)
Terry Therneau
Mayo Clinic
"cipoisson" <-
function(k, time = 1, p = 0.95, method = c("exact", "anscombe") ) {
nn <- max(length(k), length(time), length(p))
if(nn > 1) {
k <- rep(k, length = nn)
time <- rep(time, length = nn)
p <- rep(p, length = nn)
}
p <- (1 - p)/2 #two sided
method <- match.arg(method)
if(method == "exact") {
dummy1 <- ifelse(k == 0, 1, k)
#avoid an error message of qgamma
lower <- ifelse(k == 0, 0, qgamma(p, dummy1))
upper <- qgamma(1 - p, k + 1)
}
else if(method == "anscombe") {
# anscombe's method
upper <- (sqrt(k + 7/8) - qnorm(p)/2)^2
lower <- (sqrt(k - 1/8) + qnorm(p)/2)^2
}
else stop("Invalid method")
if(nn == 1)
c(lower = lower, upper = upper)/time
else cbind(lower = lower, upper = upper)/time
}
More information about the R-help
mailing list