| Title: | Easy Publication-Ready Tables and Regression Analysis |
|---|---|
| Description: | Streamlines the creation of descriptive frequency tables ('Table 1'), diagnostic test accuracy evaluations (sensitivity, specificity, predictive values), and multi-outcome regression summaries. Features a grammar for publication-ready epidemiological tables built on design-aware effect measures, prevalence and odds ratio calculations, and seamless integration with 'flextable' for exporting results to 'Microsoft Word' and 'PowerPoint'. |
| Authors: | Matheus Trabuco Gonzalez [aut, cre] |
| Maintainer: | Matheus Trabuco Gonzalez <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 3.1.2 |
| Built: | 2026-10-31 22:23:46 UTC |
| Source: | https://github.com/matheustg-14/simtablr |
Recomputes tab with a crude (and optionally adjusted) effect-measure column.
Equivalent to passing measure=/adjust= to table1() directly; calling
it when an effect column already exists replaces it.
add_effect(tab, measure, adjust.for = NULL, ref = NULL, conf.level = NULL, ...)add_effect(tab, measure, adjust.for = NULL, ref = NULL, conf.level = NULL, ...)
tab |
A |
measure |
One of |
adjust.for |
Optional covariate names for an adjusted column. |
ref |
Optional reference level(s); see |
conf.level |
Optional confidence level; defaults to the table's. |
... |
Ignored. |
The recomputed table1 object.
data(epitabl) table1(epitabl, c("sex", "smoking"), by = "adjudicated_acs") |> add_effect("OR")data(epitabl) table1(epitabl, c("sex", "smoking"), by = "adjudicated_acs") |> add_effect("OR")
Capture adjustment covariates
adjust(spec, ...)adjust(spec, ...)
spec |
A |
... |
Tidyselect expressions for adjustment covariates. |
A modified simtab_spec.
adjust(simtab(epitabl), age, sex)adjust(simtab(epitabl), age, sex)
Evaluates all applicable rules against a computed result. Rule failures are caught and skipped so advice can never break analysis.
advise(result, audit = FALSE)advise(result, audit = FALSE)
result |
A computed |
audit |
Logical. |
A simtab_advice object: a list of advice entries deduplicated by
rule id, each with id, severity, message, citation, fix, and
why. It prints one block per rule, most severe first, and converts with
as.data.frame(). With audit = TRUE, a simtab_audit object.
simtablr_references for the full references behind the
citations shown in advice, and simtablr_guidance() to control display.
res <- tb(epitabl, sex, diabetes) advise(res) advise(res, audit = TRUE)res <- tb(epitabl, sex, diabetes) advise(res) advise(res, audit = TRUE)
Convert a SimtablR codebook to a flextable
## S3 method for class 'simtab_codebook' as_flextable(x, ...)## S3 method for class 'simtab_codebook' as_flextable(x, ...)
x |
A |
... |
Additional arguments passed to |
A styled flextable object.
if (requireNamespace("flextable", quietly = TRUE)) { cb <- codebook(epitabl[, c("age", "sex", "diabetes")]) flextable::as_flextable(cb) }if (requireNamespace("flextable", quietly = TRUE)) { cb <- codebook(epitabl[, c("age", "sex", "diabetes")]) flextable::as_flextable(cb) }
Convert simtab_rbind_tb Object to Flextable
as_flextable.simtab_rbind_tb(x, footnotes = NULL, ...)as_flextable.simtab_rbind_tb(x, footnotes = NULL, ...)
x |
A |
footnotes |
Optional character vector of footer lines appended to the table. |
... |
Additional arguments passed to |
A flextable object.
if (requireNamespace("flextable", quietly = TRUE)) { t1 <- tb(epitabl, sex, diabetes) t2 <- tb(epitabl, hypertension, diabetes) as_flextable.simtab_rbind_tb(rbind(t1, t2)) }if (requireNamespace("flextable", quietly = TRUE)) { t1 <- tb(epitabl, sex, diabetes) t2 <- tb(epitabl, hypertension, diabetes) as_flextable.simtab_rbind_tb(rbind(t1, t2)) }
Convert a SimtablR result or spec to a flextable
as_flextable.simtab_result(x, ...) as_flextable.simtab_spec(x, ...) as_flextable.simtab_report(x, ...)as_flextable.simtab_result(x, ...) as_flextable.simtab_spec(x, ...) as_flextable.simtab_report(x, ...)
x |
A |
... |
Passed to the subclass flextable renderer. |
A flextable object, or a named list of flextable objects for a
simtab_report.
if (requireNamespace("flextable", quietly = TRUE)) { res <- tb(epitabl, sex, diabetes) flextable::as_flextable(res) }if (requireNamespace("flextable", quietly = TRUE)) { res <- tb(epitabl, sex, diabetes) flextable::as_flextable(res) }
as_gt() is a soft-dependency renderer for HTML and Quarto workflows. It
auto-computes a simtab_spec, then dispatches by result subclass. Built-in
results with specialised renderers retain their display features; every other
result with an as.data.frame renderer is converted from its display data
frame. Extension engines can register a custom as_gt renderer.
as_gt(x, ...) ## S3 method for class 'simtab_spec' as_gt(x, ...) ## S3 method for class 'simtab_result' as_gt(x, ...) ## S3 method for class 'simtab_rbind_tb' as_gt(x, ...) ## S3 method for class 'simtab_report' as_gt(x, ...)as_gt(x, ...) ## S3 method for class 'simtab_spec' as_gt(x, ...) ## S3 method for class 'simtab_result' as_gt(x, ...) ## S3 method for class 'simtab_rbind_tb' as_gt(x, ...) ## S3 method for class 'simtab_report' as_gt(x, ...)
x |
A SimtablR result or spec. |
... |
Passed to |
A gt_tbl object, or a named list of gt_tbl objects for a
simtab_report.
if (requireNamespace("gt", quietly = TRUE)) { res <- tb(epitabl, sex, diabetes) as_gt(res) }if (requireNamespace("gt", quietly = TRUE)) { res <- tb(epitabl, sex, diabetes) as_gt(res) }
Builds concise manuscript prose from the decisions recorded in a computed
SimtablR result. Passing a bare simtab_spec computes it first, matching the
other render/extract verbs.
as_methods(x, ...) ## S3 method for class 'simtab_result' as_methods(x, software = FALSE, ...) ## S3 method for class 'simtab_report' as_methods(x, software = FALSE, ...)as_methods(x, ...) ## S3 method for class 'simtab_result' as_methods(x, software = FALSE, ...) ## S3 method for class 'simtab_report' as_methods(x, software = FALSE, ...)
x |
A |
... |
Passed to methods; otherwise ignored. |
software |
Logical. If |
A character string of length one.
res <- tb(epitabl, sex, diabetes) as_methods(res) as_methods(res, software = TRUE)res <- tb(epitabl, sex, diabetes) as_methods(res) as_methods(res, software = TRUE)
Returns the checked-rules table ($checked) with a fired logical column
joined on, so the fired/silent distinction shown by print() is available
as a single rectangular table.
## S3 method for class 'simtab_audit' as.data.frame(x, row.names = NULL, optional = FALSE, ...)## S3 method for class 'simtab_audit' as.data.frame(x, row.names = NULL, optional = FALSE, ...)
x |
A |
row.names, optional, ...
|
Ignored; accepted for S3 consistency. |
A data.frame with one row per checked rule.
res <- tb(epitabl, sex, diabetes) as.data.frame(advise(res, audit = TRUE))res <- tb(epitabl, sex, diabetes) as.data.frame(advise(res, audit = TRUE))
Convert rbind_tb to Data Frame
## S3 method for class 'simtab_rbind_tb' as.data.frame(x, row.names = NULL, optional = FALSE, tidy = FALSE, ...)## S3 method for class 'simtab_rbind_tb' as.data.frame(x, row.names = NULL, optional = FALSE, tidy = FALSE, ...)
x |
An |
row.names |
NULL or a character vector giving the row names for the data frame. |
optional |
Logical. If TRUE, setting row names and converting column names is optional. |
tidy |
Logical. If |
... |
Additional arguments. |
A data.frame.
t1 <- tb(epitabl, sex, diabetes) t2 <- tb(epitabl, hypertension, diabetes) as.data.frame(rbind(t1, t2))t1 <- tb(epitabl, sex, diabetes) t2 <- tb(epitabl, hypertension, diabetes) as.data.frame(rbind(t1, t2))
A simtab_report bundles items that can have different shapes (for
example simtablr()'s descriptive Table 1 and association Table 2), so
there is no single natural rectangular table for a report in general. This
default method instead returns a named list of as.data.frame() results,
one per item, mirroring as_gt.simtab_report() and
as_flextable.simtab_report(). Subclasses whose items always share one
shape, such as sensitivity(), provide their own
rectangular as.data.frame() method instead of using this default.
## S3 method for class 'simtab_report' as.data.frame(x, row.names = NULL, optional = FALSE, ...)## S3 method for class 'simtab_report' as.data.frame(x, row.names = NULL, optional = FALSE, ...)
x |
A |
row.names, optional, ...
|
Passed to each item's |
A named list of data.frames, one per report item.
rep <- simtablr(epitabl, outcome = mace_event, exposure = renal_impairment, vars = c(age, sex), design = "cohort") as.data.frame(rep)rep <- simtablr(epitabl, outcome = mace_event, exposure = renal_impairment, vars = c(age, sex), design = "cohort") as.data.frame(rep)
Convert a SimtablR result or spec to a data frame
## S3 method for class 'simtab_result' as.data.frame(x, row.names = NULL, optional = FALSE, tidy = FALSE, ...) ## S3 method for class 'simtab_spec' as.data.frame(x, row.names = NULL, optional = FALSE, tidy = FALSE, ...)## S3 method for class 'simtab_result' as.data.frame(x, row.names = NULL, optional = FALSE, tidy = FALSE, ...) ## S3 method for class 'simtab_spec' as.data.frame(x, row.names = NULL, optional = FALSE, tidy = FALSE, ...)
x |
A |
row.names |
Unused. |
optional |
Unused. |
tidy |
Logical. |
... |
Passed to subclass renderers. For |
A data.frame.
res <- tb(epitabl, sex, diabetes) as.data.frame(res) as.data.frame(res, tidy = TRUE)res <- tb(epitabl, sex, diabetes) as.data.frame(res) as.data.frame(res, tidy = TRUE)
Dispatches to the engine's registered autoplot renderer.
## S3 method for class 'simtab_result' autoplot(object, ...)## S3 method for class 'simtab_result' autoplot(object, ...)
object |
A |
... |
Passed to the engine's autoplot renderer. |
A ggplot object.
if (requireNamespace("ggplot2", quietly = TRUE)) { r <- roc(epitabl, poc_hstn_value, adjudicated_acs) ggplot2::autoplot(r) }if (requireNamespace("ggplot2", quietly = TRUE)) { r <- roc(epitabl, poc_hstn_value, adjudicated_acs) ggplot2::autoplot(r) }
Plot a computed SimtablR spec
## S3 method for class 'simtab_spec' autoplot(object, ...)## S3 method for class 'simtab_spec' autoplot(object, ...)
object |
A |
... |
Passed to the computed result's autoplot method. |
A ggplot object when the computed result supports autoplot.
if (requireNamespace("ggplot2", quietly = TRUE)) { sp <- regtab(epitabl, "adjudicated_acs", ~ age + sex, family = binomial())$spec ggplot2::autoplot(sp) }if (requireNamespace("ggplot2", quietly = TRUE)) { sp <- regtab(epitabl, "adjudicated_acs", ~ age + sex, family = binomial())$spec ggplot2::autoplot(sp) }
Build a SimtablR codebook
codebook(x, ...)codebook(x, ...)
x |
A data frame, |
... |
Ignored. |
For reports, a publication label recorded consistently by one or
more items is used. If report items record conflicting labels for the same
variable, codebook() warns and uses the neutral label stored on the
source column rather than choosing an arbitrary item by position.
A simtab_codebook data frame with one row per variable.
cb <- codebook(epitabl[, c("age", "sex", "diabetes")]) head(cb)cb <- codebook(epitabl[, c("age", "sex", "diabetes")]) head(cb)
Capture variables to describe
describe(spec, ...)describe(spec, ...)
spec |
A |
... |
Tidyselect expressions for variables to describe. |
A modified simtab_spec.
describe(simtab(epitabl), age, sex)describe(simtab(epitabl), age, sex)
Returns the study design recorded by set_design(), without requiring
callers to read the internal "simtablr.design" attribute directly.
On a data frame this reads the advisory attribute; on a simtab_spec or
simtab_result it reads the specification's design field, falling back
to the source data frame's attribute for a simtab_result (matching what
repro_manifest() reports as design/design_source). It does not
indicate whether the design took part in effect-measure resolution; see
resolved_from on spec$effect or design_used in repro_manifest()
for that.
design(x)design(x)
x |
A data.frame, |
A single design string, or NULL if none is recorded.
cohort <- set_design(epitabl, "cohort") design(cohort)cohort <- set_design(epitabl, "cohort") design(cohort)
diag_test() compares a binary index test with a binary reference
standard and reports the confusion matrix with sensitivity, specificity,
predictive values, likelihood ratios, and related metrics, each with a
confidence interval. Positive levels are detected automatically but can be
set with positive and test_positive. For a continuous marker use
roc().
diag_test( data, test, ref, positive = NULL, test_positive = NULL, conf.level = 0.95, ci = c("exact", "wilson"), d = 2, percent = TRUE )diag_test( data, test, ref, positive = NULL, test_positive = NULL, conf.level = 0.95, ci = c("exact", "wilson"), d = 2, percent = TRUE )
data |
A data frame. |
test |
The index test column: a bare name or string. Must have two levels. |
ref |
The reference standard column: a bare name or string. Must have two levels. |
positive |
The level of |
test_positive |
The level of |
conf.level |
Number between 0 and 1. Confidence level for intervals. |
ci |
String. Interval method for the proportions: |
d |
Integer. Decimal places for all displayed estimates and intervals. |
percent |
Logical. If |
Sensitivity, specificity, PPV, NPV, accuracy, and prevalence are
proportions from the confusion matrix, with Clopper-Pearson intervals by
default or Wilson intervals with ci = "wilson". Predictive values and
accuracy depend on the prevalence in data. Likelihood ratios use the
log-method interval for a ratio of proportions (Simel et al., 1991; Altman
et al., 2000). The diagnostic odds ratio uses the Woolf logit interval, with
standard error
(Glas et al., 2003).
No continuity correction is applied, so both intervals are NA when any
cell of the matrix is zero. Cohen's kappa measures
chance-corrected agreement between test and reference, with the Fleiss,
Cohen & Everitt (1969) standard error. The Youden index and F1 score are
reported without intervals.
Rows missing either the test or the reference are dropped, and a message reports how many.
Use fmt() to change decimals or percentages, plot() for a fourfold
display, and ggplot2::autoplot() with type = "matrix" or
type = "metrics" for a heatmap or a plot of metrics with intervals.
as.data.frame(x, tidy = TRUE) returns the unrounded metrics.
A simtab_result of class simtab_diag. Print it to see the
confusion matrix and metrics, convert it with as.data.frame(), or save
it with export_docx(), export_pptx(), or export_xlsx(). Unrounded
results are stored in $data.
Clopper, C. J., & Pearson, E. S. (1934). The use of confidence or fiducial limits illustrated in the case of the binomial. Biometrika, 26(4), 404–413. doi:10.1093/biomet/26.4.404.
Simel, D. L., Samsa, G. P., & Matchar, D. B. (1991). Likelihood ratios with confidence: sample size estimation for diagnostic test studies. Journal of Clinical Epidemiology, 44(8), 763–770. doi:10.1016/0895-4356(91)90128-V.
Altman, D. G., Machin, D., Bryant, T. N., & Gardner, M. J. (2000). Statistics with Confidence (2nd ed.). BMJ Books.
Glas, A. S., Lijmer, J. G., Prins, M. H., Bonsel, G. J., & Bossuyt, P. M. M. (2003). The diagnostic odds ratio: a single indicator of test performance. Journal of Clinical Epidemiology, 56(11), 1129–1135. doi:10.1016/S0895-4356(03)00177-X.
Cohen, J. (1960). A coefficient of agreement for nominal scales. Educational and Psychological Measurement, 20(1), 37–46. doi:10.1177/001316446002000104.
Fleiss, J. L., Cohen, J., & Everitt, B. S. (1969). Large sample standard errors of kappa and weighted kappa. Psychological Bulletin, 72(5), 323–327. doi:10.1037/h0028106.
roc() for continuous markers, plot.simtab_diag(), and
simtablr_references for all references cited by SimtablR.
# Point-of-care troponin against adjudicated ACS substudy <- subset(epitabl, diagnostic_substudy == "Yes") acc <- diag_test(substudy, test = poc_hstn_positive, ref = adjudicated_acs) acc # Wilson intervals, decimals instead of percentages diag_test( substudy, poc_hstn_positive, adjudicated_acs, positive = "Yes", test_positive = "Positive", ci = "wilson", percent = FALSE ) # Metrics as a data frame as.data.frame(acc)# Point-of-care troponin against adjudicated ACS substudy <- subset(epitabl, diagnostic_substudy == "Yes") acc <- diag_test(substudy, test = poc_hstn_positive, ref = adjudicated_acs) acc # Wilson intervals, decimals instead of percentages diag_test( substudy, poc_hstn_positive, adjudicated_acs, positive = "Yes", test_positive = "Positive", ci = "wilson", percent = FALSE ) # Metrics as a data frame as.data.frame(acc)
Computes VanderWeele-Ding E-values for ratio-scale estimates and confidence
limits. Risk ratios are used directly, and so are prevalence ratios: a
prevalence ratio is a ratio of proportions, so the risk-ratio formula
applies to it as the estimand (VanderWeele & Ding, 2017); the result keeps
the "PR" label. For common outcomes, odds ratios use
the square-root approximation and hazard ratios use the VanderWeele-Ding
conversion (1 - 0.5^sqrt(HR)) / (1 - 0.5^sqrt(1/HR)); with rare = TRUE
the supplied ratio is treated as a rare-outcome risk-ratio approximation.
e_value(x, ...) ## S3 method for class 'simtab_result' e_value(x, measure = NULL, rare = FALSE, ...)e_value(x, ...) ## S3 method for class 'simtab_result' e_value(x, measure = NULL, rare = FALSE, ...)
x |
A computed SimtablR result containing ratio estimates. For
|
... |
Reserved for future options. |
measure |
Optional ratio measure override: |
rare |
Logical. Treat OR/HR estimates as rare-outcome approximations to risk ratios instead of applying the square-root approximation. |
E-values require positive, finite ratio estimates and confidence limits from a supported SimtablR result; unsupported scales fail with a classed input condition. Missing or non-finite source estimates are not converted into evidence. An E-value is a sensitivity-analysis threshold, not proof that uncontrolled confounding is absent, and must be interpreted with the identification assumptions of the parent analysis.
A simtab_e_value result with raw E-value numerics.
VanderWeele, T. J., & Ding, P. (2017). Sensitivity analysis in observational research: introducing the E-value. Annals of Internal Medicine, 167(4), 268–274. doi:10.7326/M16-2607.
ratio_result <- tb(epitabl, diabetes, adjudicated_acs, or, ref = "No") e_value(ratio_result)ratio_result <- tb(epitabl, diabetes, adjudicated_acs, or, ref = "No") e_value(ratio_result)
Selects the registered engine used when a specification is computed. Because
the engine determines the numerical evidence, applying engine() to a
computed result updates its stored specification and recomputes through the
same path as other evidence-changing verbs.
engine(spec, name)engine(spec, name)
spec |
A |
name |
A single registered engine name. See |
A modified simtab_spec, or a recomputed simtab_result.
engine(simtab(epitabl), "descriptive")engine(simtab(epitabl), "descriptive")
A fully synthetic prospective cohort of 1,500 adults enrolled after an emergency-department presentation with suspected acute coronary syndrome (ACS). The data were constructed to demonstrate descriptive, design-aware, diagnostic, regression, survival, sensitivity, and reporting workflows in SimtablR. They do not contain real patient records.
epitablepitabl
A data frame with 1,500 rows and 22 variables:
Unique study participant identifier (ACS0001 to ACS1500).
Age at the index presentation, in years.
Sex recorded for clinical assessment (Female, Male).
Body mass index in kg/m2; contains clinical missing values.
Smoking status (Never, Former, Current).
History of hypertension (No, Yes).
History of diabetes (No, Yes).
History of dyslipidemia (No, Yes).
Total cholesterol in mg/dL; contains clinical missing values.
Hours from symptom onset to emergency department presentation.
Systolic blood pressure at presentation, in mmHg.
Renal impairment (eGFR below 60 mL/min/1.73 m2; No, Yes).
Maintenance dialysis (No, Yes); rare clinical exposure.
Independent reference diagnosis of acute coronary syndrome (No, Yes).
Enrolled in point-of-care diagnostic substudy (No, Yes).
Point-of-care high-sensitivity troponin in ng/L.
Binary point-of-care troponin result (Negative, Positive).
Index hospital length of stay, in days.
Emergency department revisits during 1-year follow-up.
Hospital readmission during 1-year follow-up (No, Yes).
Time to MACE or censoring after presentation, in days.
Observed major adverse cardiovascular event before censoring (No, Yes).
ESTROBE-ACS enrolled 1,500 adult participants presenting with chest pain or an ischemic equivalent and undergoing evaluation for suspected ACS.
The primary reference diagnosis is independent clinical adjudication
(adjudicated_acs). A point-of-care high-sensitivity troponin substudy
(diagnostic_substudy) evaluated continuous troponin concentrations
(poc_hstn_value) and binary test positivity (poc_hstn_positive).
In-hospital course and secondary outcomes are captured by hospital length of
stay (length_of_stay), 1-year emergency department revisits (ed_visits),
and 1-year hospital readmission (rehospitalized).
Survival follow-up covers all 1,500 participants up to 365 days from
presentation. Major adverse cardiovascular event (MACE) status is recorded
by mace_event with follow-up time in mace_time_days.
Synthetic data generated by data-raw/generate-epitabl.R.
data(epitabl) table1( epitabl, c(age, sex, smoking, renal_impairment), by = adjudicated_acs ) diagnostic <- subset(epitabl, diagnostic_substudy == "Yes") diag_test( diagnostic, test = poc_hstn_positive, ref = adjudicated_acs, positive = "Yes" )data(epitabl) table1( epitabl, c(age, sex, smoking, renal_impairment), by = adjudicated_acs ) diagnostic <- subset(epitabl, diagnostic_substudy == "Yes") diag_test( diagnostic, test = poc_hstn_positive, ref = adjudicated_acs, positive = "Yes" )
Turns an inert simtab_spec into a simtab_result by running the shared,
engine-agnostic validator, resolving one registered engine, running that
engine's own hard-error validator (if any), and wrapping the engine's raw
numeric output in the namespaced result subclass the engine registered.
Passing an existing simtab_result recomputes from its stored specification.
evaluate(spec)evaluate(spec)
spec |
A |
A simtab_result.
sp <- simtab(epitabl) |> describe(hypertension) |> stratify(adjudicated_acs) res <- evaluate(sp) ressp <- simtab(epitabl) |> describe(hypertension) |> stratify(adjudicated_acs) res <- evaluate(sp) res
Export a SimtablR table to a Word (.docx) file
export_docx(x, path, footnotes = NULL, methods = FALSE, overwrite = FALSE, ...)export_docx(x, path, footnotes = NULL, methods = FALSE, overwrite = FALSE, ...)
x |
A SimtablR object with an |
path |
Output file path. A missing |
footnotes |
Optional character vector passed to table renderers that support footnotes. |
methods |
Logical; when |
overwrite |
Logical. Existing files are protected by default; pass
|
... |
Passed to |
Exports are written to a temporary file in the destination
directory and published only after the backend succeeds. Existing files
are never changed unless overwrite = TRUE.
Invisibly returns the normalized output path.
export_pptx(), export_xlsx(), table1()
## Not run: data(epitabl) table1(epitabl, c("age", "sex"), by = "adjudicated_acs") |> export_docx(tempfile(fileext = ".docx")) ## End(Not run)## Not run: data(epitabl) table1(epitabl, c("age", "sex"), by = "adjudicated_acs") |> export_docx(tempfile(fileext = ".docx")) ## End(Not run)
Writes a plot through ggplot2::ggsave(). When width and height are not
supplied, the plot's own recommended dimensions are used; an explicit value
always overrides the recommendation.
export_plot( x, path, width = NULL, height = NULL, dpi = 300, overwrite = FALSE, ... )export_plot( x, path, width = NULL, height = NULL, dpi = 300, overwrite = FALSE, ... )
x |
A |
path |
Output file path; the extension selects the device. When absent,
|
width, height
|
Canvas size in inches. Default |
dpi |
Resolution for raster devices. Default |
overwrite |
Logical. Existing files are protected by default; pass
|
... |
Passed to |
Invisibly returns the normalized output path.
## Not run: data(epitabl) roc(epitabl, poc_hstn_value, adjudicated_acs) |> export_plot(tempfile(fileext = ".png")) ## End(Not run)## Not run: data(epitabl) roc(epitabl, poc_hstn_value, adjudicated_acs) |> export_plot(tempfile(fileext = ".png")) ## End(Not run)
Export a SimtablR table to a PowerPoint (.pptx) file
export_pptx(x, path, font_size = 14, overwrite = FALSE, ...)export_pptx(x, path, font_size = 14, overwrite = FALSE, ...)
x |
A SimtablR object with an |
path |
Output file path. A missing |
font_size |
Font size applied before export. Default |
overwrite |
Logical. Existing files are protected by default; pass
|
... |
Passed to |
Invisibly returns the normalized output path.
## Not run: data(epitabl) table1(epitabl, c("age", "sex"), by = "adjudicated_acs") |> export_pptx(tempfile(fileext = ".pptx")) ## End(Not run)## Not run: data(epitabl) table1(epitabl, c("age", "sex"), by = "adjudicated_acs") |> export_pptx(tempfile(fileext = ".pptx")) ## End(Not run)
Export regtab results to CSV
export_regtab_csv(x, file, overwrite = FALSE, ...)export_regtab_csv(x, file, overwrite = FALSE, ...)
x |
A |
file |
Output file path. A missing |
overwrite |
Logical. Existing files are protected by default; pass
|
... |
Passed to |
The file is completed in the destination directory before it is published. Backend failures remove partial output and preserve any existing destination.
Invisibly returns x.
## Not run: mod <- regtab(epitabl, outcomes = "rehospitalized", predictors = ~ age + sex) export_regtab_csv(mod, tempfile(fileext = ".csv")) ## End(Not run)## Not run: mod <- regtab(epitabl, outcomes = "rehospitalized", predictors = ~ age + sex) export_regtab_csv(mod, tempfile(fileext = ".csv")) ## End(Not run)
Export regtab results to Excel
export_regtab_xlsx(x, file, overwrite = FALSE, ...)export_regtab_xlsx(x, file, overwrite = FALSE, ...)
x |
A |
file |
Output file path. A missing |
overwrite |
Logical. Existing files are protected by default; pass
|
... |
Passed to |
Invisibly returns x.
## Not run: mod <- regtab(epitabl, outcomes = "rehospitalized", predictors = ~ age + sex) export_regtab_xlsx(mod, tempfile(fileext = ".xlsx")) ## End(Not run)## Not run: mod <- regtab(epitabl, outcomes = "rehospitalized", predictors = ~ age + sex) export_regtab_xlsx(mod, tempfile(fileext = ".xlsx")) ## End(Not run)
Writes three worksheets: a long machine-readable tidy sheet with numeric
statistic cells, the formatted display sheet, and a data dictionary, named
machine-readable, display, and data-dictionary. Reports write one
display sheet per item instead of a single display sheet.
export_xlsx(x, path, overwrite = FALSE, ...)export_xlsx(x, path, overwrite = FALSE, ...)
x |
A SimtablR object with an |
path |
Output file path. A missing |
overwrite |
Logical. Existing files are protected by default; pass
|
... |
Passed to |
Invisibly returns the normalized output path.
## Not run: data(epitabl) table1(epitabl, c("age", "sex"), by = "adjudicated_acs") |> export_xlsx(tempfile(fileext = ".xlsx")) ## End(Not run)## Not run: data(epitabl) table1(epitabl, c("age", "sex"), by = "adjudicated_acs") |> export_xlsx(tempfile(fileext = ".xlsx")) ## End(Not run)
flow() assembles source, subset, rendered-cohort, complete-case, and model
Ns from a result or report without fitting or recomputing anything.
flow(x, ...) ## S3 method for class 'simtab_flow' as_flextable(x, ...) ## S3 method for class 'simtab_flow' autoplot(object, ...)flow(x, ...) ## S3 method for class 'simtab_flow' as_flextable(x, ...) ## S3 method for class 'simtab_flow' autoplot(object, ...)
x |
A |
... |
Ignored. |
object |
A |
A simtab_flow object.
res <- tb(epitabl, sex, diabetes) flow(res)res <- tb(epitabl, sex, diabetes) flow(res)
Set render formatting options
fmt( spec, d = NULL, conf_pct = NULL, labels = NULL, percent = NULL, big_mark = NULL, decimal_mark = NULL )fmt( spec, d = NULL, conf_pct = NULL, labels = NULL, percent = NULL, big_mark = NULL, decimal_mark = NULL )
spec |
A |
d |
Decimal places for percentages/estimates, or |
conf_pct |
Confidence-interval percentage label, or |
labels |
Optional named character labels, merged by variable name
through |
percent |
Logical, or |
big_mark |
Character inserted between every three digits of the integer
part of rendered numbers (e.g. |
decimal_mark |
Character used as the radix point in rendered numbers
(e.g. |
A modified simtab_spec.
fmt(simtab(epitabl), d = 1, conf_pct = 95) fmt(simtab(epitabl), big_mark = ",", decimal_mark = ".")fmt(simtab(epitabl), d = 1, conf_pct = 95) fmt(simtab(epitabl), big_mark = ",", decimal_mark = ".")
Glance a SimtablR result
## S3 method for class 'simtab_result' glance(x, ...) ## S3 method for class 'simtab_spec' glance(x, ...)## S3 method for class 'simtab_result' glance(x, ...) ## S3 method for class 'simtab_spec' glance(x, ...)
x |
A |
... |
Ignored. |
A one-row summary data.frame, where available.
fit <- regtab(epitabl, "adjudicated_acs", ~ age + sex, family = binomial()) generics::glance(fit)fit <- regtab(epitabl, "adjudicated_acs", ~ age + sex, family = binomial()) generics::glance(fit)
Namespaced subclasses (simtab_tb, simtab_table1, simtab_regtab,
simtab_diag, simtab_roc, ...) are the supported way to test result
identity; bare legacy tags (kept in the class vector for external,
backward-compatible inherits() callers) should not be tested directly in
new package code. Use is_simtab(x, preset) instead.
is_simtab(x, preset = NULL)is_simtab(x, preset = NULL)
x |
Any object. |
preset |
Optional character engine/preset name (e.g. |
TRUE/FALSE.
res <- tb(epitabl, sex, diabetes) is_simtab(res) is_simtab(res, preset = "tb") is_simtab(iris)res <- tb(epitabl, sex, diabetes) is_simtab(res) is_simtab(res, preset = "tb") is_simtab(iris)
Builds a simtab_style object: the single specification that controls both the
text conventions of a table (how counts, percentages, confidence intervals and
p-values are written) and its visual flextable theme. Pass the result to the
style argument of table1(), or register it under a name with
register_journal() so it can be referred to as style = "myjournal".
journal_style( np_template = NULL, count_header = "n (%)", digits_cont = 1, digits_est = 2, ci_sep = " - ", ci_parens = "()", est_template = NULL, pval_thresh = 0.001, pval_digits = 3, pval_upper = NULL, pval_leading_zero = TRUE, pval_adaptive = FALSE, percent_sign = TRUE, flex = NULL )journal_style( np_template = NULL, count_header = "n (%)", digits_cont = 1, digits_est = 2, ci_sep = " - ", ci_parens = "()", est_template = NULL, pval_thresh = 0.001, pval_digits = 3, pval_upper = NULL, pval_leading_zero = TRUE, pval_adaptive = FALSE, percent_sign = TRUE, flex = NULL )
np_template |
Character template for a categorical "count (percent)" cell,
using |
count_header |
Character appended to categorical variable headers to note
the cell convention, e.g. |
digits_cont |
Integer decimals for continuous summaries. Default |
digits_est |
Integer decimals for effect-measure estimates. Default |
ci_sep |
Character separating confidence-interval bounds (and IQR bounds),
e.g. |
ci_parens |
Two characters wrapping the confidence interval, e.g. |
est_template |
Character template for an estimate-with-CI string, using
|
pval_thresh |
Numeric; p-values below this print as |
pval_digits |
Integer decimals for p-values. Default |
pval_upper |
Optional numeric ceiling; p-values above this print as
|
pval_leading_zero |
Logical; whether p-values keep a leading zero before
the decimal point. Default |
pval_adaptive |
Logical; whether p-values above |
percent_sign |
Logical; whether the default |
flex |
A function of one argument |
An object of class "simtab_style".
register_journal(), list_journals(), table1()
s <- journal_style(count_header = "No. (%)", ci_sep = " to ", percent_sign = FALSE)s <- journal_style(count_header = "No. (%)", ci_sep = " to ", percent_sign = FALSE)
Set display labels
label(spec, ..., labels = NULL)label(spec, ..., labels = NULL)
spec |
A |
... |
Named character labels. |
labels |
Optional named character vector of labels. |
Label edits merge by variable name: supplied labels replace matching entries and all unspecified recorded labels remain unchanged. On computed results, this is a presentation-only edit; raw evidence is retained and the result call records the edit.
A modified simtab_spec.
label(simtab(epitabl), age = "Age, years", sex = "Sex")label(simtab(epitabl), age = "Age, years", sex = "Sex")
List registered SimtablR engines
list_engines()list_engines()
A character vector of registered engine names.
list_engines()list_engines()
List available journal style presets
list_journals()list_journals()
A character vector of registered preset names.
journal_style(), register_journal()
list_journals()list_journals()
Set an effect measure
measure(spec, m, ref = NULL, conf.level = 0.95, adjust = NULL)measure(spec, m, ref = NULL, conf.level = 0.95, adjust = NULL)
spec |
A |
m |
A single effect-measure name. |
ref |
Optional reference level: one level shared by every variable, or
a named list with one level per variable, e.g.
|
conf.level |
Confidence level between 0 and 1. |
adjust |
Optional tidyselect adjustment covariates, captured as a convenience for the builder register. |
A modified simtab_spec.
measure(simtab(epitabl), "OR", conf.level = 0.90)measure(simtab(epitabl), "OR", conf.level = 0.90)
Set missing-data policy
missingness(spec, display = NULL, denominator = NULL, model = NULL)missingness(spec, display = NULL, denominator = NULL, model = NULL)
spec |
A |
display |
Whether to display missingness rows. |
denominator |
Missing-data denominator policy, |
model |
Missing-data model policy, |
A modified simtab_spec.
missingness(simtab(epitabl), display = TRUE, denominator = "available")missingness(simtab(epitabl), display = TRUE, denominator = "available")
Returns the stable model-information rows retained by regtab() or
survtab(), including analysed N, estimator, convergence, boundary, failure,
and error fields where applicable. Unlike the conventional accessors,
model_info() may select a failed outcome because its purpose is to inspect
that failure.
model_info(object, outcome = NULL, ...)model_info(object, outcome = NULL, ...)
object |
A computed |
outcome |
Optional single outcome name. |
... |
Unused. |
A data frame with one row per requested model.
data(epitabl) fit <- regtab( epitabl, "rehospitalized", ~ age + sex, family = binomial("logit"), robust = FALSE ) model_info(fit)data(epitabl) fit <- regtab( epitabl, "rehospitalized", ~ age + sex, family = binomial("logit"), robust = FALSE ) model_info(fit)
regtab() and survtab() are reporting-evidence objects rather than mutable
fitted-model objects. These methods expose the conventional model evidence
that SimtablR retains: link-scale coefficients, confidence intervals,
formulas, analysed observation counts, and covariance matrices.
## S3 method for class 'simtab_result' coef(object, outcome = NULL, ...) ## S3 method for class 'simtab_result' vcov(object, outcome = NULL, complete = TRUE, ...) ## S3 method for class 'simtab_result' formula(x, outcome = NULL, ...) ## S3 method for class 'simtab_result' nobs(object, outcome = NULL, ...) ## S3 method for class 'simtab_result' confint(object, parm, level = 0.95, outcome = NULL, ...)## S3 method for class 'simtab_result' coef(object, outcome = NULL, ...) ## S3 method for class 'simtab_result' vcov(object, outcome = NULL, complete = TRUE, ...) ## S3 method for class 'simtab_result' formula(x, outcome = NULL, ...) ## S3 method for class 'simtab_result' nobs(object, outcome = NULL, ...) ## S3 method for class 'simtab_result' confint(object, parm, level = 0.95, outcome = NULL, ...)
object, x
|
A computed |
outcome |
Optional single outcome name. Omit it for the conventional single-outcome value or a predictably named multi-outcome collection. |
... |
Unused. |
complete |
Retained for compatibility with |
parm |
Optional coefficient names or positions for |
level |
Confidence level for |
A single-outcome result returns the conventional vector, matrix, formula, or
scalar. A multi-outcome result returns a list named by outcome, except
stats::nobs() which returns a named integer vector. Supply outcome to
select one outcome. Unknown, non-scalar, and failed-outcome selections raise
simtab_error_model.
Confidence intervals replay the inference represented by the result. Wald
intervals can be returned at another level from copied coefficient and
covariance evidence. Firth profile intervals are retained only at the level
used to fit the result; requesting another level requires refitting and is
therefore rejected.
SimtablR deliberately does not retain fitted values, residuals, response
vectors, mutable fitted-model objects, or a prediction/forecasting surface.
Use stats::glm(), survival::coxph(), or
logistf::logistf() directly when those model-object workflows are required.
coef() returns a named numeric vector or named list of vectors;
confint() and vcov() return a matrix or named list of matrices;
formula() returns a formula or named list of formulas; nobs() returns
an integer scalar or named integer vector.
data(epitabl) fit <- regtab( epitabl, outcomes = "rehospitalized", predictors = ~ age + sex, family = binomial("logit"), robust = FALSE ) coef(fit) confint(fit) formula(fit) nobs(fit) vcov(fit)data(epitabl) fit <- regtab( epitabl, outcomes = "rehospitalized", predictors = ~ age + sex, family = binomial("logit"), robust = FALSE ) coef(fit) confint(fit) formula(fit) nobs(fit) vcov(fit)
Toggle the overall column
overall(spec, value = TRUE)overall(spec, value = TRUE)
spec |
A |
value |
|
A modified simtab_spec.
overall(simtab(epitabl), FALSE)overall(simtab(epitabl), FALSE)
Draws a fourfold display of the retained confusion matrix with sensitivity and specificity annotated on the bottom margin.
## S3 method for class 'simtab_diag' plot(x, col = c("#ffcccc", "#ccffcc"), main = "Confusion Matrix", ...)## S3 method for class 'simtab_diag' plot(x, col = c("#ffcccc", "#ccffcc"), main = "Confusion Matrix", ...)
x |
A |
col |
Character vector of length 2. Fill colours for the negative and
positive quadrants respectively. Default: |
main |
Character. Plot title. Default: |
... |
Additional arguments passed to |
Invisibly returns x.
d <- diag_test(epitabl, poc_hstn_positive, adjudicated_acs, positive = "Yes", test_positive = "Positive") plot(d)d <- diag_test(epitabl, poc_hstn_positive, adjudicated_acs, positive = "Yes", test_positive = "Positive") plot(d)
Print Method for simtab_rbind_tb Objects
## S3 method for class 'simtab_rbind_tb' print(x, digits = NULL, ...)## S3 method for class 'simtab_rbind_tb' print(x, digits = NULL, ...)
x |
A |
digits |
Minimum number of significant digits to be printed. |
... |
Additional arguments. |
Invisibly returns x.
t1 <- tb(epitabl, sex, diabetes) t2 <- tb(epitabl, hypertension, diabetes) print(rbind(t1, t2))t1 <- tb(epitabl, sex, diabetes) t2 <- tb(epitabl, hypertension, diabetes) print(rbind(t1, t2))
Dispatches to the engine's registered print renderer. Falls back to an
honest generic (header + as_data_frame renderer if available + advice)
when the engine registered no print renderer.
## S3 method for class 'simtab_result' print(x, ...)## S3 method for class 'simtab_result' print(x, ...)
x |
A |
... |
Passed to subclass renderers. For |
Invisibly returns x.
res <- tb(epitabl, sex, diabetes) print(res)res <- tb(epitabl, sex, diabetes) print(res)
Vertical stacking of tb objects to create multi-variable tables.
## S3 method for class 'simtab_tb' rbind(..., deparse.level = 1)## S3 method for class 'simtab_tb' rbind(..., deparse.level = 1)
... |
Objects of class |
deparse.level |
Integer controlling label deparsing (unused). |
This method is registered as an S3 method on base::rbind() (it does not
mask base::rbind), so rbind(tb1, tb2) dispatches here while ordinary
matrix/data.frame rbind() is unaffected.
The resulting rbind_tb object combines multiple bivariate tables sharing
a common stratifying column into a stacked summary table.
A combined object of class c("simtab_rbind_tb", "rbind_tb", "simtab").
t1 <- tb(epitabl, sex, diabetes) t2 <- tb(epitabl, hypertension, diabetes) rbind(t1, t2)t1 <- tb(epitabl, sex, diabetes) t2 <- tb(epitabl, hypertension, diabetes) rbind(t1, t2)
Stores the full engine contract — compute function, result subclass,
optional legacy class tag, optional hard-error validator, a named subset of
renderer verbs, and an optional engine-options validator — under a
case-insensitive name. A user-registered engine gets print/as.data.frame/
as_flextable/as_gt/tidy/glance/autoplot/as_methods dispatch through
evaluate()'s shared simtab_result methods with no further S3 ceremony.
register_engine( name, compute, subclass = paste0("simtab_", .normalise_registry_name(name)), legacy_tag = NULL, validate = NULL, renderers = list(), engine_opts = NULL, verbs = NULL, overwrite = FALSE )register_engine( name, compute, subclass = paste0("simtab_", .normalise_registry_name(name)), legacy_tag = NULL, validate = NULL, renderers = list(), engine_opts = NULL, verbs = NULL, overwrite = FALSE )
name |
Character engine name, e.g. |
compute |
Function with signature |
subclass |
Character result subclass. Defaults to |
legacy_tag |
Optional extra class tag kept for backward-compatible
|
validate |
Optional function |
renderers |
Named list of renderer functions, names drawn from
|
engine_opts |
Optional function |
verbs |
Optional character vector of the evidence-changing verbs the
engine uses: any of |
overwrite |
Logical. Replacing a built-in engine ( |
Invisibly, name.
## Not run: register_engine("dummy", compute = function(spec, data) list(data = data, meta = list())) ## End(Not run)## Not run: register_engine("dummy", compute = function(spec, data) list(data = data, meta = list())) ## End(Not run)
Stores a simtab_style in SimtablR's preset registry under name so it can be
used as style = name in table1() and the add_*() helpers. Registering a
name that already exists overwrites it.
register_journal(name, style)register_journal(name, style)
name |
Character preset name (case-insensitive). |
style |
A |
Invisibly, name.
journal_style(), list_journals()
register_journal("mylab", journal_style(count_header = "No. (%)", ci_sep = " to ")) list_journals()register_journal("mylab", journal_style(count_header = "No. (%)", ci_sep = " to ")) list_journals()
regtab() fits the same set of predictors to one or more outcomes and
returns the estimates side by side in a single publication-style table, one
column per outcome. The default Poisson-log model with robust standard
errors gives rate ratios for counts and prevalence or risk ratios for 0/1
outcomes (modified Poisson); use family = binomial() for odds ratios or
gaussian() for mean differences. For crude estimates alongside a
descriptive table use table1().
regtab( data, outcomes, predictors, family = poisson(link = "log"), offset = NULL, robust = TRUE, method = "glm", exponentiate = NULL, labels = NULL, predictor_labels = NULL, d = 2, conf.level = 0.95, include_intercept = FALSE, p_values = FALSE, design = NULL, exposure = NULL )regtab( data, outcomes, predictors, family = poisson(link = "log"), offset = NULL, robust = TRUE, method = "glm", exponentiate = NULL, labels = NULL, predictor_labels = NULL, d = 2, conf.level = 0.95, include_intercept = FALSE, p_values = FALSE, design = NULL, exposure = NULL )
data |
A data frame. |
outcomes |
Character vector of outcome column names. Each outcome gets its own model with the same predictors. |
predictors |
The right-hand side of the model, as a one-sided formula
( |
family |
A |
offset |
Optional person-time column: a bare name or string. With a
Poisson-log model, |
robust |
Standard errors: |
method |
String. |
exponentiate |
Logical. Whether to report exponentiated estimates. If
|
labels |
Named character vector of display labels for outcomes, e.g.
|
predictor_labels |
Named character vector of display labels for model
terms, e.g. |
d |
Integer. Decimal places for estimates and intervals. |
conf.level |
Number between 0 and 1. Confidence level for intervals. |
include_intercept |
Logical. If |
p_values |
Logical. If |
design |
String. Optional study design recorded on the result. It does
not change the family; it labels log-link estimates on binary outcomes as
prevalence ratios ( |
exposure |
Optional exposure column: a bare name or string. It must be
a main-effect term of |
Each outcome is fitted with stats::glm() and the requested family.
Intervals are Wald intervals on the link scale, using HC0 sandwich
standard errors by default; a Poisson-log model with robust errors on a 0/1
outcome is the modified Poisson approach for prevalence and risk ratios
(Zou, 2004). method = "firth" uses penalised-likelihood (profile)
inference instead, so the HC options do not apply.
For models with two or more predictor terms, generalized variance
inflation factors (Fox & Monette, 1992) are stored on the result. Show them
with as.data.frame(fit, vif = TRUE) or generics::glance(fit, vif = TRUE).
When a binomial or Poisson coefficient diverges (separation), its
model-based standard error on the link scale exceeds 100 and the table
shows a dash with a footnote instead of a number such as
0.00 (0.00 - 0.00); refit with method = "firth". The raw estimate is
kept in $data and the flag in meta$not_estimable.
Rows with a missing outcome or predictor are dropped from that outcome's
model, so the N can differ between outcomes. It is shown in the table and
in model_info().
coef(), confint(), vcov(), formula(), and nobs() work on the
result, returning one entry per outcome or a single one with
outcome = "name". model_info() reports convergence and failed
models, generics::tidy() returns one row per term, and
ggplot2::autoplot() draws a forest plot.
The result is a reporting table, not a fitted model: it keeps no fitted
values or residuals and cannot predict. For conditional logistic
regression, prediction, or model diagnostics, fit stats::glm(),
logistf::logistf(), or survival::clogit() directly.
A simtab_result of class simtab_regtab. Print it to see the
formatted table, convert it with as.data.frame(), or save it with
export_docx(), export_pptx(), or export_xlsx(). Unrounded results
are stored in $data.
Zou, G. (2004). A modified Poisson regression approach to prospective studies with binary data. American Journal of Epidemiology, 159(7), 702–706. doi:10.1093/aje/kwh090.
Firth, D. (1993). Bias reduction of maximum likelihood estimates. Biometrika, 80(1), 27–38. doi:10.1093/biomet/80.1.27.
Fox, J., & Monette, G. (1992). Generalized collinearity diagnostics. Journal of the American Statistical Association, 87(417), 178–183. doi:10.1080/01621459.1992.10475190.
Long, J. S., & Ervin, L. H. (2000). Using heteroscedasticity consistent standard errors in the linear regression model. The American Statistician, 54(3), 217–224. doi:10.1080/00031305.2000.10474549.
model_info() for convergence, survtab() for time-to-event
outcomes, table1() for crude and adjusted effects in a descriptive
table, and simtablr_references for all references cited by SimtablR.
# Rate ratios for two count outcomes (Poisson, robust SEs) fit <- regtab( epitabl, outcomes = c("ed_visits", "length_of_stay"), predictors = ~ age + sex + smoking ) fit # Odds ratios for a binary outcome, with p-values regtab( epitabl, "rehospitalized", ~ age + sex + diabetes, family = binomial(), p_values = TRUE ) # One row per term, for further processing generics::tidy(fit) # Name the exposure so reviewer tools skip the covariates adjusted <- regtab( epitabl, "mace_event", ~ renal_impairment + age + sex, family = binomial("log"), design = "cohort", exposure = renal_impairment ) e_value(adjusted)# Rate ratios for two count outcomes (Poisson, robust SEs) fit <- regtab( epitabl, outcomes = c("ed_visits", "length_of_stay"), predictors = ~ age + sex + smoking ) fit # Odds ratios for a binary outcome, with p-values regtab( epitabl, "rehospitalized", ~ age + sex + diabetes, family = binomial(), p_values = TRUE ) # One row per term, for further processing generics::tidy(fit) # Name the exposure so reviewer tools skip the covariates adjusted <- regtab( epitabl, "mace_event", ~ renal_impairment + age + sex, family = binomial("log"), design = "cohort", exposure = renal_impairment ) e_value(adjusted)
Captures the runtime and recorded analysis decisions needed to reproduce a SimtablR result. The data hash and ruleset version are read from the result; the data are not re-hashed.
repro_manifest(result)repro_manifest(result)
result |
A |
A simtab_manifest list. estimator, interval_method, tests,
and the corrections in engine_decisions are the same recorded decisions
that as_methods() writes as prose. packages lists SimtablR, its
Imports, and the suggested packages the result's engine used (for
example pROC for roc()), alongside the R version and platform in r.
design and design_source describe
any study design recorded on the specification or the source data frame,
whether or not it took part in resolving measure; design_used
distinguishes the two, and is TRUE only when resolved_from is
"design". A design recorded only on the data frame (set_design() on
a data.frame) is advisory and never sets design_used; see
set_design().
res <- tb(epitabl, sex, diabetes) repro_manifest(res)res <- tb(epitabl, sex, diabetes) repro_manifest(res)
roc() measures how well one or more continuous markers discriminate a
binary outcome. It reports the area under the ROC curve (AUC) with a
confidence interval and, by default, the Youden-optimal cutpoint with its
sensitivity, specificity, and predictive values. With two or more markers,
their AUCs are compared pairwise with the DeLong test. For a test that is
already binary use diag_test(). Requires the pROC package.
roc( data, marker, outcome, positive = NULL, direction = c("auto", ">", "<"), cutpoint = c("youden", "none"), conf.level = 0.95, d = 2, percent = TRUE )roc( data, marker, outcome, positive = NULL, direction = c("auto", ">", "<"), cutpoint = c("youden", "none"), conf.level = 0.95, d = 2, percent = TRUE )
data |
A data frame. |
marker |
One or more numeric marker columns: a bare name, |
outcome |
The binary outcome column: a bare name or string. |
positive |
The level of |
direction |
String. Which marker values indicate disease: |
cutpoint |
String. |
conf.level |
Number between 0 and 1. Confidence level for AUC intervals. |
d |
Integer. Decimal places for displayed estimates. |
percent |
Logical. If |
ROC curves and AUCs are computed with pROC (Robin et al., 2011), using DeLong intervals for the AUC and the paired DeLong test to compare markers measured on the same patients (DeLong et al., 1988). A cutpoint chosen from the same data is optimistic: its sensitivity and specificity will usually be lower in new patients (Ewald, 2006), and a note says so. The AUC describes discrimination only, not calibration.
Rows with a missing outcome or marker value are dropped, across all markers at once, so every marker is evaluated on the same patients. A message reports how many rows were removed. Each marker needs both outcome classes among the remaining rows.
Use fmt() to change decimals or percentages and ggplot2::autoplot() to
draw the ROC curves. The curve coordinates and DeLong comparisons are
stored in $data.
A simtab_result of class simtab_roc. Print it to see the AUC
table and comparisons, convert it with as.data.frame(), or save it with
export_docx(), export_pptx(), or export_xlsx(). Unrounded results
are stored in $data.
Robin, X., Turck, N., Hainard, A., et al. (2011). pROC: an open-source package for R and S+ to analyze and compare ROC curves. BMC Bioinformatics, 12, 77. doi:10.1186/1471-2105-12-77.
DeLong, E. R., DeLong, D. M., & Clarke-Pearson, D. L. (1988). Comparing the areas under two or more correlated receiver operating characteristic curves: a nonparametric approach. Biometrics, 44(3), 837–845. doi:10.2307/2531595.
Ewald, B. (2006). Post hoc choice of cut points introduced bias to diagnostic research. Journal of Clinical Epidemiology, 59(8), 798–801. doi:10.1016/j.jclinepi.2005.11.025.
diag_test() for binary tests and simtablr_references for all
references cited by SimtablR.
if (requireNamespace("pROC", quietly = TRUE)) { substudy <- subset(epitabl, diagnostic_substudy == "Yes") # AUC and Youden cutpoint for point-of-care troponin roc(substudy, poc_hstn_value, adjudicated_acs) # Compare two markers with the paired DeLong test fit <- roc(substudy, c(poc_hstn_value, systolic_bp), adjudicated_acs, positive = "Yes") fit # AUC only, no data-driven cutpoint roc(substudy, poc_hstn_value, adjudicated_acs, cutpoint = "none") }if (requireNamespace("pROC", quietly = TRUE)) { substudy <- subset(epitabl, diagnostic_substudy == "Yes") # AUC and Youden cutpoint for point-of-care troponin roc(substudy, poc_hstn_value, adjudicated_acs) # Compare two markers with the paired DeLong test fit <- roc(substudy, c(poc_hstn_value, systolic_bp), adjudicated_acs, positive = "Yes") fit # AUC only, no data-driven cutpoint roc(substudy, poc_hstn_value, adjudicated_acs, cutpoint = "none") }
sensitivity() takes a computed result and recomputes named variations of
the recorded specification. Variations are either functions that take a
simtab_spec and return a modified simtab_spec, or supported shorthand
values such as denominator = "complete" and measure = "OR".
sensitivity(result, ...) ## S3 method for class 'simtab_sensitivity' as_flextable(x, ...)sensitivity(result, ...) ## S3 method for class 'simtab_sensitivity' as_flextable(x, ...)
result |
A computed |
... |
Named sensitivity variations. Unnamed variations are rejected. |
x |
A |
A simtab_sensitivity report.
res <- tb(epitabl, renal_impairment, adjudicated_acs, measure = "rr", ref = "No") sensitivity(res, measure = "or")res <- tb(epitabl, renal_impairment, adjudicated_acs, measure = "rr", ref = "No") sensitivity(res, measure = "or")
Records a study design on a data frame or a simtab_spec. The two forms
behave differently: on a simtab_spec, the design participates in
evaluate()'s effect-measure resolution, so a call such as
set_design(spec, "cohort") |> evaluate() can pick RR over an unset
measure. On a data frame, the design is recorded only as an attribute for
educator advice (methodological guidance rules can read it); it is not
consulted when resolving an effect measure, even for a tb()/table1()
call built directly from that data frame. To resolve a measure from
design, pass design = to the direct function or call set_design() on a
simtab_spec (see vignette("study-design-effect-measures")).
set_design(data, design)set_design(data, design)
data |
A data.frame or |
design |
Study design, e.g. |
data with a SimtablR design attribute, or a modified
simtab_spec.
set_design(simtab(epitabl), "cohort") cohort_data <- set_design(epitabl, "cohort") # advisory only; see Detailsset_design(simtab(epitabl), "cohort") cohort_data <- set_design(epitabl, "cohort") # advisory only; see Details
Set the default summary statistic
set_summary(spec, stat = c("auto", "median", "mean"), .by_var = NULL)set_summary(spec, stat = c("auto", "median", "mean"), .by_var = NULL)
spec |
A |
stat |
Summary statistic, one of |
.by_var |
Optional variable for a per-variable override. |
A modified simtab_spec.
set_summary(describe(simtab(epitabl), age), "median")set_summary(describe(simtab(epitabl), age), "median")
Captures data once into a shared data reference and returns an inert
simtab_spec. Printing the returned object shows the analysis plan; it never
performs estimation.
simtab(data)simtab(data)
data |
A data frame. |
A simtab_spec object.
spec <- simtab(epitabl) specspec <- simtab(epitabl) spec
Installs (or removes) a session-wide completer that offers column-name
and terse-flag completions inside calls to tb(), table1(), regtab(),
diag_test(), roc(), and survtab() — e.g. tb(df, var<TAB>).
simtab_completions(enable = TRUE, quiet = FALSE)simtab_completions(enable = TRUE, quiet = FALSE)
enable |
Logical. |
quiet |
Logical. Suppress the confirmation message. Default |
This works by setting rc.options(custom.completer = ), the only
completion-extension hook RStudio's editor honors for package authors.
Because that option is session-global, enabling it affects completion
behavior everywhere in the session, not just inside SimtablR calls: on any
line that isn't a recognized SimtablR call, this completer declines the
token, and RStudio falls back to its own completion engine (or to a
previously installed custom completer, which is called first).
Invisibly, a list with enabled (logical), mode ("throw" when
installed, "unsupported" when the host cannot support it), and host
("rstudio" or "other").
RStudio only. Declining a token relies on the host restoring native
completion, which RStudio does and a plain console does not; on any other
front end (Rterm, radian, batch), enabling the completer would leave
non-SimtablR tokens with no completions at all. simtab_completions()
therefore declines to install outside RStudio and tells you so, rather than
degrading completion for the rest of the session.
Never installed automatically — SimtablR's .onLoad does not call this.
Call it yourself, e.g. from .Rprofile:
if (interactive()) SimtablR::simtab_completions().
simtab_completions(enable = FALSE, quiet = TRUE)simtab_completions(enable = FALSE, quiet = TRUE)
SimtablR errors inherit from simtab_error. More specific classes identify
the failing surface so callers can assert on behavior without matching prose:
simtab_error_input for invalid user-supplied arguments at a public entry
point, simtab_error_binding for variable binding and role-selection
failures, simtab_error_spec for invalid SimtablR specifications,
simtab_error_engine for engine validation or compute failures,
simtab_error_flag for invalid table flags, simtab_error_render for
missing renderer methods, and simtab_error_dependency for a suggested
package that is needed but not installed. simtab_error_export identifies
unsafe paths, destination collisions, and failed file writes.
simtab_error_model identifies unsupported model access and invalid outcome
selectors on retained model evidence.
Messages follow one house form: an x line stating the problem, an i line
giving the context that produced it, and a v line naming the next action.
{} expressions in the message are evaluated in the calling function's
environment, so a caller can interpolate its own locals directly rather than
pre-building the string with sprintf().
This documentation-only topic evaluates to NULL; condition helpers
signal classed errors rather than returning values.
tryCatch( tb(epitabl, non_existent_var, diabetes), simtab_error = function(e) message("Caught simtab error") )tryCatch( tb(epitabl, non_existent_var, diabetes), simtab_error = function(e) message("Caught simtab error") )
simtablr() composes existing presets into a transparent simtab_report.
It creates a cohort-description Table 1 and an exposure-to-outcome Table 2
using the same table1() effect path as direct users. No new estimation is
performed by the orchestrator.
simtablr( data, outcome, exposure, vars = NULL, adjust = NULL, design = NULL, test = TRUE, style = "default", ... )simtablr( data, outcome, exposure, vars = NULL, adjust = NULL, design = NULL, test = TRUE, style = "default", ... )
data |
A data.frame. |
outcome |
Bare column name for the outcome. |
exposure |
Bare column name for the exposure. |
vars |
Optional tidyselect expression of Table 1 variables. Defaults to
all columns except |
adjust |
Optional tidyselect expression of adjustment covariates for Table 2. |
design |
Optional per-call study design used by the existing design-aware measure resolver. |
test |
Logical or test name passed to |
style |
Display style passed to |
... |
Additional |
A simtab_report with named table1 and table2 results.
## Not run: data(epitabl) simtablr(epitabl, outcome = adjudicated_acs, exposure = smoking, vars = c(age, sex, smoking), adjust = c(age, sex), design = "cross_sectional") ## End(Not run)## Not run: data(epitabl) simtablr(epitabl, outcome = adjudicated_acs, exposure = smoking, vars = c(age, sex, smoking), adjust = c(age, sex), design = "cross_sectional") ## End(Not run)
Guidance changes only which stored advice is displayed. "default" shows
severity 3-4 advice and counts hidden severity 1-2 notes; "important"
and its compatibility alias "quiet" show severity 3-4 advice only;
"teaching" shows severity 1-4 advice with external citations and recorded
rationale; "strict" shows severity 1-4 advice in compact prose; and
"off" hides automatic advice. Severity 0 remains audit-only.
When a result has only one non-audit advice entry, that entry is shown under
every profile except "off" instead of being reported as hidden.
simtablr_guidance(level = NULL)simtablr_guidance(level = NULL)
level |
One of |
Guidance is a session-level display setting read when a stored result is
printed. Call simtablr_guidance() separately; do not place it inside the
... of table1() or tb(). Changing guidance does not recompute results.
The active guidance level, invisibly when setting.
simtablr_references for the full references behind the citations shown in advice.
previous <- simtablr_guidance() result <- table1(epitabl, "sex") simtablr_guidance("teaching") print(result) simtablr_guidance(previous) suppressMessages(print(result))previous <- simtablr_guidance() result <- table1(epitabl, "sex") simtablr_guidance("teaching") print(result) simtablr_guidance(previous) suppressMessages(print(result))
Full references for every method and recommendation that SimtablR cites,
both on its help pages and in its educator advice. Advice messages show a
short tag such as "(Ver Hoef & Boveng 2007)"; each entry below starts with
that tag in bold, so you can look it up here. Use
simtablr_guidance("teaching") to show the citation on every advice
message, or advise(result) to list the advice for a stored result.
Anscombe 1956. Anscombe, F. J. (1956). On estimating binomial response relations. Biometrika, 43(3/4), 461–464. doi:10.1093/biomet/43.3-4.461.
Barros & Hirakata 2003. Barros, A. J. D., & Hirakata, V. N. (2003). Alternatives for logistic regression in cross-sectional studies: an empirical comparison of models that directly estimate the prevalence ratio. BMC Medical Research Methodology, 3, 21. doi:10.1186/1471-2288-3-21.
Bender & Lange 2001. Bender, R., & Lange, S. (2001). Adjusting for multiple testing: when and how? Journal of Clinical Epidemiology, 54(4), 343–349. doi:10.1016/S0895-4356(00)00314-0.
Campbell 2007. Campbell, I. (2007). Chi-squared and Fisher-Irwin tests of two-by-two tables with small sample recommendations. Statistics in Medicine, 26(19), 3661–3675. doi:10.1002/sim.2832.
Fisher 1935. Fisher, R. A. (1935). The Design of Experiments. Oliver & Boyd.
Greenland & Robins 1985. Greenland, S., & Robins, J. M. (1985). Estimation of a common effect parameter from sparse follow-up data. Biometrics, 41(1), 55–68. doi:10.2307/2530643.
Haldane 1956. Haldane, J. B. S. (1956). The estimation and significance of the logarithm of a ratio of frequencies. Annals of Human Genetics, 20(4), 309–311. doi:10.1111/j.1469-1809.1955.tb01285.x.
Katz et al. 1978. Katz, D., Baptista, J., Azen, S. P., & Pike, M. C. (1978). Obtaining confidence intervals for the risk ratio in cohort studies. Biometrics, 34(3), 469–474. doi:10.2307/2530610.
Knol 2011. Knol, M. J., Le Cessie, S., Algra, A., Vandenbroucke, J. P., & Groenwold, R. H. H. (2012). Overestimation of risk ratios by odds ratios in trials and cohort studies: alternatives to logistic regression. Canadian Medical Association Journal, 184(8), 895–899. Published online 2011. doi:10.1503/cmaj.101715.
Pearson 1900. Pearson, K. (1900). On the criterion that a given system of deviations from the probable in the case of a correlated system of variables is such that it can be reasonably supposed to have arisen from random sampling. Philosophical Magazine, Series 5, 50(302), 157–175. doi:10.1080/14786440009463897.
Rothman, Greenland & Lash 2008. Rothman, K. J., Greenland, S., & Lash, T. L. (2008). Modern Epidemiology (3rd ed.). Lippincott Williams & Wilkins.
van Elteren 1960. van Elteren, P. H. (1960). On the combination of independent two-sample tests of Wilcoxon. Bulletin of the International Statistical Institute, 37, 351–361.
Woolf 1955. Woolf, B. (1955). On estimating the relation between blood group and disease. Annals of Human Genetics, 19(4), 251–253. doi:10.1111/j.1469-1809.1955.tb01348.x.
Zou 2004. Zou, G. (2004). A modified Poisson regression approach to prospective studies with binary data. American Journal of Epidemiology, 159(7), 702–706. doi:10.1093/aje/kwh090.
Altman 1991. Altman, D. G. (1991). Practical Statistics for Medical Research. Chapman & Hall.
Austin 2009. Austin, P. C. (2009). Balance diagnostics for comparing the distribution of baseline covariates between treatment groups in propensity-score matched samples. Statistics in Medicine, 28(25), 3083–3107. doi:10.1002/sim.3697.
Bland & Altman 1996. Bland, J. M., & Altman, D. G. (1996). Statistics notes: Transforming data. BMJ, 312(7033), 770. doi:10.1136/bmj.312.7033.770.
Yang & Dalton 2012. Yang, D., & Dalton, J. E. (2012). A unified approach to measuring the effect size between two groups using SAS. SAS Global Forum 2012, Paper 335-2012. https://support.sas.com/resources/papers/proceedings12/335-2012.pdf.
Firth 1993. Firth, D. (1993). Bias reduction of maximum likelihood estimates. Biometrika, 80(1), 27–38. doi:10.1093/biomet/80.1.27.
Fox & Monette 1992. Fox, J., & Monette, G. (1992). Generalized collinearity diagnostics. Journal of the American Statistical Association, 87(417), 178–183. doi:10.1080/01621459.1992.10475190.
Hanley, Negassa, Edwardes & Forrester 2003. Hanley, J. A., Negassa, A., Edwardes, M. D., & Forrester, J. E. (2003). Statistical analysis of correlated data using generalized estimating equations: an orientation. American Journal of Epidemiology, 157(4), 364–375. doi:10.1093/aje/kwf215.
Heinze & Schemper 2002. Heinze, G., & Schemper, M. (2002). A solution to the problem of separation in logistic regression. Statistics in Medicine, 21(16), 2409–2419. doi:10.1002/sim.1047.
Long & Ervin 2000. Long, J. S., & Ervin, L. H. (2000). Using heteroscedasticity consistent standard errors in the linear regression model. The American Statistician, 54(3), 217–224. doi:10.1080/00031305.2000.10474549.
Riley 2019. Riley, R. D., Snell, K. I. E., Ensor, J., et al. (2019). Minimum sample size for developing a multivariable prediction model: Part II - binary and time-to-event outcomes. Statistics in Medicine, 38(7), 1276–1296. doi:10.1002/sim.7992.
van Smeden 2016. van Smeden, M., de Groot, J. A. H., Moons, K. G. M., et al. (2016). No rationale for 1 variable per 10 events criterion for binary logistic regression analysis. BMC Medical Research Methodology, 16, 163. doi:10.1186/s12874-016-0267-3.
van Smeden 2019. van Smeden, M., Moons, K. G. M., de Groot, J. A. H., et al. (2019). Sample size for binary logistic prediction models: beyond events per variable criteria. Statistical Methods in Medical Research, 28(8), 2455–2474. doi:10.1177/0962280218784726.
Ver Hoef & Boveng 2007. Ver Hoef, J. M., & Boveng, P. L. (2007). Quasi-Poisson vs. negative binomial regression: how should we model overdispersed count data? Ecology, 88(11), 2766–2772. doi:10.1890/07-0043.1.
Westreich & Greenland 2013. Westreich, D., & Greenland, S. (2013). The Table 2 fallacy: presenting and interpreting confounder and modifier coefficients. American Journal of Epidemiology, 177(4), 292–298. doi:10.1093/aje/kws412.
Cox 1972. Cox, D. R. (1972). Regression models and life-tables. Journal of the Royal Statistical Society, Series B, 34(2), 187–202. doi:10.1111/j.2517-6161.1972.tb00899.x.
Grambsch & Therneau 1994. Grambsch, P. M., & Therneau, T. M. (1994). Proportional hazards tests and diagnostics based on weighted residuals. Biometrika, 81(3), 515–526. doi:10.1093/biomet/81.3.515.
Altman et al. 2000. Altman, D. G., Machin, D., Bryant, T. N., & Gardner, M. J. (2000). Statistics with Confidence (2nd ed.). BMJ Books.
Clopper & Pearson 1934. Clopper, C. J., & Pearson, E. S. (1934). The use of confidence or fiducial limits illustrated in the case of the binomial. Biometrika, 26(4), 404–413. doi:10.1093/biomet/26.4.404.
Cohen 1960. Cohen, J. (1960). A coefficient of agreement for nominal scales. Educational and Psychological Measurement, 20(1), 37–46. doi:10.1177/001316446002000104.
DeLong et al. 1988. DeLong, E. R., DeLong, D. M., & Clarke-Pearson, D. L. (1988). Comparing the areas under two or more correlated receiver operating characteristic curves: a nonparametric approach. Biometrics, 44(3), 837–845. doi:10.2307/2531595.
Ewald 2006. Ewald, B. (2006). Post hoc choice of cut points introduced bias to diagnostic research. Journal of Clinical Epidemiology, 59(8), 798–801. doi:10.1016/j.jclinepi.2005.11.025.
Fleiss, Cohen & Everitt 1969. Fleiss, J. L., Cohen, J., & Everitt, B. S. (1969). Large sample standard errors of kappa and weighted kappa. Psychological Bulletin, 72(5), 323–327. doi:10.1037/h0028106.
Glas et al. 2003. Glas, A. S., Lijmer, J. G., Prins, M. H., Bonsel, G. J., & Bossuyt, P. M. M. (2003). The diagnostic odds ratio: a single indicator of test performance. Journal of Clinical Epidemiology, 56(11), 1129–1135. doi:10.1016/S0895-4356(03)00177-X.
Hanley & McNeil 1982. Hanley, J. A., & McNeil, B. J. (1982). The meaning and use of the area under a receiver operating characteristic (ROC) curve. Radiology, 143(1), 29–36. doi:10.1148/radiology.143.1.7063747.
Robin et al. 2011. Robin, X., Turck, N., Hainard, A., et al. (2011). pROC: an open-source package for R and S+ to analyze and compare ROC curves. BMC Bioinformatics, 12, 77. doi:10.1186/1471-2105-12-77. This is also the source for the "pROC direction = 'auto'" advice tag.
Simel et al. 1991. Simel, D. L., Samsa, G. P., & Matchar, D. B. (1991). Likelihood ratios with confidence: sample size estimation for diagnostic test studies. Journal of Clinical Epidemiology, 44(8), 763–770. doi:10.1016/0895-4356(91)90128-V.
VanderWeele & Ding 2017. VanderWeele, T. J., & Ding, P. (2017). Sensitivity analysis in observational research: introducing the E-value. Annals of Internal Medicine, 167(4), 268–274. doi:10.7326/M16-2607.
Vandenbroucke 2007. Vandenbroucke, J. P., von Elm, E., Altman, D. G., et al. (2007). Strengthening the Reporting of Observational Studies in Epidemiology (STROBE): explanation and elaboration. PLoS Medicine, 4(10), e297. doi:10.1371/journal.pmed.0040297. The explanation of item 14 advises against significance tests in descriptive tables.
STROBE item 14. von Elm, E., Altman, D. G., Egger, M., et al. (2007). The Strengthening the Reporting of Observational Studies in Epidemiology (STROBE) statement: guidelines for reporting observational studies. PLoS Medicine, 4(10), e296. doi:10.1371/journal.pmed.0040296. Item 14 asks for the number of participants with missing data for each variable.
TRIPOD 2015. Collins, G. S., Reitsma, J. B., Altman, D. G., & Moons, K. G. M. (2015). Transparent reporting of a multivariable prediction model for individual prognosis or diagnosis (TRIPOD): the TRIPOD statement. BMJ, 350, g7594. doi:10.1136/bmj.g7594.
advise() and simtablr_guidance() for educator advice.
Build a STARD reporting checklist
stard(x, ...)stard(x, ...)
x |
A SimtablR diagnostic or ROC result, report, or spec. |
... |
Ignored. |
A simtab_checklist object.
d <- diag_test(epitabl, poc_hstn_positive, adjudicated_acs, positive = "Yes", test_positive = "Positive") stard(d)d <- diag_test(epitabl, poc_hstn_positive, adjudicated_acs, positive = "Yes", test_positive = "Positive") stard(d)
Capture a stratifying variable
stratify(spec, by)stratify(spec, by)
spec |
A |
by |
A single data-masked variable. |
A modified simtab_spec.
stratify(describe(simtab(epitabl), age, sex), adjudicated_acs)stratify(describe(simtab(epitabl), age, sex), adjudicated_acs)
Build a STROBE reporting checklist
strobe(x, ...) ## S3 method for class 'simtab_checklist' as_flextable(x, ...)strobe(x, ...) ## S3 method for class 'simtab_checklist' as_flextable(x, ...)
x |
A |
... |
Ignored. |
A simtab_checklist object.
res <- tb(epitabl, sex, diabetes) strobe(res)res <- tb(epitabl, sex, diabetes) strobe(res)
Set or update a SimtablR style
style(x, journal)style(x, journal)
x |
A SimtablR object. |
journal |
A single style or journal preset name. |
A modified SimtablR object.
style(simtab(epitabl), "default")style(simtab(epitabl), "default")
survtab() fits a Cox model to time-to-event data and returns a
publication-style table of hazard ratios with confidence intervals and
p-values. Give the follow-up time, the event indicator, and the predictors;
the proportional hazards assumption is checked automatically. For
outcomes without follow-up time use regtab().
survtab( data, time, event, predictors, design = NULL, conf.level = 0.95, d = 2, labels = NULL, style = "default", exposure = NULL )survtab( data, time, event, predictors, design = NULL, conf.level = 0.95, d = 2, labels = NULL, style = "default", exposure = NULL )
data |
A data frame. |
time |
Follow-up time column: a bare name or string. |
event |
Event indicator column: a bare name or string. May be 0/1, logical, or a two-level factor whose second level is the event. |
predictors |
The right-hand side of the model, as a one-sided formula
( |
design |
String. Optional study design recorded on the result. |
conf.level |
Number between 0 and 1. Confidence level for intervals. |
d |
Integer. Decimal places for hazard ratios and intervals. |
labels |
Named character vector of display labels for model terms,
e.g. |
style |
String. A journal preset name (see |
exposure |
Optional exposure column: a bare name or string, as in
|
The model is fitted with survival::coxph() using the Efron method for
ties. Hazard ratios have Wald confidence intervals. The proportional
hazards assumption is tested with the Grambsch-Therneau test on Schoenfeld
residuals (survival::cox.zph()); when any term fails, a warning is shown
with the result. Concordance and the likelihood-ratio test p-value are
available from generics::glance().
Rows with a missing time, event, or predictor are dropped. The number of
rows and events analysed is shown in the table header and in
model_info().
coef(), confint(), vcov(), formula(), and nobs() work on the
result. model_info() reports convergence, generics::tidy() returns one
row per term, and ggplot2::autoplot() draws a forest plot.
The result is a reporting table, not a fitted model: it keeps no
residuals or fitted values and cannot predict. For stratified or
time-varying models, survival curves, or residual diagnostics, fit
survival::coxph() directly.
A simtab_result of class simtab_cox. Print it to see the
formatted table, convert it with as.data.frame(), or save it with
export_docx(), export_pptx(), or export_xlsx(). Unrounded results
are stored in $data.
Cox, D. R. (1972). Regression models and life-tables. Journal of the Royal Statistical Society, Series B, 34(2), 187–202. doi:10.1111/j.2517-6161.1972.tb00899.x.
Grambsch, P. M., & Therneau, T. M. (1994). Proportional hazards tests and diagnostics based on weighted residuals. Biometrika, 81(3), 515–526. doi:10.1093/biomet/81.3.515.
regtab() for outcomes without follow-up time, model_info()
for convergence, and simtablr_references for all references cited by
SimtablR.
if (requireNamespace("survival", quietly = TRUE)) { # Hazard ratios for major adverse cardiovascular events fit <- survtab( epitabl, time = mace_time_days, event = mace_event, predictors = ~ age + sex + diabetes ) fit # Concordance, likelihood-ratio test, and events analysed generics::glance(fit) }if (requireNamespace("survival", quietly = TRUE)) { # Hazard ratios for major adverse cardiovascular events fit <- survtab( epitabl, time = mace_time_days, event = mace_event, predictors = ~ age + sex + diabetes ) fit # Concordance, likelihood-ratio test, and events analysed generics::glance(fit) }
table1() builds the descriptive "Table 1" of a study in one call: numeric
variables as mean (SD) or median (IQR), categorical variables as counts and
percentages. Add by to get one column per group, optionally with
p-values and crude or adjusted effect measures (PR, RR, or OR). For a single
cross-tabulation use tb(); for full regression output use regtab().
table1( data, vars, by = NULL, ..., flags = character(), measure = NULL, adjust = NULL, test = FALSE, summary = "auto", overall = TRUE, missing = TRUE, denominator = c("available", "complete"), na_model = c("drop", "fail", "explicit"), ref = NULL, var.type = NULL, labels = NULL, style = "default", d = NULL, conf.level = 0.95, design = NULL )table1( data, vars, by = NULL, ..., flags = character(), measure = NULL, adjust = NULL, test = FALSE, summary = "auto", overall = TRUE, missing = TRUE, denominator = c("available", "complete"), na_model = c("drop", "fail", "explicit"), ref = NULL, var.type = NULL, labels = NULL, style = "default", d = NULL, conf.level = 0.95, design = NULL )
data |
A data frame. |
vars |
Variables to describe: bare names in |
by |
Optional grouping variable: a bare name or string. Produces one column per group. |
... |
Terse flags such as |
flags |
Character vector of terse flags, e.g. |
measure |
String. Effect measure to add: |
adjust |
Optional covariates for an adjusted effect-measure column,
given like |
test |
Logical or string. |
summary |
String. Summary for numeric variables: |
overall |
Logical. If |
missing |
Logical. If |
denominator |
String. Which rows the percentages and summaries use:
|
na_model |
String. How adjusted models handle missing values:
|
ref |
Reference level for effect measures: one level for all
variables, or a named list per variable. If |
var.type |
Force variable types: |
labels |
Named character vector of display labels, e.g.
|
style |
Display style: a journal preset name (see |
d |
Integer. Decimal places for percentages and continuous summaries.
If |
conf.level |
Number between 0 and 1. Confidence level for effect measure intervals. |
design |
String. Study design used to choose the effect measure when
|
Crude effect measures for categorical variables use the same estimators as
tb(): the Katz log interval for prevalence and risk ratios (Katz et al.,
1978) and the Woolf logit interval for odds ratios (Woolf, 1955). For
numeric variables, and for every adjusted estimate, a separate generalized
linear model is fitted for each described variable, with the adjust
covariates added. Odds ratios come from logistic regression. Prevalence and
risk ratios come from log-binomial regression, falling back to modified
Poisson regression with robust standard errors when that model does not
converge (Barros & Hirakata, 2003; Zou, 2004). PR and RR are computed identically; only the label
differs.
With test = TRUE, 2x2 tables use the N-1 chi-squared test (Campbell,
2007) and larger tables the Pearson chi-squared test, without continuity
correction; Fisher's exact test is chosen only when an expected count is
below 1. Numeric variables are compared with Welch's t-test or ANOVA when
summarised by the mean, and with the Wilcoxon or Kruskal-Wallis test when
summarised by the median.
Numeric variables are treated as continuous unless they look like coded
categories: exactly two distinct whole numbers, or at most seven distinct
whole numbers with at least 20 observations. Use var.type to override.
By default each variable is described using its own non-missing values,
and a "Missing" row reports how many are absent (STROBE item 14). Tests are
always computed on observed values. denominator = "complete" restricts
the whole table to complete cases, so the displayed numbers can change.
na_model controls only the adjusted models.
Multiplicity adjustment, paired tests, and standardized mean differences
(Austin, 2009) are set afterwards with test(), e.g.
table1(df, vars, by = group, test = TRUE) |> test(p.adjust = "holm", smd = TRUE).
SMDs are reported as absolute values and need a two-level by; numeric
variables use the difference in means over the square root of the
unweighted average of the two group variances, and categorical variables
the multinomial generalisation of Yang & Dalton (2012).
With paired = TRUE, two equal-sized groups are treated as matched pairs in
row order. Use add_effect() to add or replace the effect-measure columns
and fmt() to change decimals.
A simtab_result of class simtab_table1. Print it to see the
formatted table, convert it with as.data.frame(), or save it with
export_docx(), export_pptx(), or export_xlsx(). Unrounded results
are stored in $data.
Flags may be supplied as bare words in ... after by, or programmatically with flags =. Anything else in ... is treated as a typo.
colColumn percentages (the default).
row, cell, perc
Not yet supported by table1().
pr, rr, or
Add the corresponding crude effect measure.
pAdd a p-value from an automatically chosen test, like test = TRUE.
missShow missing values.
The old flags rp and m still work as aliases for pr and miss but are deprecated.
Austin, P. C. (2009). Balance diagnostics for comparing the distribution of baseline covariates between treatment groups in propensity-score matched samples. Statistics in Medicine, 28(25), 3083–3107. doi:10.1002/sim.3697.
Barros, A. J. D., & Hirakata, V. N. (2003). Alternatives for logistic regression in cross-sectional studies: an empirical comparison of models that directly estimate the prevalence ratio. BMC Medical Research Methodology, 3, 21. doi:10.1186/1471-2288-3-21.
Campbell, I. (2007). Chi-squared and Fisher-Irwin tests of two-by-two tables with small sample recommendations. Statistics in Medicine, 26(19), 3661–3675. doi:10.1002/sim.2832.
Katz, D., Baptista, J., Azen, S. P., & Pike, M. C. (1978). Obtaining confidence intervals for the risk ratio in cohort studies. Biometrics, 34(3), 469–474. doi:10.2307/2530610.
Woolf, B. (1955). On estimating the relation between blood group and disease. Annals of Human Genetics, 19(4), 251–253. doi:10.1111/j.1469-1809.1955.tb01348.x.
Zou, G. (2004). A modified Poisson regression approach to prospective studies with binary data. American Journal of Epidemiology, 159(7), 702–706. doi:10.1093/aje/kwh090.
tb() for a single cross-tabulation, add_effect() and test()
to modify the table, journal_style() for formatting, and
simtablr_references for all references cited by SimtablR.
# Describe the whole cohort table1(epitabl, c(age, sex, smoking, bmi)) # Compare groups, with p-values table1(epitabl, c(age, sex, smoking), by = adjudicated_acs, flags = "p") # Crude and age- and sex-adjusted prevalence ratios table1( epitabl, c(smoking, diabetes, hypertension), by = adjudicated_acs, measure = "PR", adjust = c(age, sex) ) # Add standardized mean differences after the fact table1(epitabl, c(age, sex), by = adjudicated_acs, test = TRUE) |> test(smd = TRUE)# Describe the whole cohort table1(epitabl, c(age, sex, smoking, bmi)) # Compare groups, with p-values table1(epitabl, c(age, sex, smoking), by = adjudicated_acs, flags = "p") # Crude and age- and sex-adjusted prevalence ratios table1( epitabl, c(smoking, diabetes, hypertension), by = adjudicated_acs, measure = "PR", adjust = c(age, sex) ) # Add standardized mean differences after the fact table1(epitabl, c(age, sex), by = adjudicated_acs, test = TRUE) |> test(smd = TRUE)
tb() builds a frequency table for one variable, or a cross-tabulation of
two, with optional percentages, an association test, and crude effect
measures (PR, RR, or OR). Put the exposure first (rows) and the outcome
second (columns); a numeric first variable is summarised as mean (SD) or
median (IQR) within each outcome group. For many variables at once use
table1(); for adjusted estimates use regtab().
tb( data, ..., m = FALSE, miss = FALSE, d = 1, big_mark = "", decimal_mark = ".", style = "n_pct", style.rp = "{rp} ({lower} - {upper})", style.or = "{or} ({lower} - {upper})", test = FALSE, subset = NULL, strat = NULL, rp = FALSE, or = FALSE, ref = NULL, conf.level = 0.95, var.type = NULL, summary = "auto", flags = NULL, labels = NULL, measure = NULL, design = NULL )tb( data, ..., m = FALSE, miss = FALSE, d = 1, big_mark = "", decimal_mark = ".", style = "n_pct", style.rp = "{rp} ({lower} - {upper})", style.or = "{or} ({lower} - {upper})", test = FALSE, subset = NULL, strat = NULL, rp = FALSE, or = FALSE, ref = NULL, conf.level = 0.95, var.type = NULL, summary = "auto", flags = NULL, labels = NULL, measure = NULL, design = NULL )
data |
A data frame, or a single vector to tabulate on its own. |
... |
One or two variables to tabulate: bare names, strings, or
tidyselect expressions such as |
m |
Deprecated; use |
miss |
Logical. If |
d |
Integer. Decimal places for percentages and continuous summaries. Effect measures always use two decimals. |
big_mark |
String inserted between every three digits, e.g. |
decimal_mark |
String used as the decimal point, e.g. |
style |
String. How counts and percentages are shown: |
style.rp |
String template for prevalence and risk ratios, using
|
style.or |
String template for odds ratios, using |
test |
Logical or string. |
subset |
A logical expression evaluated in |
strat |
A variable to stratify by: a bare name or string. The table is repeated within each stratum and, if an effect measure is requested, the stratum-specific estimates and a Mantel-Haenszel pooled estimate are added. Row and cell percentages use each stratum as the denominator, so a row's event percentage is the risk within that stratum. |
rp |
Deprecated; use the |
or |
Logical. If |
ref |
Reference level of the row (exposure) variable for effect
measures, given as a level name or its position. If |
conf.level |
Number between 0 and 1. Confidence level for effect measure intervals. |
var.type |
Force variable types: |
summary |
String. Summary for numeric variables: |
flags |
Character vector of terse flags, e.g. |
labels |
Named character vector of display labels, e.g.
|
measure |
String. Effect measure to add: |
design |
String. Study design used to choose the effect measure when
none is requested: |
Effect measures compare each row level with the reference level (ref),
taking the last column level as the event. Prevalence and risk ratios use
the Katz log interval (Katz et al., 1978) and odds ratios the Woolf logit
interval (Woolf, 1955). With strat, stratum-specific tables are pooled
with the Mantel-Haenszel estimator and tested with the Cochran-Mantel-Haenszel
test. Homogeneity across strata is tested with the Breslow-Day test for odds
ratios and, for prevalence and risk ratios, with Cochran's Q on the
inverse-variance weighted stratum log ratios. A stratified numeric variable
is compared within strata: by the F-test for the group term in a linear
model with stratum when summarised by the mean, and by the van Elteren
stratified Wilcoxon test (van Elteren, 1960) for two groups when summarised
by the median.
With test = TRUE, 2x2 tables use the N-1 chi-squared test (Campbell,
2007) and larger tables the Pearson chi-squared test, without continuity
correction. Fisher's exact test is chosen automatically only when an
expected count is below 1; request it with test = "fisher". Numeric
variables are compared with the t-test or ANOVA when summarised by the
mean, and with the Wilcoxon or Kruskal-Wallis test when summarised by the
median.
Numeric variables are treated as continuous unless they look like coded
categories: exactly two distinct whole numbers, or at most seven distinct
whole numbers with at least 20 observations. Use var.type to override.
Missing values are excluded from counts, percentages, tests, and effect
measures. Use the miss flag to display them as a separate category.
Paired tests and multiplicity adjustment are set afterwards with test(),
e.g. tb(df, value, group, test = TRUE) |> test(paired = TRUE). Use
fmt() to change decimals and rbind() to stack several tb() tables
that share the same column variable.
A simtab_result of class simtab_tb. Print it to see the
formatted table, convert it with as.data.frame(), or save it with
export_docx(), export_pptx(), or export_xlsx(). Unrounded results
are stored in $data.
Flags may be supplied as bare words in ... alongside the selected variables, or programmatically with flags =.
rowRow percentages.
colColumn percentages.
cell, perc
Percentages of the table total. perc reads better in one-variable tables.
pr, rr, or
Add the corresponding crude effect measure.
pAdd a p-value from an automatically chosen test, like test = TRUE.
missShow missing values.
The old flags rp and m still work as aliases for pr and miss but are deprecated.
Campbell, I. (2007). Chi-squared and Fisher-Irwin tests of two-by-two tables with small sample recommendations. Statistics in Medicine, 26(19), 3661–3675. doi:10.1002/sim.2832.
Katz, D., Baptista, J., Azen, S. P., & Pike, M. C. (1978). Obtaining confidence intervals for the risk ratio in cohort studies. Biometrics, 34(3), 469–474. doi:10.2307/2530610.
Woolf, B. (1955). On estimating the relation between blood group and disease. Annals of Human Genetics, 19(4), 251–253. doi:10.1111/j.1469-1809.1955.tb01348.x.
Pearson, K. (1900). On the criterion that a given system of deviations from the probable in the case of a correlated system of variables is such that it can be reasonably supposed to have arisen from random sampling. Philosophical Magazine, Series 5, 50(302), 157–175. doi:10.1080/14786440009463897.
Fisher, R. A. (1935). The Design of Experiments. Oliver & Boyd.
table1() for many variables at once, regtab() for adjusted
effect measures, diag_test() for diagnostic accuracy, and
simtablr_references for all references cited by SimtablR.
# Frequencies of one variable tb(epitabl, smoking) # Row percentages, a p-value, and crude prevalence ratios tb(epitabl, smoking, adjudicated_acs, flags = c("row", "pr", "p"), ref = "Never") # The same request with bare flags (shorthand) tb(epitabl, smoking, adjudicated_acs, row, pr, p, ref = "Never") # Odds ratio stratified by sex, with a Mantel-Haenszel pooled estimate tb(epitabl, renal_impairment, adjudicated_acs, strat = sex, flags = "or", ref = "No") # A numeric variable summarised by group tb(epitabl, age, adjudicated_acs, test = TRUE)# Frequencies of one variable tb(epitabl, smoking) # Row percentages, a p-value, and crude prevalence ratios tb(epitabl, smoking, adjudicated_acs, flags = c("row", "pr", "p"), ref = "Never") # The same request with bare flags (shorthand) tb(epitabl, smoking, adjudicated_acs, row, pr, p, ref = "Never") # Odds ratio stratified by sex, with a Mantel-Haenszel pooled estimate tb(epitabl, renal_impairment, adjudicated_acs, strat = sex, flags = "or", ref = "No") # A numeric variable summarised by group tb(epitabl, age, adjudicated_acs, test = TRUE)
Set a comparison test
test(spec, method = "auto", p.adjust = NULL, paired = NULL, smd = NULL)test(spec, method = "auto", p.adjust = NULL, paired = NULL, smd = NULL)
spec |
A |
method |
Test method. Defaults to |
p.adjust |
Multiplicity adjustment method, or |
paired |
Logical; whether paired tests are requested. |
smd |
Logical; whether standardized mean differences are requested. |
A modified simtab_spec.
test(stratify(describe(simtab(epitabl), age), adjudicated_acs), "wilcoxon")test(stratify(describe(simtab(epitabl), age), adjudicated_acs), "wilcoxon")
Tidy a SimtablR result
## S3 method for class 'simtab_result' tidy(x, ...) ## S3 method for class 'simtab_spec' tidy(x, ...)## S3 method for class 'simtab_result' tidy(x, ...) ## S3 method for class 'simtab_spec' tidy(x, ...)
x |
A |
... |
Ignored. |
A long data.frame. For table1, this matches
as.data.frame(x, tidy = TRUE).
res <- tb(epitabl, sex, diabetes) generics::tidy(res)res <- tb(epitabl, sex, diabetes) generics::tidy(res)
Keeps only engine-agnostic checks: spec shape and effect-measure existence.
Per-engine hard errors live in that engine's own validate hook, registered
via register_engine(), and run by evaluate() after this shared check.
validate(spec)validate(spec)
spec |
A |
Invisibly, spec.
sp <- simtab(epitabl) |> describe(hypertension) validate(sp)sp <- simtab(epitabl) |> describe(hypertension) validate(sp)
why() prints the decisions already recorded on a spec, result, or
report. Passing a simtab_spec is inert: it describes the planned analysis
without computing it.
why(x, ...)why(x, ...)
x |
A |
... |
Ignored. |
A simtab_explanation: a character vector with one line per
recorded decision. It prints one line per row; as.character() or
cat(x, sep = "\n") give the plain lines.
res <- tb(epitabl, sex, diabetes) why(res)res <- tb(epitabl, sex, diabetes) why(res)