[R] Problems with coxph and survfit in a stratified model with interactions
Chris Andrews
chrisaa at umich.edu
Mon Oct 15 16:30:16 CEST 2012
rm wrote
> I’m trying to set up proportional hazard model that is stratified with
> respect to covariate 1 and has an interaction between covariate 1 and
> another variable, covariate 2. Both variables are categorical. In the
> following, I try to illustrate the two problems that I’ve encountered,
> using the lung dataset.
>
> The first problem is the warning:
>
> To me, it seems that there are too many dummies generated.
>
> The second problem is the error:
Adding the main effect of cov2 allows the model to run
library(survival)
lung$cov1 <- factor(lung$ph.ecog, 0:3, c("zero","one","two","three"))
lung$cov2 <- factor(lung$sex, 1:2, c("male","female"))
sCox <- coxph(Surv(time, status) ~ strata(cov1) + cov2 + cov1:cov2,
data=lung)
df <- data.frame(
cov1=factor(0:3, 0:3, c("zero","one","two","three"))[1],
cov2=factor(1:2, 1:2, c("male","female"))[1]
)
df
sfCox <- survfit(sCox, newdata=df)
plot(sfCox[1], conf=FALSE)
lines(sfCox[2], col=2)
lines(sfCox[3], col=3)
lines(sfCox[4], col=4)
--
View this message in context: http://r.789695.n4.nabble.com/Problems-with-coxph-and-survfit-in-a-stratified-model-with-interactions-tp4646096p4646241.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list