Stephen,
I can almost but not quite get my arms around what you are asking. A bit
more detail
would help. Like
cph.approve = what kind of object, generated by function __
But, let me make a guess:
cph is the result of coxph, and the model has both covariates and a strata
You want predictioned survival curves, more than 1, of the type
"covariates = a, b,c,
strata=1" "covariates = d,e, f, strata=2", ... for arbitrary
covariates and strata.
Now, the predicted survival curves for different strata are different lengths.
The survfit.coxph routine gets around this by being verbose: it expects you to
give it
covariate sets, and returns
all of the strata for each covariate. This allows it to give a compact result.
You can
always do:
newpred <- survfit(cox-model-fit, newdata=something)
newpred[5,17] # survival curve for the 5th strata, covariates from the 17th
row of
newdata
But, you want to put the results into a matrix, for some pre-specifed set of
time points.
Take it one step further.
mytimepoints <- seq(0, 5*365, by=30) # every 30 days
z <- summary(newpred[5,17], time=mytimepoints, extend=TRUE)$surv
The summary.survfit function's "time" argument was originally
written for people who only
wanted to print certain time points, but it works as well for those who only
want to
extract certain ones. It correctly handles the fact that the curve is a step
function.
Terry Therneau
On 02/01/2013 05:00 AM, r-help-request at r-project.org
wrote:> What is the syntax to obtain survival curves for single strata on many
subjects?
>
> I have a model based on Surv(time,response) object, so there is a single
row per subject and no start,stop and no switching of strata.
>
> The newdata has many subjects and each subject has a strata and the
survival based on the subject risk and the subject strata is needed.
>
> If I do
>
> newpred<- survfit(cph.approve,new=newapp,se=F)
>
> I get all strata for every subject.
>
> Attempting
>
>> > newpred<- survfit(cph.approve,new=newapp,id=CertId,se=F)
> Error in survfit.coxph(cph.approve, new = newapp, id = CertId, se = F) :
> The individual option is only valid for start-stop data
>> > newpred<- survfit(cph.approve,new=newapp,indi=T,se=F)
> Error in survfit.coxph(cph.approve, new = newapp, indi = T, se = F) :
> The individual option is only valid for start-stop data
>
> Please, advise if obtaining a single strata for a basic (time,response)
model is possible? Due to differing lengths of the surv for different strata
this will not go in a "wide" data.frame without padding.
>
> Thanks everybody and have a great day.
>
> Stephen B
>