Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ggcoxdiagnostics.R, fix for ox.scale = "time" and non unique eventtimes #468

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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