# [R] basehaz and newdata

mah harwood262 at gmail.com
Mon Apr 7 17:34:55 CEST 2008

```I am unable to get the basehaz function to apply a proportional
hazards model to a new data frame.  I replicated my specific situation
with the example for coxph in the help, where I changed the x value of
the first record from 0 to 1.  Is there something incorrect in the
syntax that I am using?  Thanks in advance!

test1 <- list(time=  c(4, 3,1,1,2,2,3),
status=c(1,NA,1,0,1,1,0),
x=     c(0, 2,1,1,1,0,0),
sex=   c(0, 0,0,0,1,1,1))
test2 <- list(time=  c(4, 3,1,1,2,2,3),
status=c(1,NA,1,0,1,1,0),
x=     c(1, 2,1,1,1,0,0),
sex=   c(0, 0,0,0,1,1,1))
f1 <- coxph( Surv(time, status) ~ x + strata(sex), data=test1)
#stratified model
f2 <- coxph( Surv(time, status) ~ x + strata(sex), data=test2)
#stratified model
f1
Call:
coxph(formula = Surv(time, status) ~ x + strata(sex), data = test1)

coef exp(coef) se(coef)     z    p
x 1.17      3.22     1.29 0.907 0.36

Likelihood ratio test=0.87  on 1 df, p=0.351  n=6 (1 observation
deleted due to missingness)
> f2
Call:
coxph(formula = Surv(time, status) ~ x + strata(sex), data = test2)

coef exp(coef) se(coef)    z    p
x 0.896      2.45     1.42 0.63 0.53

Likelihood ratio test=0.38  on 1 df, p=0.535  n=6 (1 observation
deleted due to missingness)
>
> basehaz(f1, newdata=test2)
Error in basehaz(f1, newdata = test2) :
unused argument(s) (newdata = list(time = c(4, 3, 1, 1, 2, 2, 3),
status = c(1, NA, 1, 0, 1, 1, 0), x = c(1, 2, 1, 1, 1, 0, 0), sex =
c(0, 0, 0, 0, 1, 1, 1)))
>

```