> 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
}

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to