[R] Predicted Cox survival curves - factor coding problems...

From: <sally.x.wetten_at_gsk.com>
Date: Fri, 04 May 2007 11:24:54 +0100


I am trying to use the survfit() function with the newdata argument to produce predicted survivor curves for a particular covariate profile.

The main purpose of the plot will be to visualise the effect of snp1, coded 0 and 1. In my Cox model I have stratified by one variable, edu, and so I know I will automatically get a separate curve for each strata. My problem is how to deal with the variable sitenew, which is a 3 level factor (coded 0,1,2).

coxsnps$edu <- as.factor(coxsnps$edu)
coxsnps$sitenew <- as.factor(coxsnps$sitenew)

test1 <- coxph(Surv(time,censor) ~ snp1 + sex + sitenew + geno + eth_self + strata(edu), data=coxsnps)

                        coef exp(coef) se(coef)      z       p
        snp1             -0.4324     0.649   0.1073 -4.031 5.5e-05
        sex           0.0604     1.062   0.0915  0.660 5.1e-01
        sitenew1      0.5128     1.670   0.1381  3.712 2.1e-04
        sitenew2      0.2688     1.308   0.1313  2.047 4.1e-02
        geno          0.9702     2.639   0.0663 14.630 0.0e+00
        eth_self      0.0871     1.091   0.1088  0.801 4.2e-01


profile1 <- data.frame(snp1=factor(c(0,1), levels=c("0", "1")), sex=0, 
sitenew=0, geno=0, eth_self=0)
plot(survfit(test1, newdata=profile1))

Putting sitenew=0 in the dataframe produces the error

        Error in x2 %*% coef : non-conformable arguments

implying the rows and columns of the matrices don't match up. This makes sense as R creates dummy variables for sitenew. I naively tried using sitenew1=0, sitenew2=0 in the dataframe instead, which produced the same error message.

Is there a way to produce curves by edu and snp1 but just one level of sitenew?

If not, what would be the procedure for producing curves for all of them
(for reference)?

Many thanks,
Sally



This e-mail was sent by GlaxoSmithKline Services Unlimited
(registered in England and Wales No. 1047315), which is a
member of the GlaxoSmithKline group of companies. The registered address of GlaxoSmithKline Services Unlimited is 980 Great West Road, Brentford, Middlesex TW8 9GS.

        [[alternative HTML version deleted]]



R-help_at_stat.math.ethz.ch 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. Received on Fri 04 May 2007 - 10:35:24 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 04 May 2007 - 11:31:50 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.