Recently I have used the R package gtsummary to create univariable and multivariable models using coxph in gtsummary,but there is the following error:
add_global_p: Global p-values for variable(s) add_global_p(include = c("Age", "Gender", "Path_T", "Path_N", "Path_M", "Path_stage", "TP53")) were calculated
with
car::Anova(x$model_obj, type = "III")
x add_global_p() uses car::Anova() to calculate the global p-value,
and the function returned an error while calculating the p-values.
Is your model type supported by car::Anova()?
Error in df.terms.default(mod) : Model has aliased term(s); df ambiguous.
My code is below,
library(gtsummary)
data<-read.table("patient_data.txt",sep="\t",header=T)
data1<-na.omit(data)
library(survival)
tbl_uvsurv <- select(data1,everything()) %>%
tbl_uvregression(
method=coxph,
y=Surv(Time,Status),
exponentiate=TRUE
) %>%
add_global_p() %>%
bold_p(t=0.05)%>%
bold_labels()
library(survival)
tbl_mvsurv <-coxph(
Surv(Time,Status) ~.,
data=data1
) %>%
tbl_regression(
exponentiate=TRUE
) %>%
add_global_p() %>%
bold_p(t=0.05)%>%
bold_labels()
We can best answer your question when you provide a reproducible example, meaning providing code we can run on our machines utilizing a publicly available dataset (or a simulated data set). Below are two examples: one of a multivariable model and one a table of univariable models.
library(survival)
#> Warning: package 'survival' was built under R version 4.1.1
library(gtsummary)
packageVersion("gtsummary")
#> [1] '1.4.2'
# multivariable model
tbl1 <-
coxph(Surv(ttdeath, death) ~ age + trt, trial) %>%
tbl_regression(exponentiate = TRUE) %>%
add_global_p()
#> add_global_p: Global p-values for variable(s) `add_global_p(include = c("age",
#> "trt"))` were calculated with
#> `car::Anova(x$model_obj, type = "III")`

# univariable model
tbl2 <-
trial %>%
select(ttdeath, death, age, trt) %>%
tbl_uvregression(
y = Surv(ttdeath, death),
method = coxph,
exponentiate = TRUE
) %>%
add_global_p()
#> add_global_p: Global p-values for variable(s) `add_global_p(include = c("age",
#> "trt"))` were calculated with
#> `car::Anova(mod = x$model_obj, type = "III")`
Created on 2021-09-19 by the reprex package (v2.0.1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With