[R] Time-dependent coefficients in a Cox model with categorical variants

Max Shell archerrish at gmail.com
Mon Jan 15 09:58:55 CET 2018

Suppose I have a dataset contain three variants, looks like
> head(dta)

  Sex    tumorsize    Histology       time         status
    0            1.5            2              12.1000             0
    1            1.8            1              38.4000             0

Sex: 1 for male; 0 for female., two levels
Histology: 1 for SqCC; 2 for High risk AC; 3 for low risk AC, three levels
Now I need to get a Time-dependent coefficients cox fit:

for(i in c(1,3) dta[,i] <- factor(dta[,i])
fit <-
    Surv(time, status) ~  Sex + tumorsize +  Histology + tt(Histology),
    data = dta,
    tt = function(x, t, ...) x * log(t)

But  I keep gettting this error says:

Error in if (any(infs)) warning(paste("Loglik converged before variable ",  :
  missing value where TRUE/FALSE needed
In addition: Warning message:
In Ops.factor(x, log(t)) : ‘*’ not meaningful for factors.

How can I fix it? I know that the "Sex" and "Histology" are both
categorical variants. I  want to have a model that have two β(t) = a +
blog(t) for each histology level.
Thank you!

More information about the R-help mailing list