Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

univariable and multivariable

Tags:

gtsummary

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()

A multivariable table:

library(survival)
  tbl_mvsurv <-coxph(
   Surv(Time,Status) ~.,
        data=data1
   ) %>%
  tbl_regression(
      exponentiate=TRUE
   ) %>%
   add_global_p() %>%
  bold_p(t=0.05)%>%
 bold_labels()
like image 464
belivemyself96 Avatar asked Nov 17 '25 05:11

belivemyself96


1 Answers

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")`

enter image description here

# 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")`

enter image description here Created on 2021-09-19 by the reprex package (v2.0.1)

like image 119
Daniel D. Sjoberg Avatar answered Nov 20 '25 01:11

Daniel D. Sjoberg