Overview

Rbearcat provides three table functions that apply UC styling automatically:

Function Purpose
bcat_reg_table() Regression results (wraps modelsummary)
bcat_sum_table() Descriptive / summary statistics
bcat_cor_table() Correlation matrix with significance stars

All three auto-detect the output format (HTML, PDF, Word) and style accordingly.

library(Rbearcat)

Regression Tables with bcat_reg_table()

Single Model

m1 <- lm(mpg ~ wt + hp, data = mtcars)
bcat_reg_table(m1, caption = "Model 1: MPG predicted by Weight and Horsepower")
Table 1: Model 1: MPG predicted by Weight and Horsepower
Model 1
(Intercept) 37.227***
(1.599)
Wt −3.878***
(0.633)
Hp −0.032***
(0.009)
Num.Obs. 32
R2 0.827
R2 Adj. 0.815
* p < 0.1, ** p < 0.05, *** p < 0.01

Comparing Multiple Models

Pass a named list of models to display them side by side:

m2 <- lm(mpg ~ wt + hp + cyl, data = mtcars)
m3 <- lm(mpg ~ wt + hp + cyl + disp, data = mtcars)

bcat_reg_table(
  list("Base" = m1, "Add Cylinders" = m2, "Full" = m3),
  caption = "Comparing Nested OLS Models"
)
Table 2: Comparing Nested OLS Models
Base Add Cylinders Full
(Intercept) 37.227*** 38.752*** 40.829***
(1.599) (1.787) (2.757)
Wt −3.878*** −3.167*** −3.854***
(0.633) (0.741) (1.015)
Hp −0.032*** −0.018 −0.021
(0.009) (0.012) (0.012)
Cyl −0.942* −1.293*
(0.551) (0.656)
Disp 0.012
(0.012)
Num.Obs. 32 32 32
R2 0.827 0.843 0.849
R2 Adj. 0.815 0.826 0.826
* p < 0.1, ** p < 0.05, *** p < 0.01

Robust Standard Errors

Use se_type to pass a heteroskedasticity-consistent variance estimator:

bcat_reg_table(m1, se_type = "HC1", caption = "HC1 Robust Standard Errors")
Table 3: HC1 Robust Standard Errors
Model 1
(Intercept) 37.227***
(2.037)
Wt −3.878***
(0.651)
Hp −0.032***
(0.007)
Num.Obs. 32
R2 0.827
R2 Adj. 0.815
* p < 0.1, ** p < 0.05, *** p < 0.01

Custom Coefficient Names and GOF

bcat_reg_table(
  m2,
  coef_rename = c("wt" = "Weight (1000 lbs)",
                   "hp" = "Horsepower",
                   "cyl" = "Cylinders"),
  gof_map = c("nobs", "r.squared", "adj.r.squared"),
  caption = "Custom Labels"
)
Table 4: Custom Labels
Model 1
(Intercept) 38.752***
(1.787)
Weight (1000 lbs) −3.167***
(0.741)
Horsepower −0.018
(0.012)
Cylinders −0.942*
(0.551)
Num.Obs. 32
R2 0.843
R2 Adj. 0.826
* p < 0.1, ** p < 0.05, *** p < 0.01

Changing Significance Stars

bcat_reg_table(
  m1,
  stars = c("+" = 0.1, "*" = 0.05, "**" = 0.01, "***" = 0.001),
  caption = "Alternative Star Convention"
)
Table 5: Alternative Star Convention
Model 1
(Intercept) 37.227***
(1.599)
Wt −3.878***
(0.633)
Hp −0.032**
(0.009)
Num.Obs. 32
R2 0.827
R2 Adj. 0.815
+ p < 0.1, * p < 0.05, ** p < 0.01, *** p < 0.001

Summary Statistics with bcat_sum_table()

Basic Usage

Pass a data frame (or subset of columns) to get mean, SD, min, median, max, N, and percent missing:

bcat_sum_table(
  mtcars[, c("mpg", "wt", "hp", "qsec")],
  caption = "Descriptive Statistics for mtcars"
)
Table 6: Descriptive Statistics for mtcars
Variable Mean Sd Min Median Max n % Missing
mpg 20.09 6.03 10.40 19.20 33.90 32 0
wt 3.22 0.98 1.51 3.33 5.42 32 0
hp 146.69 68.56 52.00 123.00 335.00 32 0
qsec 17.85 1.79 14.50 17.71 22.90 32 0

Grouped Summaries

Use by to compute statistics within groups:

