2
$\begingroup$

I'm trying out the adjustedCurves package in R for estimating confounder adjusted survival curves, and I'm starting with the standard "lung" dataset demonstrated in the examples in http://www.sthda.com/english/wiki/cox-proportional-hazards-model.

When I run the below code against the "lung" dataset, such code based on the description provided in https://cran.rstudio.com/web/packages/adjustedCurves/vignettes/introduction.html for "Direct Standardization", I get the error message "Error in ate_checkArgs(call = call, object.event = object.event, object.censor = object.censor, : Cannot handle missing values in the model coefficients (event)". I've tried skipping over the NA fields using the na.action = ... in the adjustedsurv() parameters, I've tried replacing all NA values in the entire DF with 0's, but nothing seems to work. What am I doing wrong?

library(adjustedCurves)
library(ggplot2)
library(survival)
library(survminer)

head(lung) # check out lung dataset

lungMod <- lung %>% 
  mutate(event = status-1) %>%
  mutate(group = as.factor(sex-1))

outcomeModel <- survival::coxph(Surv(time, event) ~ age + sex + ph.ecog
                                + group, data= lungMod, x=TRUE)

adjSurvLung <- adjustedsurv(
  data = lungMod,
  variable = "group",
  ev_time = "time",
  event = "event",
  method = "direct",
  outcome_model = outcomeModel,
  conf_int = TRUE,
  na.action = "na.pass"
)

Corrected example using Denzo's solution:

outcomeModel <- survival::coxph(Surv(time, event) ~ age + ph.ecog
                                + group, data= lungMod, x=TRUE)

adjSurvLung <- adjustedsurv(
  data = lungMod,
  variable = "group",
  ev_time = "time",
  event = "event",
  method = "direct",
  outcome_model = outcomeModel,
  conf_int = TRUE,      
  na.action = "na.omit"
)

# look at Cox model by running the below; before Denzo's solution the group coefficient was all NA
outcomeModel

plot(adjSurvLung, conf_int=TRUE, linetype=TRUE)

Resulting plot: enter image description here

$\endgroup$

1 Answer 1

3
$\begingroup$

You misread the error message. It says Cannot handle missing values in the model coefficients, not that there are missing values in the dataset.

If you take a look at your Cox model, you will see that the model coefficient of the group variable is in fact NA. If any of the model coefficients are missing or infinite, the adjustedsurv function will be unable to perform the required calculations.

In this case, the reason for that NA value is that group is simply a different version of sex and you include both in the model formula. This is an extreme form of co-linearity (the variables are identical), which results in a missing coefficient. It can be easily fixed by omitting sex from the formula. Since you also do have missing data in your lungMod data set, you should also set na.action to na.omit or simply keep the argument on its default value.

I happen to be the developer of this package, so if you have any other questions I am happy to help.

$\endgroup$
1
  • 1
    $\begingroup$ I figured you might be the developer when I read through the package documentation! Thank you for the package and for the guidance! $\endgroup$ Commented Mar 27, 2023 at 10:00

Not the answer you're looking for? Browse other questions tagged or ask your own question.