adayim / consort

Create CONSORT diagrams for clinical studies.
Other
28 stars 4 forks source link

Minor error related to split_data_variable #4

Closed harrelfe closed 1 year ago

harrelfe commented 2 years ago

I have simulated clinical trial data and created a disposition table and get an error message I can't decode.

N <- 1000
set.seed(1)
r <- data.table(id = 1 : N)
r[, .c('age', 'pain', 'hxmed') :=
      .(round(rnorm(.N, 60, 15)),
              sample(0 : 5, .N, replace=TRUE),
                sample(0 : 1, .N, replace=TRUE, prob=c(0.95, 0.05)) ) ]
# Set consent status to those not excluded at screening
r[age >= 40 & pain > 0 & hxmed == 0,
  consent := sample(0 : 1, .N, replace=TRUE, prob=c(0.1, 0.9))]
# Set randomization status for those consenting
r[consent == 1,
  randomized := sample(0 : 1, .N, replace=TRUE, prob=c(0.15, 0.85))]
# Add treatment and follow-up time to randomized subjects
r[randomized == 1, tx     := sample(c('Treatment A', 'Treatment B'), .N, replace=TRUE)]
r[randomized == 1, futime := pmin(runif(.N, 0, 10), 3)]
# Add outcome status for those followed 3 years
# Make a few of those followed 3 years missing
r[futime == 3,
  y := sample(c(0, 1, NA), .N, replace=TRUE, prob=c(0.75, 0.2, 0.05))]
require(consort)
r[, exc := factor(fcase(pain  == 0, 1,
                        hxmed == 1, 2,
                        age < 40  , 3,
                        default=NA),
                  1:3, c('pain-free', 'Hx medication', 'age < 40'))]
r[, qual := is.na(exc)]
r[, consent := ifelse(consent == 1, 1, NA)]
consort_plot(r,
             orders = c(id      = 'Screened',
                        exc     = 'Excluded',
                        qual    = 'Qualified for Randomization',
                        consent = 'Consented',
                        tx      = 'Randomized'),
             side_box = 'exc',
             allocation = 'tx',
             labels=c('1'='Screening', '2'='Consent') #, '3'='Randomization')
)

Error in if (i == "split_data_variable") { : missing value where TRUE/FALSE needed

The problem occurs when there is nothing downstream of allocation, as when debugging a consort diagram. When I add follow-up events after allocation all is well.

adayim commented 2 years ago

Hi Frank, thanks for reporting this. I think the problem is theres no node box after treatment allocation, but the package expect some nodes. I will look into that.

adayim commented 2 years ago

Hi Frank. I have pushed the changes and it works now.