tabler_resp: Response table

View source: R/utils2.R

tabler_respR Documentation

Response table

Description

Convenience function to calculate proportions and confidence intervals and format for easy display.

Usage

tabler_resp(
  x,
  r_or_better = levels(x)[3:2],
  conf = 0.95,
  digits = 0L,
  frac = TRUE,
  show_conf = TRUE,
  pct.sign = TRUE,
  total = FALSE,
  two_stage = FALSE
)

Arguments

x

a factor variable of responses; responses should be ordered as CR, PR, SD, PD, NE or similar (i.e., best to worst)

r_or_better

if integer(s), indicates the levels of x that are to be combined with better responses; for example, if r_or_better = 3 (default), then any occurrence of level 1, 2, or 3 of x is treated as a response, and the proportion and confidence interval are calculated for the aggregate

if FALSE; levels of x are estimated independently

conf, frac, show_conf, pct.sign

additional arguments passed to binconr

digits

number of digits past the decimal point to keep

total

logical or numeric; if TRUE, a column with the total, i.e., length(x) is added; if numeric, length(x) and, optionally, fraction and percent out of total is added

two_stage

FALSE (default, assumes exact binomial CIs are desired) or a vector of length 3 with the 1) maximum number responses in the first stage that can be observed without continuing; 2) the sample size in the first stage; and 3) the sample size in the second stage

if more than three integers are given, the remaining should indicate the column(s) which should be calculated as two-stage CIs

See Also

bincon; binconr; response

Other tabler: tabler_by(), tabler_stat2(), tabler_stat(), tabler()

Examples

set.seed(1)
r <- c('CR', 'PR', 'SD', 'PD', 'NE')
x <- factor(sample(r, 30, replace = TRUE), r)

tabler_resp(x)
tabler_resp(x, 3)
tabler_resp(x, 'PR')
tabler_resp(x, 'PR', total = 50)

## note NAs are removed
y <- replace(x, 1:10, value = NA)
tabler_resp(x, FALSE)
tabler_resp(y, FALSE)


## two-stage designs
two_stage <- c(r1 = 2, n1 = 10, n2 = 20)
tabler_resp(x, two_stage = c(two_stage))

## two-stage only for SD or better and PR or better
tabler_resp(x, two_stage = c(two_stage, 6:7))

## compare
bincon(c(2, 20), c(10, 20), method = 'two-stage') ## SD or better
bincon(c(2, 16), c(10, 20), method = 'two-stage') ## PR or better

## one-stage methods should not be used
bincon(c(20, 16), 30, method = 'exact')


## typical usage
ht <- htmlTable::htmlTable(
  rbind(
    '95% CI' = tabler_resp(x),
    '90% CI' = tabler_resp(x, conf = 0.9),
    'Simple' = tabler_resp(x, frac = FALSE, pct.sign = FALSE,
                           show_conf = FALSE, digits = 1),
    'Two-stage' = tabler_resp(x, two_stage = c(2, 10, 20, 6:7))
  ),
  caption = 'Table of responses with exact binomial and
    two-stage<sup>&dagger;</sup>confidence intervals.',
  css.cell = 'padding: 0 10 0px; white-space: nowrap;',
  cgroup = c('Evaluation', 'Outcome (95% CI)'),
  n.cgroup = c(nlevels(x), 2L)
)
structure(ht, class = 'htmlTable')


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