[R] SAS code in R
Terry Therneau
therneau at mayo.edu
Tue Sep 6 15:39:32 CEST 2011
-- Begin included message
/* Combinations of Risk Factors */
data test2;
input sex treat;
DATALINES;
0 0
1 0
0 1
1 1
;
run;
/* Survival estimates for the above combinations */
proc phreg data = pudat2;
model withtime*wcens(0) = sex treat /ties = efron;
baseline out = surv2 survival = survival lower = slower upper = supper
covariates = test2 /method = ch nomean cltype=loglog;
run;
/* Survival estimates at 1 year */
proc print data = surv2 noobs;
where withtime = 364;
fit1 <- coxph(Surv(withtime,wcens)~ sex+treat,data=pudat2)
my.fit <- survift(fit1)
summary(my.fit)
Unfortunately, the estimates shown do not match those of SAS.
-- End inclusion
You need to add a newdata=test2 argument to the survfit call. Like the
SAS code, test2 is a data set containing the list of subjects for which
you want an estimate. You can also add a times= argument to the summary
function.
Last, if you look at the documentation you will see that the default
handling for ties in the baseline hazard is the Fleming-Harrington
method in R, whenever the "Efron" approx was used in computing the
coefficients. (Same approximation, 2 different names when used in the
two contexts, for more details see the chapter in my book). The "CH" or
Aalen approx for a baseline hazard is the same math as the Breslow
approx for the coefficients. So to match the chimeric mixture you used
in the SAS code you will need to add type="aalen" to the survfit call.
The numeric effect of this is usually neglible, but when I see "do not
match" in a query I assume you are looking to have all the digits the
same.
As to competing risks, I have some code for R but documentation is yet
to be done -- on my to do list. Walter Kremers
(kremers.walter at mayo.edu) has a nice SAS macro for this case, however.
You might want to drop him a line.
Terry Therneau
More information about the R-help
mailing list