[R] predicting expected number of events using a coxph model
peter dalgaard
pdalgd at gmail.com
Sat Jun 30 10:31:05 CEST 2012
On Jun 29, 2012, at 23:56 , agittens wrote:
> I fit a coxph model:
>
> coxphfit <- coxph(Surv(sampledLifetime, !sampledCensoredQ) ~ curpbc6 +
> prevpbc6, sampledTimeSeries)
>
> Now I'm trying to predict the expected number of events using a new dataset.
> The documentation suggests that
>
> coxPred <- predict(coxphfit, newdata = testTimeSeries, type="expected")
>
> will do what I want, but I get the error
>
> Error in model.frame.default(data = testTimeSeries, formula =
> Surv(sampledLifetime, :
> variable lengths differ (found for 'curpbc6')
>
> when I do this. The dataframes sampledTimeSeries and testTimeSeries were
> constructed by taking rows from a larger dataframe, so they have the same
> data.
>
> What am I doing incorrectly?
Most likely referring to a variable not in testTimeSeries. (I kind of suspect that unlike predict.lm, predict.coxph does not ignore the left hand side of formulas. Does testTimeSeries contain a sampledLifetime column?)
--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
More information about the R-help
mailing list