bcat_sum_table(
  mtcars[, c("mpg", "wt", "hp", "cyl")],
  by = "cyl",
  caption = "Summary Statistics by Cylinder Count"
)
Table 7: Summary Statistics by Cylinder Count
Cyl Variable Mean Sd Min Median Max n % Missing
6 mpg 19.74 1.45 17.80 19.70 21.40 7 0
6 wt 3.12 0.36 2.62 3.21 3.46 7 0
6 hp 122.29 24.26 105.00 110.00 175.00 7 0
4 mpg 26.66 4.51 21.40 26.00 33.90 11 0
4 wt 2.29 0.57 1.51 2.20 3.19 11 0
4 hp 82.64 20.93 52.00 91.00 113.00 11 0
8 mpg 15.10 2.56 10.40 15.20 19.20 14 0
8 wt 4.00 0.76 3.17 3.76 5.42 14 0
8 hp 209.21 50.98 150.00 192.50 335.00 14 0

Selecting Statistics

Choose only the statistics you need:

bcat_sum_table(
  mtcars[, c("mpg", "hp")],
  stats = c("mean", "sd", "n"),
  caption = "Mean, SD, and N Only"
)
Table 8: Mean, SD, and N Only
Variable Mean Sd n
mpg 20.09 6.03 32
hp 146.69 68.56 32

Correlation Matrices with bcat_cor_table()

Basic Correlation Matrix

By default, shows the lower triangle with Pearson correlations and significance stars:

bcat_cor_table(
  mtcars[, c("mpg", "wt", "hp", "disp", "qsec")],
  caption = "Pearson Correlation Matrix"
)
Table 9: Pearson Correlation Matrix
Variable mpg wt hp disp qsec
mpg 1
wt -0.87*** 1
hp -0.78*** 0.66*** 1
disp -0.85*** 0.89*** 0.79*** 1
qsec 0.42** -0.17 -0.71*** -0.43** 1
Note: * p<0.1 ** p<0.05 *** p<0.01

Full Matrix with Spearman Method

bcat_cor_table(
  mtcars[, c("mpg", "wt", "hp")],
  method = "spearman",
  full_matrix = TRUE,
  caption = "Full Spearman Correlation Matrix"
)
Table 10: Full Spearman Correlation Matrix
Variable mpg wt hp
mpg 1 -0.89*** -0.89***
wt -0.89*** 1 0.77***
hp -0.89*** 0.77*** 1
Note: * p<0.1 ** p<0.05 *** p<0.01

Without Stars

bcat_cor_table(
  mtcars[, c("mpg", "wt", "hp")],
  stars = FALSE,
  caption = "Correlation Matrix (No Stars)"
)
Table 11: Correlation Matrix (No Stars)
Variable mpg wt hp
mpg 1
wt -0.87 1
hp -0.78 0.66 1

General Table Styling with bcat_fmt_style_table()

For any data frame, bcat_fmt_style_table() applies UC header colors and formatting:

bcat_fmt_style_table(
  head(iris, 8),
  caption = "Iris Sample",
  striped = TRUE
)
Table 12: Iris Sample
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
5.1 3.5 1.4 0.2 setosa
4.9 3.0 1.4 0.2 setosa
4.7 3.2 1.3 0.2 setosa
4.6 3.1 1.5 0.2 setosa
5.0 3.6 1.4 0.2 setosa
5.4 3.9 1.7 0.4 setosa
4.6 3.4 1.4 0.3 setosa
5.0 3.4 1.5 0.2 setosa

Spanning Headers

bcat_fmt_style_table(
  head(iris, 5),
  header = "Iris Dataset — First 5 Rows",
  caption = "With Spanning Header"
)
Table 13: With Spanning Header
Iris Dataset — First 5 Rows
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
5.1 3.5 1.4 0.2 setosa
4.9 3.0 1.4 0.2 setosa
4.7 3.2 1.3 0.2 setosa
4.6 3.1 1.5 0.2 setosa
5.0 3.6 1.4 0.2 setosa

Customizing Appearance

All table functions share these styling parameters:

Parameter Default Description
header_bg_color UC Red Header background color
header_txt_color "white" Header text color
font_size 12 Font size
striped TRUE Zebra-striped rows
caption NULL Table caption
footer NULL Table footnote
bcat_reg_table(
  m1,
  header_bg_color = palette_UC[["Bearcats Black"]],
  font_size = 11,
  footer = "Source: mtcars dataset",
  caption = "Custom Styled Table"
)
Table 14: Custom Styled Table
Model 1
(Intercept) 37.227***
(1.599)
Wt −3.878***
(0.633)
Hp −0.032***
(0.009)
Num.Obs. 32
R2 0.827
R2 Adj. 0.815
* p < 0.1, ** p < 0.05, *** p < 0.01
Note: Source: mtcars dataset