[R] Problems with coxph and survfit in a stratified model with interactions
rm
rm at wippies.se
Mon Oct 15 17:09:56 CEST 2012
Dear Terry,
Thanks for your valuable comments! Could you please restate the example that
you refer to? If I include cov1 in the data frame, as you suggest, I get the
following error message. Complete code follows.
” Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :
contrasts can be applied only to factors with 2 or more levels"
Regarding Chris’s suggestion, I would prefer not to have the main effect of
cov2 in the model. I would prefer to stick with “~ strata(cov1):cov2” to
keep the interpretation of the regression coefficient straightforward.
Best regards,
Roland
require(survival)
data(lung)
#
lung$cov1 <- as.factor(lung$ph.ecog)
lung$cov2 <- as.factor(lung$sex)
levels(lung$cov1)[levels(lung$cov1)==0] <- "zero"
levels(lung$cov1)[levels(lung$cov1)==1] <- "one"
levels(lung$cov1)[levels(lung$cov1)==2] <- "two"
levels(lung$cov1)[levels(lung$cov1)==3] <- "three"
levels(lung$cov2)[levels(lung$cov2)==1] <- "male"
levels(lung$cov2)[levels(lung$cov2)==2] <- "female"
#
df <- data.frame(
cov1=factor("one", levels = levels(lung$cov1)),
cov2=factor("female", levels = levels(lung$cov2))
)
sCox <- coxph(Surv(time, status) ~ strata(cov1):cov2, data=lung)
sfCox <- survfit(sCox,newdata=df)
--
View this message in context: http://r.789695.n4.nabble.com/Problems-with-coxph-and-survfit-in-a-stratified-model-with-interactions-tp4646096p4646245.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list