Error in tstart and tstop for coxph

Hi there,

in my code for coxph, i am keep getting the error that Tstart and tstop are of different length, despite the number of rows are same in tstart, tstop, and event. Can someone advide how to solve this?

Thank you.

tstart<-rep(0,nrow(emp))
tstop<-emp[,paste0("egfr40_esrd","rd")]
event<-emp[,"egfr40_esrd"]
model<-coxph(Surv(tstart,tstop,event
)~sbp+hba1c+ln_uacr+hb+weight+hdl+ldl+ua+alb+k,data=emp)

model<-coxph(Surv(tstart,tstop,event~sbp+hba1c+ln_uacr+hb+weight+hdl+ldl+ua+alb+k),data=emp)
Error in Surv(tstart, tstop, event ~ sbp + hba1c + ln_uacr + :
Start and stop are different lengths

We don't really have enough info to help you out. Could you ask this with a minimal REPRoducible EXample (reprex)? A reprex makes it much easier for others to understand your issue and figure out how to help.

If you've never heard of a reprex before, you might want to start by reading this FAQ:

Hi,
lets assume we use the mtcars df
library(dplyr)

data<-mtcars

tstart_app<-rep(0,nrow(mtcars))
tstop_app<-mtcars[,paste0("am","hp")]
event_app<-mtcars[,"am"]

appmodel<-coxph(Surv(tstart_app,tstop_app,event_app)~mpg+disp+drat+qsec,data=mtcars)
the error is tstart_app and tstop_app are of different length.

A reprex needs to be self-contained, including the libraries used. Currently, your code produces the following:

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

data<-mtcars

tstart_app<-rep(0,nrow(mtcars))
tstop_app<-mtcars[,paste0("am","hp")]
#> Error in `[.data.frame`(mtcars, , paste0("am", "hp")): undefined columns selected
event_app<-mtcars[,"am"]

appmodel<-coxph(Surv(tstart_app,tstop_app,event_app)~mpg+disp+drat+qsec,data=mtcars)
#> Error in coxph(Surv(tstart_app, tstop_app, event_app) ~ mpg + disp + drat + : could not find function "coxph"

Created on 2019-06-03 by the reprex package (v0.3.0)

1 Like