Skip to content

Commit

Permalink
Handle delayed entry data in coxsnell_flexsurvreg
Browse files Browse the repository at this point in the history
  • Loading branch information
chjackson committed May 10, 2023
1 parent 4b0cd77 commit dc2dbab
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions R/residuals.flexsurvreg.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,16 @@ residuals.flexsurvreg <- function(object, type = "response", ...)
##'
##' @export
coxsnell_flexsurvreg <- function(x){
mf <- model.frame(x, orig=TRUE)
t <- mf[,1][,"time"]
covnames <- attr(model.frame(x), "covnames")
nd <- mf[,covnames,drop=FALSE]
res <- summary(x, type="cumhaz", t=t, newdata=nd, cross=FALSE,
ci=FALSE, se=FALSE, tidy=TRUE)
res$status <- mf[,1][,"status"]
res <- res[c("time","status", setdiff(names(res), c("time","status","est")), "est")]
res
mf <- model.frame(x, orig=TRUE)
startstop <- "start" %in% colnames(mf[,1])
tind <- if (startstop) "stop" else "time"
t <- mf[,1][,tind]
start <- if (startstop) mf[,1][,"start"] else 0
covnames <- attr(model.frame(x), "covnames")
nd <- mf[,covnames,drop=FALSE]
res <- summary(x, type="cumhaz", t=t, start=start, newdata=nd, cross=FALSE,
ci=FALSE, se=FALSE, tidy=TRUE)
res$status <- mf[,1][,"status"]
res <- res[c("time","status", setdiff(names(res), c("time","status","est")), "est")]
res
}

0 comments on commit dc2dbab

Please sign in to comment.