calibration curve for cph()
On Aug 16, 2011, at 1:57 PM, array chip wrote:
Dear Frank, Thanks for suggesting val.surv() function from rms package. It's exactly what I need. I tried the example on the help page and tweak towards to my situation, but got an error message. Could you suggestion what went wrong?
It is interesting that neither my mail client nor the archives show the code that was sent to nabble. For posterity it was require(rms) ?val.surv
library(rms)
set.seed(123) # so can reproduce results
n <- 1000
age <- 50 + 12*rnorm(n)
sex <- factor(sample(c('Male','Female'), n, rep=TRUE, prob=c(.6, .4)))
cens <- 15*runif(n)
h <- .02*exp(.04*(age-50)+.8*(sex=='Female'))
t <- -log(runif(n))/h
units(t) <- 'Year'
label(t) <- 'Time to Event'
ev <- ifelse(t <= cens, 1, 0)
t <- pmin(t, cens)
S <- Surv(t, ev)
f <- cph(S ~ age + sex, x=TRUE, y=TRUE)
val.surv(f, newdata=data.frame(age,sex), S=S, u=5) ## pretend the
same training data as the independent dataset
Unable to reproduce. I get sensible output. You may need to post sessionInfo(). Do you have all the dependencies installed? I noticed that even after rms was loaded with messages about also loading Hmisc, survival, and splines, that there was a further message saying polspline was being loaded.
Error in val.surv(f, newdata = data.frame(age, sex), S = S, u = 5) : unused argument(s) (u = 5)
david. > sessionInfo() R version 2.13.1 RC (2011-07-03 r56263) Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit) locale: [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] splines stats graphics grDevices utils datasets methods base other attached packages: [1] polspline_1.1.5 rms_3.3-1 Hmisc_3.8-3 survival_2.36-9 [5] TTR_0.20-3 xts_0.8-0 zoo_1.6-5 sos_1.3-0 [9] brew_1.0-6 lattice_0.19-30 loaded via a namespace (and not attached): [1] cluster_1.14.0 grid_2.13.1 tools_2.13.1 > > ----- Original Message ----- > From: Frank Harrell <f.harrell at vanderbilt.edu> > To: r-help at r-project.org > Cc: > Sent: Tuesday, August 16, 2011 4:23 AM > Subject: Re: [R] calibration curve for cph() > > > > David Winsemius wrote: >> >> A combination of Predict (your newdata), cut2, and the plotting >> function >> of your choice ought to suffice. But thought that cross-validation >> was an >> option. Not at console at the moment (just off airplane.) >> >> Sent from my iPhone >> >> On Aug 15, 2011, at 5:26 PM, array chip >> <arrayprofile at yahoo.com> >> wrote: >> >>> is there a R function that produces calibration curve on an >>> independetn >>> data automatically, just like what calibrate() does on the >>> training data >>> itself? >>> >>> Thanks >>> >>> John >>> >>> From: Comcast <dwinsemius at comcast.net> >>> To: array chip <arrayprofile at yahoo.com> >>> Cc: "r-help at r-project.org" <r-help at r-project.org> >>> Sent: Monday, August 15, 2011 2:04 PM >>> Subject: Re: [R] calibration curve for cph() >>> >>> Build a prediction function using 'Function' that gets applied to >>> set2. >>> Calibrate and validate. >>> >>> -- >>> David >>> >>> Sent from my iPhone >>> >>> On Aug 15, 2011, at 11:31 AM, array chip >>> <arrayprofile at yahoo.com> >>> wrote: >>> >>>> Hi, the calibrate.cph() function in rms package generate >>>> calibration >>> curve for Cox model on the same dataset where the model was >>> derived using >>> bootstrapping or cross-validation. If I have the model built on >>> dataset >>> 1, and now I want to produce a calibration curve for this model on >>> an >>> independent dataset 2, how can I do that? >>>> >>>> Thanks >>>> >>>> John David Winsemius, MD West Hartford, CT