| Title: | Easy Publication-Ready Tables and Regression Analysis |
| Version: | 1.0.1 |
| Description: | Streamlines the creation of descriptive frequency tables ('Table 1'), diagnostic test accuracy evaluations (sensitivity, specificity, predictive values), and multi-outcome regression summaries. Features automatic tables, prevalence and odds ratio calculations, and seamless integration with 'flextable' for exporting results to 'Microsoft Word' and 'PowerPoint'. |
| License: | MIT + file LICENSE |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.2 |
| Imports: | cli, dplyr, flextable, lmtest, openxlsx, sandwich, stats, tidyr, utils |
| Suggests: | knitr, rmarkdown, testthat |
| VignetteBuilder: | knitr |
| Depends: | R (≥ 3.5) |
| LazyData: | true |
| URL: | https://github.com/MatheusTG-14/SimtablR, https://MatheusTG-14.github.io/SimtablR/ |
| BugReports: | https://github.com/MatheusTG-14/SimtablR/issues |
| NeedsCompilation: | no |
| Packaged: | 2026-02-12 02:46:23 UTC; mathe |
| Author: | Matheus Trabuco Gonzalez [aut, cre] |
| Maintainer: | Matheus Trabuco Gonzalez <matheustrabucogonzalez@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-02-16 17:50:07 UTC |
SimtablR: 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 automatic tables, prevalence and odds ratio calculations, and seamless integration with 'flextable' for exporting results to 'Microsoft Word' and 'PowerPoint'.
Author(s)
Maintainer: Matheus Trabuco Gonzalez matheustrabucogonzalez@gmail.com
See Also
Useful links:
Report bugs at https://github.com/MatheusTG-14/SimtablR/issues
Convert diag_test Object to Data Frame
Description
Convert diag_test Object to Data Frame
Usage
## S3 method for class 'diag_test'
as.data.frame(x, ...)
Arguments
x |
A diag_test object |
... |
Additional arguments (unused) |
Value
A data.frame containing the performance metrics
Convert tb to Data Frame
Description
Extracts the data from a tb object as a standard data.frame.
Usage
## S3 method for class 'tb'
as.data.frame(x, ...)
Arguments
x |
A |
... |
Additional arguments. |
Value
A data.frame with the formatted table.
Convert tb object to flextable
Description
Converts a tb object into a flextable for high-quality reporting
in Word or PowerPoint.
Usage
## S3 method for class 'tb'
as_flextable(x, ...)
Arguments
x |
A |
... |
Additional arguments passed to |
Value
A flextable object ready for printing or exporting.
Diagnostic Test Accuracy Assessment
Description
Computes a comprehensive confusion matrix and diagnostic performance metrics for binary classification tests.
Usage
diag_test(
data,
test,
ref,
positive = NULL,
test_positive = NULL,
conf.level = 0.95
)
Arguments
data |
A data.frame containing the test and reference variables. |
test |
Unquoted name of the diagnostic test variable (binary). |
ref |
Unquoted name of the reference standard variable (binary). |
positive |
Character or numeric. Level representing "Positive" in REFERENCE. |
test_positive |
Character or numeric. Level representing "Positive" in TEST. |
conf.level |
Numeric. Confidence level (0-1). Default: 0.95. |
Details
Confusion Matrix Structure The function creates a 2x2 confusion matrix:
TP: True Positives
TN: True Negatives
FP: False Positives
FN: False Negatives
Metrics Calculated
Sensitivity, Specificity, PPV, NPV
Accuracy, Prevalence
Likelihood Ratios, Youden's Index, F1 Score
Value
An object of class diag_test containing:
-
table: 2x2 confusion matrix -
stats: Data frame with metrics and CIs -
labels: List with labels used -
sample_size: Total valid observations
Simulated Epidemiological Dataset
Description
A simulated dataset containing demographic, clinical, and outcome variables for 500 individuals. Designed for demonstrating table creation and diagnostic testing analysis.
Usage
epitabl
Format
A data frame with 500 rows and 19 variables:
- id
Unique patient identifier
- age
Age in years (Numeric)
- sex
Biological sex (Female, Male)
- bmi
Body Mass Index in kg/m2 (Numeric, contains NAs)
- smoking
Smoking status (Never, Former, Current)
- exercise
Physical activity level (Low, Moderate, High)
- education
Educational attainment (High School, Some College, College+)
- income
Annual household income (<30k, 30-60k, 60k+)
- disease
Disease status - primary outcome (No, Yes)
- rapid_test
Result of rapid diagnostic test (Negative, Positive)
- lab_confirmed
Laboratory confirmation - gold standard (No, Yes)
- comorbidity_score
Score 0-5 based on medical history
- outcome1
Count of primary care visits in past year
- outcome2
Count of specialist visits in past year
- outcome3
Count of emergency department visits in past year
- hospitalized
Hospitalized in past year (No, Yes)
- systolic_bp
Systolic blood pressure in mmHg
- cholesterol
Total cholesterol in mg/dL
- region
Geographic region (North, South, East, West)
Source
Simulated data for the SimtablR package.
Examples
data(epitabl)
# Basic description
tb(epitabl, sex, disease)
Export regtab Results to CSV
Description
Export regtab Results to CSV
Usage
export_regtab_csv(x, file, ...)
Arguments
x |
A data.frame from regtab |
file |
File path for export |
... |
Additional arguments passed to write.csv |
Value
No return value, called for side effects
Export regtab Results to Excel
Description
Requires the 'openxlsx' package
Usage
export_regtab_xlsx(x, file, ...)
Arguments
x |
A data.frame from regtab |
file |
File path for export (.xlsx) |
... |
Additional arguments passed to openxlsx::write.xlsx |
Value
No return value, called for side effects
Plot Diagnostic Test Results
Description
Visualizes the confusion matrix using a fourfold plot.
Usage
## S3 method for class 'diag_test'
plot(x, col = c("#ffcccc", "#ccffcc"), main = "Confusion Matrix", ...)
Arguments
x |
A diag_test object. |
col |
Vector of 2 colors for Negative and Positive outcomes. |
main |
Title of the plot. |
... |
Additional arguments passed to |
Value
No return value, called for side effects
Print Method for diag_test Objects
Description
Print Method for diag_test Objects
Usage
## S3 method for class 'diag_test'
print(x, digits = 3, ...)
Arguments
x |
A diag_test object |
digits |
Number of decimal places for metrics (default: 3) |
... |
Additional arguments (unused) |
Value
No return value, called for side effects
Print Method for regtab Results
Description
Print Method for regtab Results
Usage
## S3 method for class 'regtab'
print(x, ...)
Arguments
x |
A data.frame returned by regtab |
... |
Additional arguments passed to print |
Value
No return value, called for side effects
Print Method for tb Objects
Description
Prints a formatted table with flags and attributes.
Usage
## S3 method for class 'tb'
print(x, digits = NULL, ...)
Arguments
x |
A |
digits |
Number of decimal places to display. |
... |
Additional arguments. |
Value
No return value, called for side effects
Multi-Outcome Regression Table
Description
Fits generalized linear models (GLMs) for multiple outcome variables and generates a formatted wide-format table with point estimates and confidence intervals. Supports robust standard errors, automatic exponentiation for count/binary outcomes, and custom labeling for publication-ready tables.
Usage
regtab(
data,
outcomes,
predictors,
family = poisson(link = "log"),
robust = TRUE,
exponentiate = NULL,
labels = NULL,
d = 2,
conf.level = 0.95,
include_intercept = FALSE,
p_values = FALSE
)
Arguments
data |
Data.frame containing all variables for analysis. |
outcomes |
Character vector of dependent variable names. Each outcome is modeled separately with the same set of predictors. |
predictors |
Formula or character string specifying predictors. Can be:
|
family |
GLM family specification. Options:
|
robust |
Logical. If TRUE (default), calculates heteroskedasticity-consistent (HC0) robust standard errors via the sandwich package. CIs are based on robust SEs. |
exponentiate |
Logical. If TRUE, exponentiates coefficients and CIs:
If NULL (default), automatically detects: TRUE for Poisson/Binomial, FALSE for Gaussian. |
labels |
Named character vector for renaming outcome columns in output.
Format: |
d |
Integer. Number of decimal places for rounding estimates and CIs. Default: 2. |
conf.level |
Numeric. Confidence level for intervals (0-1). Default: 0.95. |
include_intercept |
Logical. If TRUE, includes intercept in output table. Default: FALSE (typically excluded from publication tables). |
p_values |
Logical. If TRUE, adds p-values as separate column. Default: FALSE. |
Details
Model Fitting
For each outcome, the function fits:
glm(outcome ~ predictors, family = family, data = data)
Robust Standard Errors
When robust = TRUE, the function:
Fits the model with standard GLM.
Computes sandwich covariance matrix (HC0 estimator).
Calculates Wald-type CIs based on robust SEs.
This provides protection against heteroskedasticity and mild model misspecification.
Exponentiation
-
Poisson regression: exp(beta) = Incidence Rate Ratio
IRR = 1: No association
IRR > 1: Increased rate
IRR < 1: Decreased rate
-
Logistic regression: exp(beta) = Odds Ratio
OR = 1: No association
OR > 1: Increased odds
OR < 1: Decreased odds
Output Format
Returns a wide-format data.frame:
Variable | Outcome1 | Outcome2 | ... ------------|-------------------|-------------------|---- (Intercept) | 2.34 (1.89-2.91) | 1.98 (1.65-2.38) | ... age | 1.05 (1.02-1.08) | 1.03 (1.01-1.06) | ... sex | 0.87 (0.75-1.01) | 0.92 (0.81-1.05) | ...
Each cell contains: "Estimate (Lower CI - Upper CI)"
Missing Data
GLM uses complete cases by default. Observations with missing values in any variable are excluded from that specific model.
Convergence Issues
If a model fails to converge or encounters errors:
A warning is issued with the outcome name and error message
That outcome column is skipped in the output
Other outcomes continue processing
Value
A data.frame in wide format with:
-
Variable: Predictor names (first column)
-
Outcome columns: One column per outcome with formatted estimates and CIs
Can be directly exported to Excel, Word, or LaTeX for publication.
Examples
# Create example data
set.seed(456)
n <- 500
df <- data.frame(
age = rnorm(n, 50, 10),
sex = factor(sample(c("M", "F"), n, replace = TRUE)),
treatment = factor(sample(c("A", "B"), n, replace = TRUE)),
outcome1 = rpois(n, lambda = 5),
outcome2 = rpois(n, lambda = 8),
outcome3 = rpois(n, lambda = 3)
)
# Basic usage: Poisson regression for multiple outcomes
regtab(df,
outcomes = c("outcome1", "outcome2", "outcome3"),
predictors = ~ age + sex + treatment,
family = poisson(link = "log"))
# With custom labels and no robust SEs
regtab(df,
outcomes = c("outcome1", "outcome2"),
predictors = "age + sex",
labels = c(outcome1 = "Primary Endpoint", outcome2 = "Secondary Endpoint"),
robust = FALSE)
# Logistic regression with p-values
df$binary_outcome <- rbinom(n, 1, 0.4)
regtab(df,
outcomes = "binary_outcome",
predictors = ~ age + sex,
family = binomial(),
p_values = TRUE)
Frequency and Summary Tables
Description
Creates comprehensive tables for categorical or continuous variables with formatting, statistical tests, prevalence ratios (PR), odds ratios (OR), and column stratification. Supports both univariate and bivariate analysis with flexible output formatting.
Usage
tb(
data,
...,
m = FALSE,
d = 1,
format = TRUE,
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,
stat.cont = "median"
)
Arguments
data |
A data.frame or atomic vector. |
... |
Variables to be tabulated. Can include variable names and/or flags (m, p, row, col, rp, or) for controlling output format. |
m |
Logical. If TRUE, includes missing values (NA) in the table. Default: FALSE. |
d |
Integer. Number of decimal places for percentages and statistics. Default: 1. |
format |
Logical. If TRUE, renders a formatted grid output (Stata-style). If FALSE, prints as simple matrix. Default: TRUE. |
style |
Character. Format for displaying counts and percentages. Options:
|
style.rp |
Character. Format string for Prevalence Ratio. Default: |
style.or |
Character. Format string for Odds Ratio. Default: |
test |
Logical or Character. Performs statistical test on 2x2+ tables.
|
subset |
Logical expression for row filtering. |
strat |
Variable for column stratification. Disables PR/OR calculations. |
rp |
Logical. If TRUE, calculates Prevalence Ratios (PR). |
or |
Logical. If TRUE, calculates Odds Ratios (OR). |
ref |
Character or numeric. Specifies the reference level for PR/OR calculations. |
conf.level |
Numeric. Confidence level for intervals (0-1). Default: 0.95. |
var.type |
Named character vector specifying variable types.
|
stat.cont |
Character. "mean" (Mean/SD) or "median" (Median/IQR). |
Value
An object of class tb which is a matrix with attributes containing
statistics, formatted flags, and class information.