Comments

Comment

Visitor
Avatar
At my former question from 06/25/2018 at 09h19:
I figured out that I need to type in the data argument another time in ggsurvplot in order to avoid the error "The `data` argument should be provided either to ggsurvfit or survfit."

The resulting code is:
res.cox <- coxph(Surv(time, status) ~ age + sex + ph.ecog, data = lung)
sex_df <- with(lung,
data.frame(sex = c(1, 2),
age = rep(mean(age, na.rm = TRUE), 2),
ph.ecog = c(1, 1)
)
)

fit <- survfit(res.cox, newdata = sex_df)
ggsurvplot(fit, data = sex_df, conf.int = TRUE,
legend.labs=c("Sex=1", "Sex=2"),
ggtheme = theme_minimal())

Using this code gives me the plot provided in the tutorial.

Comment

Visitor
Avatar
Thank you for this great tutorial!
Unfortunately, I get the following error when running the provided code:
"The `data` argument should be provided either to ggsurvfit or survfit."

All I did was copy and paste this code from the tutorial:
res.cox <- coxph(Surv(time, status) ~ age + sex + ph.ecog, data = lung)
sex_df <- with(lung,
data.frame(sex = c(1, 2),
age = rep(mean(age, na.rm = TRUE), 2),
ph.ecog = c(1, 1)
)
)
fit <- survfit(res.cox, newdata = sex_df)
ggsurvplot(fit) # This is where I get the error mentioned above.

Comment

Visitor
Avatar
Decent tutorial, but could do with some explanation on how to handle categorical variables with more than 2 possible options.

Comment

Visitor
Avatar
Dear sir:
Really thankful for u code.
I make some revise of ur code when doing cox regression model for several ordered categorical variable in one time. I want the output including every level of every variable. But it seems not working for me.
> univ_results_factor_cancerdeath <- lapply(univ_models_factor_cancerdeath,
+ function(x){
+ x <- summary(x)
+ a <- c(1)
+ while (a<=c(nrow(x$coefficients))) {
+ row <- row.names(x$coefficients)[a]
+
+ p.value<-signif(x$coefficients[a,5],digits=2)
+
+ wald.test<-signif(x$waldtest[1], digits=2)
+
+ HR <-signif(x$conf.int[a,1], digits=2);#exp(beta)
+ HR.confint.lower <- signif(x$conf.int[a,3], 2)
+ HR.confint.upper <- signif(x$conf.int[a,4],2)
+ HR <- paste0(HR, " (",
+ HR.confint.lower, "-", HR.confint.upper, ")")
+ m <- data.frame(row, p.value, wald.test, HR)
+ names(m)<-c("rowname", "p.value", "wald.test","HR (95% CI for HR)")
+ univ_facr <- rbind(univ_factor,m)
+ a <- a+1
+ }
+ })
>
> univ_factor
Would u mind doing me a favor?
Best regards.
Timmy

Comment

Administrator
Avatar
It works for me, thanks.

Comment

Visitor
Avatar
Thank you for a nice walk-through of a Cox regression example. Very useful and easy on the non-statisticians.

Could you please check the website for missing mathematical expressions? It seems to me that whenever there is referenced to estimates and functions the spaces are blank.

Comment

Visitor
Avatar
How about "ph.karno"? (p-value: 0.005)

Comment

Administrator
Avatar
Oh sorry, this is a mistake.

The correct phrase is "the variables sex, age and ph.ecog have highly statistically significant coefficients, while the coefficient for wt.loss is not significant."

I will update the article accordingly.

Thank you for pointing this out.

Comment

Visitor
Avatar
Hi,

Given the values, I was not able to understand the phrase

"The variables sex, age and ph.ecog have highly statistically significant coefficients, while the coefficient for ph.karno is not significant." Why would "ph.karno", which has a p-val of 0.005 be insignificant?

Could you please elaborate more on this?

Thanks

E

age: 0.042
sex: 0.0015
ph.karno: 0.005
ph.ecog: 2.7e-05
wt.loss: 0.83