insightsengineering / tern

Table, Listings, and Graphs (TLG) library for common outputs used in clinical trials
https://insightsengineering.github.io/tern/
Other
77 stars 22 forks source link

[Bug]: missing p-value #1289

Closed BFalquet closed 2 months ago

BFalquet commented 3 months ago

What happened?

Shouldn't there be a p-value represented ?

library(tern)
#> Loading required package: rtables
#> Loading required package: formatters
#> Loading required package: magrittr
#> 
#> Attaching package: 'rtables'
#> The following object is masked from 'package:utils':
#> 
#>     str
#> Registered S3 method overwritten by 'tern':
#>   method   from 
#>   tidy.glm broom
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(forcats)

adrs <- tern_ex_adrs
adrs_labels <- formatters::var_labels(adrs)

adrs_f <- adrs %>%
  filter(PARAMCD == "BESRSPI") %>%
  filter(ARM %in% c("A: Drug X", "B: Placebo")) %>%
  droplevels() %>%
  mutate(
    # Reorder levels of factor to make the placebo group the reference arm.
    ARM = fct_relevel(ARM, "B: Placebo"),
    rsp = AVALC == "CR"
  )
formatters::var_labels(adrs_f) <- c(adrs_labels, "Response")

# Unstratified analysis.
df <- extract_rsp_subgroups(
  variables = list(rsp = "rsp", arm = "ARM", subgroups = c("SEX", "BMRKR2")),
  data = adrs_f
)

basic_table() %>%
  tabulate_rsp_subgroups(
    df = df,
    vars = c("n_tot", "n", "n_rsp", "prop", "or", "ci", "pval")
  )
#>                                                    B: Placebo                       A: Drug X                                        
#> Baseline Risk Factors          Total n   n    Responders   Response (%)   n    Responders   Response (%)   Odds Ratio      95% CI    
#> —————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
#> All Patients                     142     73       50          68.5%       69       59          85.5%          2.71      (1.18, 6.24) 
#> Sex                                                                                                                                  
#>   F                              78      40       25          62.5%       38       36          94.7%         10.80      (2.27, 51.45)
#>   M                              64      33       25          75.8%       31       23          74.2%          0.92      (0.30, 2.85) 
#> Continuous Level Biomarker 2                                                                                                         
#>   LOW                            50      24       13          54.2%       26       21          80.8%          3.55      (1.00, 12.57)
#>   MEDIUM                         49      23       17          73.9%       26       23          88.5%          2.71      (0.59, 12.39)
#>   HIGH                           43      26       20          76.9%       17       15          88.2%          2.25      (0.40, 12.75)

sessionInfo()

> packageVersion("tern")
[1] ‘0.9.5.9013’

Relevant log output

No response

Code of Conduct

Contribution Guidelines

Security Policy

Melkiades commented 3 months ago

as far as I could see to get pvalue you need to add the method and strata:


# Unstratified analysis.
df <- extract_rsp_subgroups(
  method = "cmh", 
  variables = list(rsp = "rsp", arm = "ARM", subgroups = c("SEX", "BMRKR2"), strata = "STRATA1"),
  data = adrs_f
)

basic_table() %>%
  tabulate_rsp_subgroups(
    df = df,
    vars = c("n_tot", "n", "n_rsp", "prop", "or", "ci", "pval")
  )

But I think this could be a bug

BFalquet commented 3 months ago

Maybe we could have an assertion that checks that method is not NULL if pval is among the vars or have a default method set up.