ggcoxdiagnostics warning message

Hi
I try to use function ggcoxdiagnostics() plots with a parametr ox.scale="time" as provided in survminer cheatsheet

library("survival")
library("survminer")
fit <- coxph(Surv(time, status) ~sex + age, data = lung)
ggcoxdiagnostics(fit, type = "schoenfeld", ox.scale = "time")

And here screenshot from sheet that I would be expected
image

And here what I really get, with message in console:

Warning messages:
1: In ggcoxdiagnostics(fit_l, type = "schoenfeld", ox.scale = "time") :
NAs introduced by coercion
2: Removed 330 rows containing non-finite values
(stat_smooth).
3: Removed 330 rows containing missing values
(geom_point).

So what wrong? (expect using parametr ecog.ps)

The syntax is right

library("survival")
library("survminer")
#> Loading required package: ggplot2
#> Loading required package: ggpubr
#> Loading required package: magrittr
lung %>% head(30) -> short_lung
fit <- coxph(Surv(time, status) ~sex + age, data = short_lung)
ggcoxdiagnostics(fit, type = "schoenfeld", ox.scale = "time")

Created on 2020-02-06 by the reprex package (v0.3.0)

So, it must be the rest of the data. Removing age works

library("survival")
library("survminer")
#> Loading required package: ggplot2
#> Loading required package: ggpubr
#> Loading required package: magrittr
lung %>% dplyr::select(time,status,sex,age) -> lung_trim
fit <- coxph(Surv(time, status) ~ sex, data = lung_trim)
ggcoxdiagnostics(fit, type = "schoenfeld", ox.scale = "time")

Created on 2020-02-06 by the reprex package (v0.3.0)

So, consider subsetting out age with NA

Still it's doesn solve problem, in lung database no NA in Age

1 Like

Hi!

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

sapply(lung, function(x) sum(is.na(x)))
sapply(lung, function(x) sum([is.na](http://is.na/)(x)))

Output:

inst      time    status       age       sex 
        1         0         0         0         0 
  ph.ecog  ph.karno pat.karno  meal.cal   wt.loss 
        1         1         3        47        14

so is no NA in "Age" in lung database (provided by survival package)
I just follow by survminer cheatsheet available here
So I still confusing why it's doesn't work

You're right, as I could have seen by summary(lung).

I noticed that while the cheatsheet did give the same code but didn't show the output.

I looked at the examples in help(ggcoxdiagnostics), one of which was

(coxph.fit2, type = "schoenfeld", ox.scale = "observation.id")

instead of ox.scale = "time")

So, I speculated that changing ox.scale to observation.id would plot, and it does. Now, I speculate that you can time order (but not necessarily scale) simply by sorting on time and get there, since observation.id will be sequential by time.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.