Ali MN
Ali MN

Reputation:

External validation of a Cox model using rcorr.cens() and val.surv

I have two independent datasets one with 5421 and the other 1000 subjects. What I would like to do is validate the Cox model obtained from the main dataset (main_dat, n=5421) using the external dataset (test_dat, n=1000). However, I get an error message using both rcorr.cens() in the Hmisc package and val.surv in rms. Here is what I have been doing:

library(rms)
surv.obj=with(main_dat,Surv(survival,surv_cens))  ## to use with rcorr.cens
phmodel=cph(surv.obj~sex+age+treatment, x=TRUE, y=TRUE, surv=T, time.inc=10, data=main_dat, se.fit=T)

estimates=survest(phmodel, newdata=test_dat, times=10)

rcorr.cens(x=estimates, S=surv.obj)

Error in rcorr.cens(x = estimates, S = surv.obj) : y must have same length as x

w=val.surv(phmodel ,newdata=test_dat, u=10)

Error in val.surv(phmodel, newdata = test_dat, u = 10) : dims [product 1000] do not match the length of object [5421] In addition: Warning message: In est.surv + S[, 1] : longer object length is not a multiple of shorter object length

Am I doing something wrong or the two datasets must have same number of observations?

Any help will be greatly appreciated.

Upvotes: 0

Views: 1509

Answers (1)

Frank Harrell
Frank Harrell

Reputation: 2230

I don't see where test_dat has surv.obj defined. You'll either need to add that to test_dat or have a free-standing object surv.obj that is used in the calls.

Note that your sample sizes are not large enough for split-sample validation, i.e., if you re-split the sample multiple times you will get disagreements in the result. Rigorous bootstrap internal validation (using the rms package validate and calibrate functions) is usually more precise.

Upvotes: 1

Related Questions