1

I'm using a Cox Proportional Hazards (survival::coxph) model in a competing risks context- i.e. multiple event types with one endpoint for each observation. I'm having a hard time using the coxph.predict function to show an estimate of expected number of events given a supplied set of covariates and follow-up time. Here is an example using the mgus2 dataset in the survival package:

library(survival)

#Modify data so each subject transitions only once to a state.
crdata <- mgus2
crdata$etime <- pmin(crdata$ptime, crdata$futime)
crdata$event <- ifelse(crdata$pstat==1, 1, 2*crdata$death)
crdata$event <- factor(crdata$event, 0:2, c("censor", "PCM", "death"))

cfit <- coxph(Surv(etime, event) ~ I(age/10) + sex + mspike,
              id = id, crdata)

Once I fit a model, and create a "newdata" data frame, R throws an error.

I tried using a from-scratch dataframe but this results in an error suggesting that the column size or the number of rows does not mesh:

#providing both follow-up time and covariates
nd=data.frame(etime=81 ,sex= "M", age=60, mspike=1.2)
predict(cfit, newdata=nd ,type="expected")

> Data is not the same size as it was in the original fit

I get the same issue Using model.frame when extracting the same data.frame used fitting the model.

nd=model.frame(cfit)
predict(cfit,newdata=nd,type="expected")

> Data is not the same size as it was in the original fit

This results in the same error. Trying to use the original data frame to make predictions doesn't work either:

nd=crdata[1,]
predict(cfit,newdata=nd,type="expected")

> Data is not the same size as it was in the original fit

I'm wondering what I'm missing here. Thanks in advance!

2
  • It's counter-intuitive, but you need to add events to your prediction data frame. These will be ignored in the output. Commented Jun 14, 2022 at 18:16
  • @AllanCameron Thanks for the response! Based on your advice, I tried nd=data.frame(etime=81, event =factor("PCM"),sex= "M", age=60, mspike=1.2) predict(cfit,newdata=nd,type="expected") But it returned the same error. I don't suppose you might be able to give an example? Commented Jun 14, 2022 at 20:01

1 Answer 1

0

I've updated my survival package from 2.7 to 3.1 and the error thrown states that "expected" predict type is not available for multistate coxph.

> predict(fit,type="expected",newdata=newdat)
Error in predict.coxphms(fit, type = "expected", newdata = newdat) : 
  predict method not yet available for multistate coxph
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.