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

2018-01-15 Thread Max Shell
Suppose I have a dataset contain three variants, looks like
> head(dta)

  SextumorsizeHistology   time status
01.52  12.1000 0
11.81  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:

library(survival)
for(i in c(1,3) dta[,i] <- factor(dta[,i])
fit <-
  coxph(
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!

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

[R] Assessing calibration of Cox model with time-dependent coefficients

2018-01-17 Thread Max Shell
I am trying to find methods for testing and visualizing calibration to Cox
models with time-depended coefficients. I have read this nice article
. In this paper,
we can fit three models:

fit0 <- coxph(Surv(futime, status) ~ x1 + x2 + x3, data = data0) p <-
log(predict(fit0, newdata = data1, type = "expected")) lp <- predict(fit0,
newdata = data1, type = "lp") logbase <- p - lp fit1 <- glm(y ~ offset(p),
family = poisson, data = data1) fit2 <- glm(y ~ lp + offset(logbase),
family = poisson, data = data1) group <- cut(lp, c(-Inf, quantile(lp, (1:9)
/ 10), Inf)) fit3 <- glm(y ~ -1 + group + offset(p), family = poisson, data
= data1)

Here,I simplely use data1 <- data0[1:500,]
First, I get following error when running line 5.

Error in eval(predvars, data, env) : object 'y' not found

So I modifited the code by replacing the y as status looks like this:

fit1 <- glm(status ~ offset(p), family = poisson, data = data1) fit2 <-
glm(status ~ lp + offset(logbase), family = poisson, data = data1) group <-
cut(lp, c(-Inf, quantile(lp, (1:9) / 10), Inf)) fit3 <- glm(status ~ -1 +
group + offset(p), family = poisson, data = data1)

*Is this replacing correct?*
Second, I try to introduce the time-transform use coxph with ttparament.

My code is:  fit0 <- coxph(Surv(time, status) ~ x1 + x2 + x3 + tt(x3), data
= data0, function(x, t, ...) x * t) p <- log(predict(fit0, newdata = data1,
type = "expected")) lp <- predict(fit0, newdata = data1, type = "lp")
logbase <- p - lp fit1 <- glm(status ~ offset(p), family = poisson, data =
data1) fit2 <- glm(status ~ lp + offset(logbase), family = poisson, data =
data1) group <- cut(lp, c(-Inf, quantile(lp, (1:9) / 10), Inf)) fit3 <-
glm(status ~ -1 + group + offset(p), family = poisson, data = data1)
My questions is:

   - Is the code above correct?
   - How to interpret the fit1, fit2, fit3? What's the connection between
   the three models and the calibration of the Cox model?
   - How to generate the calibration plot using fit3? The article dose have
   a section discuss this, but no code is provided.

Thank you!

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.