I have a model with quant vars only and the error message does not make sense: (mod1 <- coxph(Surv(time=strt,time2=stp,event=(resp==1))~ +incpost+I(amt/1e5)+rate+strata(termfac), subset=dt<"2010-08-30", data=inc,method="efron")) Call: coxph(formula = Surv(time = strt, time2 = stp, event = (resp = 1)) ~ +incpost + I(amt/1e+05) + rate + strata(termfac), data = inc, subset = dt < "2010-08-30", method = "efron") coef exp(coef) se(coef) z p incpost 0.2563 1.292 0.02479 10.34 0.0e+00 I(amt/1e+05) -0.0532 0.948 0.00487 -10.92 0.0e+00 rate -0.0507 0.951 0.00945 -5.36 8.2e-08 Likelihood ratio test=295 on 3 df, p=0 n= 1192634> length(mod1$xlevels)[1] 0 # now calling survfit with just a few rows from the data> s1 <- survfit(mod1,newdata=inc[50050:50100,],se.fit=F,individual=T,type="aa")Error in `contrasts<-`(`*tmp*`, value = "contr.treatment") : contrasts can be applied only to factors with 2 or more levels> inc[50050:50100,]dt inc incpost strt stp resp rate amt p1 matfac termfac vol 50050 2009-02-05 0.00000 0.00 0 1 0 5.35 266833 C 5 3 14229571 50051 2009-02-06 -0.09575 0.00 1 2 0 5.35 266833 C 5 3 14229571 50052 2009-02-09 -0.03875 0.00 4 5 0 5.35 266833 C 5 3 14229571 50053 2009-02-10 0.00850 0.00 5 6 0 5.35 266833 C 5 3 14229571 50054 2009-02-11 0.00250 0.00 6 7 0 5.35 266833 C 5 3 14229571 50055 2009-02-12 -0.04725 0.00 7 8 0 5.35 266833 C 5 3 14229571 50056 2009-02-13 -0.00075 0.00 8 9 0 5.35 266833 C 5 3 14229571 50057 2009-02-16 -0.10425 0.00 11 12 0 5.35 266833 C 5 3 14229571 50058 2009-02-17 -0.10425 0.00 12 13 0 5.35 266833 C 5 3 14229571 50059 2009-02-18 -0.02925 0.00 13 14 0 5.35 266833 C 5 3 14229571 50060 2009-02-19 -0.01300 0.00 14 15 0 5.35 266833 C 5 3 14229571 50061 2009-02-20 -0.04075 0.00 15 16 0 5.35 266833 C 5 3 14229571 50062 2009-02-23 -0.03100 0.00 18 19 0 5.35 266833 C 5 3 14229571 50063 2009-02-24 0.01975 0.00 19 20 0 5.35 266833 C 5 3 14229571 50064 2009-02-25 0.13050 0.00 20 21 0 5.35 266833 C 5 3 14229571 50065 2009-02-26 0.12725 0.00 21 22 0 5.35 266833 C 5 3 14229571 ... further output truncated Please, comment if you see what's the issue. Thank you. Stephen [[alternative HTML version deleted]]
On Feb 3, 2011, at 2:14 PM, Bond, Stephen wrote:> I have a model with quant vars only and the error message does not > make sense: > > (mod1 <- coxph(Surv(time=strt,time2=stp,event=(resp==1))~ +incpost > +I(amt/1e5)+rate+strata(termfac), > subset=dt<"2010-08-30", data=inc,method="efron")) > Call: > coxph(formula = Surv(time = strt, time2 = stp, event = (resp => 1)) ~ +incpost + I(amt/1e+05) + rate + strata(termfac), data = inc, > subset = dt < "2010-08-30", method = "efron") > > > coef exp(coef) se(coef) z p > incpost 0.2563 1.292 0.02479 10.34 0.0e+00 > I(amt/1e+05) -0.0532 0.948 0.00487 -10.92 0.0e+00 > rate -0.0507 0.951 0.00945 -5.36 8.2e-08 > > Likelihood ratio test=295 on 3 df, p=0 n= 1192634 > >> length(mod1$xlevels) > [1] 0 > > # now calling survfit with just a few rows from the data >> s1 <- >> survfit >> (mod1,newdata=inc[50050:50100,],se.fit=F,individual=T,type="aa") > Error in `contrasts<-`(`*tmp*`, value = "contr.treatment") : > contrasts can be applied only to factors with 2 or more levelsI obviously cannot test my theory, but would have thought the call would be: s1 <- survfit(mod1, newdata=inc[50050:50100,], c("incpost", "amt, "rate", "termfac") ], se.fit=F,individual=T,type="aa") I.e., a data.frame for newdata that matched the variables used in the RHS of the formula.> >> inc[50050:50100,] > dt inc incpost strt stp resp rate amt p1 matfac > termfac vol > 50050 2009-02-05 0.00000 0.00 0 1 0 5.35 266833 C > 5 3 14229571 > 50051 2009-02-06 -0.09575 0.00 1 2 0 5.35 266833 C > 5 3 14229571 > 50052 2009-02-09 -0.03875 0.00 4 5 0 5.35 266833 C > 5 3 14229571 > 50053 2009-02-10 0.00850 0.00 5 6 0 5.35 266833 C > 5 3 14229571 > 50054 2009-02-11 0.00250 0.00 6 7 0 5.35 266833 C > 5 3 14229571 > 50055 2009-02-12 -0.04725 0.00 7 8 0 5.35 266833 C > 5 3 14229571 > 50056 2009-02-13 -0.00075 0.00 8 9 0 5.35 266833 C > 5 3 14229571 > 50057 2009-02-16 -0.10425 0.00 11 12 0 5.35 266833 C > 5 3 14229571 > 50058 2009-02-17 -0.10425 0.00 12 13 0 5.35 266833 C > 5 3 14229571 > 50059 2009-02-18 -0.02925 0.00 13 14 0 5.35 266833 C > 5 3 14229571 > 50060 2009-02-19 -0.01300 0.00 14 15 0 5.35 266833 C > 5 3 14229571 > 50061 2009-02-20 -0.04075 0.00 15 16 0 5.35 266833 C > 5 3 14229571 > 50062 2009-02-23 -0.03100 0.00 18 19 0 5.35 266833 C > 5 3 14229571 > 50063 2009-02-24 0.01975 0.00 19 20 0 5.35 266833 C > 5 3 14229571 > 50064 2009-02-25 0.13050 0.00 20 21 0 5.35 266833 C > 5 3 14229571 > 50065 2009-02-26 0.12725 0.00 21 22 0 5.35 266833 C > 5 3 14229571 > > ... further output truncated > > Please, comment if you see what's the issue. > Thank you. > Stephen > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.David Winsemius, MD West Hartford, CT
> I have a model with quant vars only and the error message does notmake sense: Could you tell us what version of S and of the survival package you are using? You can get this with sessionInfo(), see the posting guide for details. This would help me identify the issue. I was planning to post an update to CRAN this weekend that has changes to survfit.coxph, addressing a different issue than yours -- models with a strata by covariate interaction --- but this would be a very good time to address your issue too if it is a code bug. Terry Therneau (author of survival).
Responding to T. Therneau:> sessionInfo()R version 2.10.1 (2009-12-14) i386-pc-mingw32 locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C LC_TIME=English_United States.1252 attached base packages: [1] splines stats graphics grDevices utils datasets methods base other attached packages: [1] survival_2.35-8 Also:> s1 <- predict(mod1,newdata=inc[50050:50100,],+ type="expected") Error in predict.coxph(mod1, newdata = inc[50050:50100, ], type = "expected") : Method not yet finished Stephen -----Original Message----- From: Terry Therneau [mailto:therneau at mayo.edu] Sent: Friday, February 04, 2011 8:54 AM To: Bond, Stephen Cc: r-help at r-project.org Subject: Re: coxph fails to survfit> I have a model with quant vars only and the error message does notmake sense: Could you tell us what version of S and of the survival package you are using? You can get this with sessionInfo(), see the posting guide for details. This would help me identify the issue. I was planning to post an update to CRAN this weekend that has changes to survfit.coxph, addressing a different issue than yours -- models with a strata by covariate interaction --- but this would be a very good time to address your issue too if it is a code bug. Terry Therneau (author of survival).