2
$\begingroup$

I am a Stata user now teaching myself R. I have been trying to recapitulate analyses done in Stata using R but have got stuck. A multi-variable Cox regression with an offset in Stata and R give identical results The data can be downloaded from

https://www.dropbox.com/s/r26sgzjy3rytw3r/test.csv?dl=0

Stata code

stset fu, failure(br)
stcox ag1 ag2 sz nd grade screen , offset(hc1) nohr

R-code library(survival) fit <- Surv(er1$fu, er1$br) mva <- coxph(fit ~ ag1 + ag2 + sz + nd + grade + screen + offset(hc1), data = er1)

However when I then derive the cumulative baseline hazard functions they are different. This does not occur if I remove the offset term.

Stata code

predict h0, basechazard
twoway scatter h0 _t

R-code

h0 <- basehaz(mva, centered = F)
ggplot(data=h00, aes(x=time, y=hazard)) + geom_point()

Stata

R cum baseline hazard

$\endgroup$
  • 2
    $\begingroup$ You posted this at stackoverflow.com/questions/47021000/… and got the good advice to try here. Fine, but stats.stackexchange.com/help/on-topic explains that cross-posting is not encouraged on SE. So, the implication is that you should post at just one site at once (and delete the post at the other). In either forum, the lack of a reproducible example is problematic, as we can't see your data. Experts in survival analysis (not me) may be able to help without it. $\endgroup$ – Nick Cox Oct 30 '17 at 20:44
  • $\begingroup$ This question is quite interesting, I did some experiments, it is true, when there are no offset variables, the baseline cumulative hazards are the same for STATA and R (using same methods to handle ties), when there are the offset varialbes, the baseline cumulative hazards are quite different from the two software. $\endgroup$ – Deep North Oct 31 '17 at 2:00
  • $\begingroup$ @NickCox Thank you. I had not realised cross-posting was frowned upon. I am not sure how to add the data file on which the analysis is based. $\endgroup$ – Paul Pharoah Nov 1 '17 at 7:23
  • $\begingroup$ In this particular case, a reproducible example should be possible, I imagine, with a simpler dataset invented for the purpose. The bigger deal is someone seeing this who understands exactly how offsets are handled in both programs, not me, and so far no takers. $\endgroup$ – Nick Cox Nov 1 '17 at 10:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.