R/cox.kmi.R

Defines functions cox.kmi

Documented in cox.kmi

cox.kmi <- function(formula, imp.data, df.complete = Inf, ...) {
    if (!inherits(imp.data, "kmi")) {
        stop("'imp.data' must be of class 'kmi'")
    }
    call <- match.call()
    info <- imp.data$info # that's where we have the column names (time, event)
    result <- lapply(seq_along(imp.data$imputed.data), function(i) {
        daten <- imp.data$original.data
        daten[, info[1]] <- imp.data$imputed.data[[i]][, 1]
        daten[, info[2]] <- imp.data$imputed.data[[i]][, 2]
        tmp <- coxph(formula, data = daten, ...)
        tmp
    })
    res <- MIcombine(result, df.complete = df.complete) ## that's a nice function
    zzz <- list(coefficients = res$coefficients,
                variance = res$variance,
                nimp = res$nimp,
                df = res$df,
                call = call,
                individual.fit = result)
    class(zzz) <- "cox.kmi"
    zzz
}

Try the kmi package in your browser

Any scripts or data that you put into this service are public.

kmi documentation built on May 28, 2019, 1:02 a.m.