response: Response data

View source: R/utils.R

responseR Documentation

Response data

Description

Get response data (dates, progression, best-so-far, best overall, confirmed, etc.) for vectors of dates and response assessments.

response performs the work for a single ID–data with multiple IDs should be split before proceeding; see examples. This function also requires that dates are ordered.

response2 is a convenience function that calls response for each unique id. Data are ordered and split by id, and the results are aggregated into a single data frame.

Usage

response(
  date,
  response,
  include = "(resp|stable)|([cpm]r|sd)$",
  default = NA,
  no_confirm = "stable|sd",
  progression = "prog|pd|relapse",
  n_confirm = 1L,
  n_prog = n_confirm,
  strict = FALSE,
  dr = 0,
  dp = NULL
)

response2(
  id,
  date,
  response,
  ...,
  type = c("unconfirmed", "confirmed", "bsf_unconfirmed", "bsf_confirmed")
)

Arguments

date

a vector of assessment dates for a single ID; identical date/response visits will be removed with a warning

response

a factor variable of responses for each date with levels ordered from best response to worst (e.g., factor(., levels = c('CR', 'PR', 'SD', 'PD'))

include

integer vector corresponding to the levels of response or a single regular expression to match levels of response; defines assessments that will be treated as a meaningful response, e.g., if include does not match stable disease and/or minimal response, these assessments will be ignored in calculating best-so-far and best overall responses

default

(optional) the default response if no assessments have been confirmed, usually stable disease; must be a level of response

no_confirm

responses that do not require confirmation assessments, usually stable disease (default); must match a level of response

progression

a character string or regular expression to identify progression events in response; must match a level of response

n_confirm

to confirm a response, the number of subsequent responses equal to or better than previous; e.g., if n_confirm = 1 (default), to confirm a response, the next assessment must be at least as good as the current; note that this only affects .$confirmed and .$bsf_confirmed in the return object; if n_confirm = 2, to confirm a response, the next two assessments must be at least as good, etc.

n_prog

similar to n_confirm but for progression; if nprog = 1, then a progression must be followed by at least one progression to confirm; note that this only affects .$confirmed and .$bsf_confirmed in the return object

strict

logical; if TRUE, only the first uninterrupted sequence of confirmed responses will be evaluated for best response; e.g., an unconfirmed CR between two confirmed PR sequences will result in the later PR sequence being ignored

dr

(optional) difference in level required to confirm responses; if dr = 0 (default), the next response must be equal to or better to confirm; if dr = -1, the next response must be at least one level better; dr = Inf will be equivalent to unconfirmed responses since any subsequent response can confirm the one previous

dp

(optional) difference in level required to show progression; if dp = NULL (default), only responses matching progression pattern are progression; if dp = 0, any worse response will be considered progression (e.g., CR followed by PR); dp = 1, progression is defined as a greater than one level drop in response (e.g., CR to PR is not progression but CR to SD or MR is progression)

id

for response2, a vector of IDs

...

additional arguments passed to response

type

one of "unconfirmed", "confirmed", "bsf_unconfirmed", or "bsf_confirmed": see "Value" section

Value

A list with the following elements:

$unconfirmed

a 1 x 10 data frame with dates of first and last response, first and last best response, the response for each, date last free from progression, and date of progression

$confirmed

similar to $unconfirmed but only for responses that have been confirmed

$bsf_unconfirmed

an n x 2 data frame with the best-so-far responses matching include with corresponding dates

$bsf_confirmed

similar to $bsf_unconfirmed but only for responses that have been confirmed

Examples

set.seed(1)
rsp <- c('CR', 'PR', 'SD', 'PD')
rsp <- c('sCR', 'CR', 'VGPR', 'PR', 'MR', 'SD', 'PD')
dat <- data.frame(
  id = rep(1:5, each = 10),
  date = Sys.Date() + 1:10,
  response = factor(
    # rsp[sample(seq_along(rsp), 50, TRUE, c(0.2, 0.5, 0.2, 0.1))], rsp
    rsp[sample(seq_along(rsp), 50, TRUE)], rsp
  )
)

sp <- split(dat[, -1L], dat$id)
ii <- 2
response(sp[[ii]]$date, sp[[ii]]$response)

unconf <- do.call(
  'rbind',
  lapply(sp, function(x) response(x$date, x$response)$unconfirmed)
)
conf <- do.call(
  'rbind',
  lapply(sp, function(x) response(x$date, x$response, default = 'SD')$confirmed)
)
rownames(unconf) <- rownames(conf) <- NULL

data.frame(
  id = names(sp),
  unconf = unconf$response_best_first,
  conf = conf$response_best_first
)
## compare
do.call('cbind', sp)


## or simply with response2
unconf2 <- response2(dat$id, dat$date, dat$response)
conf2 <- response2(dat$id, dat$date, dat$response, type = 'confirmed')

identical(unconf, unconf2[-1])
identical(conf, conf2[-1])


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