Creates stratified summary table with rates.
Usage
summary_table(
data,
vars,
strata = NULL,
overall = FALSE,
get_rates = FALSE,
get_no_events = FALSE,
event = NULL,
st = NULL,
control = list(ctype = "inc.rate", method = "exact")
)
Arguments
- data
A
data.frame
that includes the data that should be summarised.- vars
A character vector specifying the variables that should be summarised.
summary_table
can only summarise variables of classnumeric
orfactor
.- strata
An optional character vector specifying the variables on which the summary table should be stratified on.
- overall
If
TRUE
an additionall summary table will be created including the complete dataset. This can be used in combination withstrata
.- get_rates
If
TRUE
the summary tables includes events rates for events specified in theevent
argument for each level of variables invar
. Rates can only be estimated for factor variables invar
.- get_no_events
If
TRUE
the summary tables includes the number of events specified in theevent
argument for each level of variables invar
. This argument is obsolete ifget_rates == TRUE
as the number of events is automatically added to the table in this case.- event
Name of the event indicator that should be used to compute rates. Needs to be specified if
get_rates == TRUE
.- st
Name of the varaible that includes the survival time that should be used to comptue rates. Needs to be specified if
get_rates == TRUE
.- control
A
list
of control parameters passed to theepiR::epi.conf()
call when estimating confidence intervals for rates. This can be used to change the type and method used for estimating confidence intervals. Check out the documentation ofepiR::epi.conf()
for more information.
Value
A data.frame
with the following columns:
varname
: Including the name of the variable or the name of the category for factor variablesmean
: The mean of the variable, i.e. the proportion for binary variablesp25
: The 25th percentile (only for metric variables.)p75
: The 75th percentile (only for metric varaibles.)min
: Minimum of the variablemax
: Maximum of the variablen_category
: The number of non-NA observations for each variable or cateogryn_total
: The number of non-NA observations for the variablen_NA
: The number of NA observations for this variable or category
If strata variables were supplied to summary_table
the output
data.table
will include one row for each strata variable with the
corresponding value for the specific strata the row belongs to.
Examples
require(rstpm2)
data("brcancer")
# Simple example
summary_table(brcancer,
vars = c("x1", "x2", "x3"))
#> varname mean p25 p75 min max n_category n_total n_NA
#> 1 x1 53 46 61 21 80 NA 686 0
#> 2 x2 2 1 2 1 2 NA 686 0
#> 3 x3 25 20 35 3 120 NA 686 0
# Example with stratas
summary_table(brcancer,
vars = c("x1", "x2", "x3"),
strata = c("hormon", "x4"))
#> hormon x4 varname mean p25 p75 min max n_category n_total n_NA
#> 1 0 2 x1 50.0 45.0 59.0 21 80 NA 281 0
#> 2 0 2 x2 1.0 1.0 2.0 1 2 NA 281 0
#> 3 0 2 x3 25.0 20.0 35.0 5 120 NA 281 0
#> 4 1 2 x1 59.0 51.0 63.0 32 80 NA 163 0
#> 5 1 2 x2 2.0 2.0 2.0 1 2 NA 163 0
#> 6 1 2 x3 25.0 20.0 35.0 7 100 NA 163 0
#> 7 0 3 x1 50.0 43.5 56.5 29 77 NA 111 0
#> 8 0 3 x2 1.0 1.0 2.0 1 2 NA 111 0
#> 9 0 3 x3 30.0 22.0 41.0 3 80 NA 111 0
#> 10 1 3 x1 57.5 47.0 64.0 33 74 NA 50 0
#> 11 1 3 x2 2.0 2.0 2.0 1 2 NA 50 0
#> 12 1 3 x3 28.0 23.0 35.0 12 60 NA 50 0
#> 13 0 1 x1 50.0 46.0 61.2 37 69 NA 48 0
#> 14 0 1 x2 1.0 1.0 2.0 1 2 NA 48 0
#> 15 0 1 x3 25.0 19.0 35.0 10 65 NA 48 0
#> 16 1 1 x1 56.0 49.0 61.0 37 79 NA 33 0
#> 17 1 1 x2 2.0 2.0 2.0 1 2 NA 33 0
#> 18 1 1 x3 25.0 18.0 30.0 4 56 NA 33 0
# Example with strata and rates
brcancer$x4 <- as.factor(brcancer$x4)
summary_table(brcancer,
vars = c("x1", "x2", "x3", "x4"),
strata = c("hormon"),
get_rates = TRUE,
event = "censrec",
st = "rectime")
#> ! Rates will only be estimted for factor variables in `vars`.
#> hormon varname mean p25 p75 min max n_category n_total n_NA no_events
#> 1 0 x1 50.000 45 59 21 80 NA 440 0 NA
#> 2 0 x2 1.000 1 2 1 2 NA 440 0 NA
#> 3 0 x3 25.000 20 35 3 120 NA 440 0 NA
#> 4 0 x4 1 0.109 NA NA 0 1 48 440 0 12
#> 5 0 x4 2 0.639 NA NA 0 1 281 440 0 137
#> 6 0 x4 3 0.252 NA NA 0 1 111 440 0 56
#> 7 1 x1 58.000 50 63 32 80 NA 246 0 NA
#> 8 1 x2 2.000 2 2 1 2 NA 246 0 NA
#> 9 1 x3 25.000 20 35 4 100 NA 246 0 NA
#> 10 1 x4 1 0.134 NA NA 0 1 33 246 0 6
#> 11 1 x4 2 0.663 NA NA 0 1 163 246 0 65
#> 12 1 x4 3 0.203 NA NA 0 1 50 246 0 23
#> t_at_risk p_events rate_est rate_lower rate_upper
#> 1 NA NA NA NA NA
#> 2 NA NA NA NA NA
#> 3 NA NA NA NA NA
#> 4 62398 0.05853659 0.0001923139 9.937138e-05 0.0003359336
#> 5 299081 0.66829268 0.0004580699 3.845799e-04 0.0005415135
#> 6 104802 0.27317073 0.0005343409 4.036354e-04 0.0006938862
#> 7 NA NA NA NA NA
#> 8 NA NA NA NA NA
#> 9 NA NA NA NA NA
#> 10 45477 0.06382979 0.0001319348 4.841776e-05 0.0002871666
#> 11 210621 0.69148936 0.0003086112 2.381796e-04 0.0003933503
#> 12 49021 0.24468085 0.0004691867 2.974241e-04 0.0007040104