rrms

a problem about error in cph of R code: object 'n' not found"


I am trying to generate a nomogram with the following R code and keep on getting error for the last line. The error message says "Error in cph(Surv(futime, fustat) ~ ., x = T, y = T, surv = T, data = rt, : object 'n' not found". Could anyone please help? Thanks in advance.

library(rms)
setwd("C:\\Users\\yue\\Desktop\\04.diff")                  
rt=read.table("risk.txt",sep="\t",header=T,row.names=1,check.names=F)   
rt=rt[c(1:(ncol(rt)-2))] 

dd <- datadist(rt)
options(datadist="dd")

f <- cph(Surv(futime, fustat) ~ ., x=T, y=T, surv=T, data=rt, time.inc=1)

Solution

  • We can create the Surv object as

    s1 <- Surv(rt$futime, rt$fustat)
    f <- cph(s1 ~ FOXM1 + IGF2BP3, x=TRUE, y=TRUE, surv=TRUE, data=rt, time.inc=1)
    

    -output

    f
    Cox Proportional Hazards Model
     
     cph(formula = s1 ~ FOXM1 + IGF2BP3, data = rt, x = TRUE, y = TRUE, 
         surv = TRUE, time.inc = 1)
     
                            Model Tests    Discrimination    
                                                  Indexes    
     Obs       232    LR chi2     49.90    R2       0.231    
     Events     43    d.f.            2    Dxy      0.550    
     Center 1.0881    Pr(> chi2) 0.0000    g        1.019    
                      Score chi2  70.81    gr       2.771    
                      Pr(> chi2) 0.0000                      
     
             Coef   S.E.   Wald Z Pr(>|Z|)
     FOXM1   0.0812 0.0174 4.65   <0.0001 
     IGF2BP3 0.1426 0.0303 4.70   <0.0001