3

I'm trying to use survminer to create an adjusted survival curve with ggadjustedcurves(). My code is as follows:

adjustedcurve <- coxph(Surv(time_DeathTxCensor, deadORtx==1) ~ strata(natADI_quart) + sex + FVCpctPre + DLCOpctPre + smokeHx + age_dx, data=ADI, id=ID)
ggadjustedcurves(adjustedcurve,
                 variable="natADI_quart",
                 method="conditional",
                 data=ADI)

And I am getting the error message:

Error in if (xi > xj) 1L else -1L : missing value where TRUE/FALSE needed

Also here is my traceback:

16. .gt(structure(c(1L, 3L, 2L, 4L), .Label = c("1", "2", "3", "4" ), class = "factor"), 1L, 2L)
15. rank(x, ties.method = "min", na.last = "keep")
14. as.vector(rank(x, ties.method = "min", na.last = "keep"))
13. xtfrm.default(x)
12. xtfrm(x)
11. as.vector(xtfrm(x))
10. FUN(X[[i]], ...)
9. lapply(z, function(x) if (is.object(x)) as.vector(xtfrm(x)) else x)
8. order(x, na.last = na.last, decreasing = decreasing)
7. `[.tbl_df`(x, order(x, na.last = na.last, decreasing = decreasing))
6. x[order(x, na.last = na.last, decreasing = decreasing)]
5. sort.default(unique(data[, variable]))
4. sort(unique(data[, variable]))
3. ggadjustedcurves.conditional(data, fit, variable, size = size)
2. surv_adjustedcurves(fit = fit, variable = variable, data = data, reference = reference, method = method, size = size, ...)
1. ggadjustedcurves(adjustedcurve, data = ADI)

I have no idea what this means or how to fix it. Would really appreciate any help :)

Werner Hertzog
  • 2,002
  • 3
  • 24
  • 36
gcgoobie
  • 53
  • 2

1 Answers1

3

The problem arises in the survminer adjusted curves functions, where it is trying to sort the unique levels of a factor variable by indexing from the data set using the variable name.

This throws an error.

If you're comfortable editing the functions in the package, you can retrieve them from here: https://github.com/kassambara/survminer/blob/master/R/ggadjustedcurves.R

.. and fix the bug by replacing the three occurrences of:

lev <- sort(unique(data[,variable]))

with

lev <- sort(unique(pull(data, variable)))

Hope this helps.

Matt
  • 41
  • 4
  • Oops sorry this should have been a comment – Matt Dec 02 '20 at 12:16
  • OK I went through the code and made these changes, but when I run the code I'm now getting the following error: _Error in .get_data(fit, data) : could not find function ".get_data"_ I'm not totally clear if this is in a package that I don't already have downloaded or not..? – gcgoobie Dec 02 '20 at 16:43
  • 1
    Ah that's a helper function – you can grab it from the utilities script: https://github.com/kassambara/survminer/blob/master/R/utilities.R – Matt Dec 03 '20 at 00:05
  • I had the same issue with 'ggadjustedcurve' and was able to solve it using the answer and comment of @Matt! Thanks a lot! – fbeese Nov 29 '22 at 11:18