response | R Documentation |
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.
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")
)
date |
a vector of assessment dates for a single ID; identical
|
response |
a factor variable of responses for each |
include |
integer vector corresponding to the levels of |
default |
(optional) the default response if no assessments have been
confirmed, usually stable disease; must be a level of |
no_confirm |
responses that do not require confirmation assessments,
usually stable disease (default); must match a level of |
progression |
a character string or regular expression to identify
progression events in |
n_confirm |
to confirm a response, the number of subsequent responses
equal to or better than previous; e.g., if |
n_prog |
similar to |
strict |
logical; if |
dr |
(optional) difference in level required to confirm responses; if
|
dp |
(optional) difference in level required to show progression; if
|
id |
for |
... |
additional arguments passed to |
type |
one of |
A list with the following elements:
$unconfirmed |
a |
$confirmed |
similar to |
$bsf_unconfirmed |
an |
$bsf_confirmed |
similar to |
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])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.