https://github.com/cran/Hmisc
Revision 288a6220b956d91fff5bd3cdc5eb883d53ebe1bd authored by Charles Dupont on 10 January 2006, 13:38:31 UTC, committed by cran-robot on 10 January 2006, 13:38:31 UTC
1 parent df80191
Raw File
Tip revision: 288a6220b956d91fff5bd3cdc5eb883d53ebe1bd authored by Charles Dupont on 10 January 2006, 13:38:31 UTC
version 3.0-9
Tip revision: 288a622
rcorr.cens.s
## Computes rank correlation measures between a variable X and a possibly
## censored variable Y, with event/censoring indicator EVENT
## Rank correlation is extension of Somers' Dxy = 2(Concordance Prob-.5)
## See Harrell et al JAMA 1984(?)
## Set outx=T to exclude ties in X from computations (-> Goodman-Kruskal
##  gamma-type rank correlation)

rcorr.cens <- function(x, S, outx=FALSE)
{
  if(!length(dim(S)))
    S <- cbind(S, rep(1, length(S)))
  
  y <- S[,1]
  event <- S[,2]
  if(length(y)!=length(x))
    stop("y must have same length as x")

  miss <- is.na(x) | is.na(y) | is.na(event)
  nmiss <- sum(miss)
  if(nmiss>0) {
    miss <- !miss
    x <- x[miss]
    y <- y[miss]
    event <- event[miss]
  }
  
  n <- length(x)
  ne <- sum(event)
  storage.mode(x) <- if(.R.) "double"
                     else "single"
  
  storage.mode(y) <- if(.R.) "double"
                     else "single"
  
  storage.mode(event) <- "logical"

  z <-
    if(.R.)
      .Fortran("cidxcn",x,y,event,length(x),nrel=double(1),nconc=double(1),
               nuncert=double(1),
               c.index=double(1),gamma=double(1),sd=double(1),as.logical(outx),
               PACKAGE="Hmisc")
    else
      .Fortran("cidxcn",x,y,event,length(x),nrel=double(1),nconc=double(1),
               nuncert=double(1),
               c.index=double(1),gamma=double(1),sd=double(1),as.logical(outx))
  
  r <- c(z$c.index,z$gamma,z$sd,n,nmiss,ne,z$nrel,z$nconc,z$nuncert)
  names(r) <- c("C Index","Dxy","S.D.","n","missing","uncensored",
                "Relevant Pairs",
                "Concordant","Uncertain")
  r
}
back to top