Skip to content

Conversation

@Istalan
Copy link

@Istalan Istalan commented May 12, 2020

I hope this is the correct place for this, as this is my first time really using Github.

Pleasantries first: This is a wonderful package and i'm very thankful for having it.

The issue

The following Code produces empty plots:

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

also it generates the following warning:

 Warning messages:
1: In ggcoxdiagnostics(fit, 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).

I could not find an issue for this problem, but it was also described here:
https://community.rstudio.com/t/ggcoxdiagnostics-warning-message/51867

My understanding of the problem and my solution

The introduction of NAs by Coercion happens in current line 92

xval <- as.numeric(rownames(res))

with res being defined by

res <- as.data.frame(resid(fit, type = type))

While resid(fit, type = type) returns an object with rownames that correspond to the sorted event-times, if the rownames are not unique the casting to data.frame will make them:

raw_res <- resid(fit, type = "schoenfeld")
res <- as.data.frame(raw_res)
rownames(raw_res)[1:4]
rownames(res)[1:4]

The rownames of the data.frame then can't be converted to numeric. My Solution is to just keep the initial result raw_res <- resid(fit, type = "schoenfeld") to initiate xval.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant