rpredictionsurvival-analysiscox-regression

When plotting the predicted results from a svycoxph object, how can you tell which curve is which?


I used svycoxph from the survey package to create an object based on a complex survey design:

object <- svycoxph(Surv(time, status) ~ group, design=design)

And then I used predict() as documented here on page 88 to predict curves and plot them:

prediction <- predict(object, type="curve", newdata = data.frame(group=c("A", "B")) )

plot(prediction[[1]],ci=FALSE,col="sienna") 
lines(prediction[[2]],ci=FALSE,col="royalblue")

My group variable is a factor with levels A and B. Is list 1 A and list 2 B? I assumed this was the case, but the results are the opposite of what I expected. When I open the object in the source pane, there is no labeling beyond list 1 and 2 (no A or B labeled anywhere).

Is there any way the curves got flipped? Are the results possibly listed alphabetically instead of in factor order?


Solution

  • Here is my solution, I didn't get any errors for having only one level. I am using the example in survey and just modified the predict statement.

    library(survey)
    library(survival)
     
     data(pbc, package="survival")
     pbc$randomized<-with(pbc, !is.na(trt) & trt>0)
     biasmodel<-glm(randomized~age*edema,data=pbc,family=binomial)
     pbc$randprob<-fitted(biasmodel)
     if (is.null(pbc$albumin)) pbc$albumin<-pbc$alb ##pre2.9.0
     dpbc<-svydesign(id=~1, prob=~randprob, strata=~edema, data=subset(pbc,randomized))
     rpbc<-as.svrepdesign(dpbc)
     
     (model<-svycoxph(Surv(time,status>0)~log(bili)+protime+albumin,design=dpbc))
     svycoxph(Surv(time,status>0)~log(bili)+protime+albumin,design=rpbc)
     s1<-predict(model,se=TRUE, type="curve",
                newdata=data.frame(bili=c(3), protime=c(10), albumin=c(3.5)))
     s2<-predict(model,se=TRUE, type="curve",
                 newdata=data.frame(bili=c(9), protime=c(10), albumin=c(3.5)))