R/plotsurvivors.R

Defines functions plotsurvivors

Documented in plotsurvivors

plotsurvivors <-
function(x,status=rep(1,length(x))) {
  if (any(x==0)) {
    x <- x[-which(x==0)]
    status <- status[-which(x==0)]
  }
  if (any(status==0)) {
    x <- x[-which(status==0)]
    status <- status[-which(status==0)]
  }
  if (any(is.na(x))) {
    x <- x[-which(is.na(x))]
    status <- status[-which(is.na(x))]
  }
  if (any(is.na(status))) {
    x <- x[-which(is.na(status))]
    status <- status[-which(is.na(status))]
  }
  n <- length(x)
  tri <- sort(x)
  tri2 <- unique(tri)
  alive <- integer(length(tri2))
  alive[1] <- n
  for (i in 2:length(unique(tri2))) {
    alive[i] <- alive[i-1]-length(which(tri==tri2[i-1]))
  }
  plot(tri2,alive,pch=16,xlab="Time",ylab="Survivors (log scale)",log="y")
  result <- list(n=n,time=tri2,alive=alive)
  invisible(result)
}

Try the RVAideMemoire package in your browser

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

RVAideMemoire documentation built on Nov. 6, 2023, 5:07 p.m.