tox_worst: Find highest grade toxicities

View source: R/utils2.R

tox_worstR Documentation

Find highest grade toxicities

Description

Returns a subset of input data with worst toxicity grade per toxicity code per patient, ie, sorts and removes duplicates.

Usage

tox_worst(
  data,
  id = "id",
  desc = "desc",
  grade = "grade",
  code = NULL,
  version = 4L
)

Arguments

data

toxicity data frame

id

column name with identifier

desc

column name with toxicity descriptions (or codes)

grade

column name with toxiticity grades; should be a factor with the desired order to be properly sorted, i.e., least to most severe

code, version

if code is given, match_ctc will match this column from data with the CTCAE version given and return toxicity descriptions rather than codes; if showing toxicity codes is desired, use desc instead

note that version should be either 3 or 4 (default) corresponding to ctcae_v3 or ctcae_v4, respectively

Value

A filtered data frame with attributes:

attr(., "data")

the input data frame sorted by id, desc, and grade

attr(., "duplicates"

the indices of rows removed from attr(., "data") which correspond to duplicate desc per id with equal or lesser grades

See Also

match_ctc, tabler_by; tabler_by2

Examples

set.seed(1)
f <- function(x, ...) sample(x, 100, replace = TRUE, ...)

tox <- data.frame(id = rep(1:10, 10), phase = 1:2,
                  code = f(rawr::ctcae_v4$tox_code[1:10]),
                  grade = factor(f(1:3, prob = c(.3, .4, .3))))

## get worst tox by CTCAE code
## this will convert the code to description strings
tox1 <- tox_worst(tox, id = 'id', grade = 'grade', code = 'code')

## or by formatted descriptions and grade
tox$desc <- factor(match_ctc(tox$code)$tox_desc)
tox2 <- tox_worst(tox, id = 'id', grade = 'grade', desc = 'desc')

## both methods are equivalent
stopifnot(identical(tox1, tox2))


## these rows have been removed from attr(tox1, 'data')
attr(tox1, 'duplicates')

stopifnot(
  all.equal(tox1, attr(tox1, 'data')[-attr(tox1, 'duplicates'), ],
            check.attributes = FALSE)
)


## use tabler_by/tabler_by2 to summarize
tabler_by(tox1, 'desc', 'grade', n = 10, pct.sign = FALSE)
tabler_by2(tox1, 'desc', 'grade', stratvar = 'phase')


raredd/rawr documentation built on March 4, 2024, 1:36 a.m.