Max Shell
2018-Jan-17 16:24 UTC
[R] Assessing calibration of Cox model with time-dependent coefficients
I am trying to find methods for testing and visualizing calibration to Cox models with time-depended coefficients. I have read this nice article <journals.sagepub.com/doi/10.1177/0962280213497434>. 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]]
Bert Gunter
2018-Jan-17 18:21 UTC
[R] Assessing calibration of Cox model with time-dependent coefficients
1. Please repost in **plain text** as html can get mangled, as here (see below), on this plain text list. 2. Generally, statistical issues are off topic here. stats.stackexchange.com is one place to post such questions. Having said that, the intersection of statistics and (on topic) R coding is often nonempty, so you may wish to wait to see whether someone here satisfactorily answers your query before posting on Cross Validated. Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Wed, Jan 17, 2018 at 8:24 AM, Max Shell <archerrish at gmail.com> wrote:> I am trying to find methods for testing and visualizing calibration to Cox > models with time-depended coefficients. I have read this nice article > <journals.sagepub.com/doi/10.1177/0962280213497434>. 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 at r-project.org mailing list -- To UNSUBSCRIBE and more, see > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide R-project.org > posting-guide.html > and provide commented, minimal, self-contained, reproducible code.[[alternative HTML version deleted]]
Maybe Matching Threads
- Time-dependent coefficients in a Cox model with categorical variants
- coxreg vs coxph: time-dependent treatment
- how to check linearity in Cox regression
- anova.rq {quantreg) - Why do different level of nesting changes the P values?!
- questions on rpart (tree changes when rearrange the order of covariates?!)