Type: | Package |
Title: | Create Summary Tables for Statistical Reports |
Version: | 5.1.1 |
Date: | 2021-08-01 |
Author: | Dane R. Van Domelen |
Maintainer: | Dane R. Van Domelen <vandomed@gmail.com> |
Description: | Contains functions for creating various types of summary tables, e.g. comparing characteristics across levels of a categorical variable and summarizing fitted generalized linear models, generalized estimating equations, and Cox proportional hazards models. Functions are available to handle data from simple random samples as well as complex surveys. |
License: | GPL (≥ 3) |
LazyData: | true |
Encoding: | UTF-8 |
Depends: | dplyr, knitr |
Imports: | kableExtra, MASS, stats, survey (≥ 4.1) |
RoxygenNote: | 7.1.1 |
Suggests: | gee, rmarkdown, survival |
VignetteBuilder: | knitr |
NeedsCompilation: | no |
Packaged: | 2021-08-02 00:29:41 UTC; vando |
Repository: | CRAN |
Date/Publication: | 2021-08-02 04:30:02 UTC |
Format P-values for Functions in the tab Package
Description
Formats p-values for tables generated by the functions in the tab package. Handles rounding and presentation of p-values.
Usage
formatp(
p,
decimals = c(2, 3),
cuts = 0.01,
lowerbound = 0.001,
leading0 = TRUE,
avoid1 = FALSE
)
Arguments
p |
Numeric vector of p-values. |
decimals |
Number of decimal places for p-values. If a vector is
provided rather than a single value, number of decimal places will depend on
what range the p-value lies in. See |
cuts |
Cut-point(s) to control number of decimal places used for
p-values. For example, by default |
lowerbound |
Controls cut-point at which p-values are no longer printed
as their value, but rather <lowerbound. For example, by default
|
leading0 |
If |
avoid1 |
If |
Value
Character vector.
Examples
# Generate vector of numeric p-values
set.seed(123)
p <- c(runif(n = 5, min = 0, max = 1), 1, 0, 4e-7, 0.009)
# Round to nearest 2 decimals for p in (0.01, 1] and 3 decimals for p < 0.01
pvals <- formatp(p = p)
# Use 2 decimal places, a lower bound of 0.01, and omit the leading 0
pvals <- formatp(p = p, decimals = 2, lowerbound = 0.01, leading0 = FALSE)
Print a GLM Summary Table to the RStudio Viewer
Description
You can call this function as you would glm
or pass a
previously fitted glm
object. Either way, the result is
a summary table printed to the Viewer.
Usage
glm_v(...)
Arguments
... |
Arguments to pass to glm. |
Value
kable
Examples
# Fit and view
glm_v(death_1yr ~ Age + Sex + Race, data = tabdata, family = "binomial")
# Fit then view
fit <- glm(death_1yr ~ Age + Sex + Race, data = tabdata, family = "binomial")
glm_v(fit)
# Piping is OMG so cool Hashtag HexStickerz
fit %>% glm_v()
Create Summary Tables for Statistical Reports
Description
Contains functions for creating various types of summary tables, e.g. comparing characteristics across levels of a categorical variable and summarizing fitted generalized linear models, generalized estimating equations, and Cox proportional hazards models. Functions are available to handle data from simple random samples as well as complex surveys.
Details
Package: | tab |
Type: | Package |
Version: | 5.1.1 |
Date: | 2021-08-01 |
License: | GPL-3 |
See CRAN documentation for full list of functions.
Author(s)
Dane R. Van Domelen
vandomed@gmail.com
References
Acknowledgment: This material is based upon work supported by the National Science Foundation Graduate Research Fellowship under Grant No. DGE-0940903.
Create Summary Table for Fitted Cox Proportional Hazards Model
Description
Creates a table summarizing a GEE fit using the coxph
function.
Usage
tabcoxph(
fit,
columns = c("beta.se", "hr.ci", "p"),
var.labels = NULL,
factor.compression = 1,
sep.char = ", ",
decimals = 2,
formatp.list = NULL
)
Arguments
fit |
Fitted |
columns |
Character vector specifying what columns to include. Choies
for each element are |
var.labels |
Named list specifying labels to use for certain predictors.
For example, if |
factor.compression |
Integer value from 1 to 5 controlling how much compression is applied to factor predictors (higher value = more compression). If 1, rows are Variable, Level 1 (ref), Level 2, ...; if 2, rows are Variable (ref = Level 1), Level 2, ...; if 3, rows are Level 1 (ref), Level 2, ...; if 4, rows are Level 2 (ref = Level 1), ...; if 5, rows are Level 2, ... |
sep.char |
Character string with separator to place between lower and
upper bound of confidence intervals. Typically |
decimals |
Numeric value specifying number of decimal places for numbers other than p-values. |
formatp.list |
List of arguments to pass to |
Value
References
1. Therneau, T. (2015). A Package for Survival Analysis in S. R package version 2.38. https://cran.r-project.org/package=survival.
2. Therneau, T.M. and Grambsch, P.M. (2000). Modeling Survival Data: Extending the Cox Model. Springer, New York. ISBN 0-387-98784-3.
Examples
# Cox PH model with age, sex, race, and treatment
library("survival")
fit <- coxph(
Surv(time = time, event = delta) ~ Age + Sex + Race + Group,
data = tabdata
)
tabcoxph(fit)
# Can also use piping
fit %>% tabcoxph()
# Same as previous, but with custom labels for Age and Race and factors
# displayed in slightly more compressed format
fit %>%
tabcoxph(
var.labels = list(Age = "Age (years)", Race = "Race/ethnicity"),
factor.compression = 2
)
# Cox PH model with some higher-order terms
fit <- coxph(
Surv(time = time, event = delta) ~
poly(Age, 2, raw = TRUE) + Sex + Race + Group + Race*Group,
data = tabdata
)
fit %>% tabcoxph()
Sample Dataset for tab Package
Description
Data frame with 15 variables, used to illustrate certain functions.
Source
Simulated data in R
Create Frequency Table
Description
Creates an I-by-J frequency table comparing the distribution of y
across levels of x
.
Usage
tabfreq(
formula = NULL,
data = NULL,
x = NULL,
y = NULL,
columns = c("xgroups", "p"),
cell = "counts",
parenth = "col.percent",
sep.char = ", ",
test = "chi.fisher",
xlevels = NULL,
yname = NULL,
ylevels = NULL,
compress.binary = FALSE,
yname.row = TRUE,
text.label = NULL,
quantiles = NULL,
quantile.vals = FALSE,
decimals = 1,
formatp.list = NULL,
n.headings = FALSE,
kable = TRUE
)
Arguments
formula |
Formula, e.g. |
data |
Data frame containing variables named in |
x |
Vector indicating group membership for columns of I-by-J table. |
y |
Vector indicating group membership for rows of I-by-J table. |
columns |
Character vector specifying what columns to include. Choices
for each element are |
cell |
Character string specifying what statistic to display in cells.
Choices are |
parenth |
Character string specifying what statistic to display in
parentheses. Choices are |
sep.char |
Character string with separator to place between lower and
upper bound of confidence intervals. Typically |
test |
Character string specifying which test for association between
|
xlevels |
Character vector with labels for the levels of |
yname |
Character string with a label for the |
ylevels |
Character vector with labels for the levels of |
compress.binary |
Logical value for whether to compress binary |
yname.row |
Logical value for whether to include a row displaying the
name of the |
text.label |
Character string with text to put after the |
quantiles |
Numeric value. If specified, table compares |
quantile.vals |
Logical value for whether labels for |
decimals |
Numeric value specifying number of decimal places for numbers other than p-values. |
formatp.list |
List of arguments to pass to |
n.headings |
Logical value for whether to display group sample sizes in parentheses in column headings. |
kable |
Logical value for whether to return a
|
Value
Examples
# Compare sex distribution by group
(freqtable1 <- tabfreq(Sex ~ Group, data = tabdata))
# Same as previous, but showing male row only and % (SE) rather than n (%)
(freqtable2 <- tabfreq(Sex ~ Group, data = tabdata,
cell = "col.percent", parenth = "se",
compress.binary = TRUE))
Create Frequency Table (for Complex Survey Data)
Description
Creates an I-by-J frequency table comparing the distribution of y
across levels of x
.
Usage
tabfreq.svy(
formula,
design,
columns = c("xgroups", "p"),
cell = "col.percent",
parenth = "se",
sep.char = ", ",
xlevels = NULL,
yname = NULL,
ylevels = NULL,
compress.binary = FALSE,
yname.row = TRUE,
text.label = NULL,
decimals = 1,
svychisq.list = NULL,
formatp.list = NULL,
n.headings = FALSE,
N.headings = FALSE,
kable = TRUE
)
Arguments
formula |
Formula, e.g. |
design |
Survey design object from |
columns |
Character vector specifying what columns to include. Choices
for each element are |
cell |
Character string specifying what statistic to display in cells.
Choices are |
parenth |
Character string specifying what statistic to display in
parentheses. Choices are |
sep.char |
Character string with separator to place between lower and
upper bound of confidence intervals. Typically |
xlevels |
Character vector with labels for the levels of |
yname |
Character string with a label for the |
ylevels |
Character vector with labels for the levels of |
compress.binary |
Logical value for whether to compress binary |
yname.row |
Logical value for whether to include a row displaying the
name of the |
text.label |
Character string with text to put after the |
decimals |
Numeric value specifying number of decimal places for numbers other than p-values. |
svychisq.list |
List of arguments to pass to
|
formatp.list |
List of arguments to pass to |
n.headings |
Logical value for whether to display unweighted sample sizes in parentheses in column headings. |
N.headings |
Logical value for whether to display weighted sample sizes in parentheses in column headings. |
kable |
Logical value for whether to return a
|
Details
Basically tabmedians
for complex survey data. Relies heavily on
the survey package.
Value
kable
or character matrix.
Examples
# Create survey design object
library("survey")
design <- svydesign(
data = tabsvydata,
ids = ~sdmvpsu,
strata = ~sdmvstra,
weights = ~wtmec2yr,
nest = TRUE
)
# Compare race distribution by sex
tabfreq.svy(Race ~ Sex, design)
Create Summary Table for Fitted Generalized Estimating Equation Model
Description
Creates a table summarizing a GEE fit using the gee
function.
Usage
tabgee(
fit,
data = NULL,
columns = NULL,
robust = TRUE,
var.labels = NULL,
factor.compression = 1,
sep.char = ", ",
decimals = 2,
formatp.list = NULL
)
Arguments
fit |
Fitted |
data |
Data frame that served as 'data' in function call to
|
columns |
Character vector specifying what columns to include. Choices
for each element are |
robust |
Logical value for whether to use robust standard errors. |
var.labels |
Named list specifying labels to use for certain predictors.
For example, if |
factor.compression |
Integer value from 1 to 5 controlling how much compression is applied to factor predictors (higher value = more compression). If 1, rows are Variable, Level 1 (ref), Level 2, ...; if 2, rows are Variable (ref = Level 1), Level 2, ...; if 3, rows are Level 1 (ref), Level 2, ...; if 4, rows are Level 2 (ref = Level 1), ...; if 5, rows are Level 2, ... |
sep.char |
Character string with separator to place between lower and
upper bound of confidence intervals. Typically |
decimals |
Numeric value specifying number of decimal places for numbers other than p-values. |
formatp.list |
List of arguments to pass to |
Value
Examples
# Load in sample dataset and convert to long format
tabdata2 <- reshape(data = tabdata,
varying = c("bp.1", "bp.2", "bp.3", "highbp.1",
"highbp.2", "highbp.3"),
timevar = "bp.visit", direction = "long")
tabdata2 <- tabdata2[order(tabdata2$id), ]
# Blood pressure at 1, 2, and 3 months vs. age, sex, race, and treatment
library("gee")
fit <- gee(bp ~ Age + Sex + Race + Group, id = id, data = tabdata2,
corstr = "unstructured")
tabgee(fit)
# Can also use piping
fit %>% tabgee(data = tabdata2)
# Same as previous, but with custom labels for Age and Race and factors
# displayed in slightly more compressed format
fit %>%
tabgee(
data = tabdata2,
var.labels = list(Age = "Age (years)", Race = "Race/ethnicity"),
factor.compression = 2
)
# GEE with some higher-order terms
# higher-order terms
fit <- gee(
highbp ~ poly(Age, 2, raw = TRUE) + Sex + Race + Group + Race*Group,
id = id,
data = tabdata2,
family = "binomial",
corstr = "unstructured"
)
fit %>% tabgee(data = tabdata2)
Create Summary Table for Fitted Generalized Linear Model
Description
Creates a table summarizing a GLM fit using glm
.
Usage
tabglm(
fit,
columns = NULL,
xvarlabels = NULL,
factor.compression = 1,
sep.char = ", ",
decimals = 2,
formatp.list = NULL
)
Arguments
fit |
Fitted |
columns |
Character vector specifying what columns to include. Choices
for each element are |
xvarlabels |
Named list specifying labels to use for certain predictors.
For example, if |
factor.compression |
Integer value from 1 to 5 controlling how much compression is applied to factor predictors (higher value = more compression). If 1, rows are Variable, Level 1 (ref), Level 2, ...; if 2, rows are Variable (ref = Level 1), Level 2, ...; if 3, rows are Level 1 (ref), Level 2, ...; if 4, rows are Level 2 (ref = Level 1), ...; if 5, rows are Level 2, ... |
sep.char |
Character string with separator to place between lower and
upper bound of confidence intervals. Typically |
decimals |
Numeric value specifying number of decimal places for numbers other than p-values. |
formatp.list |
List of arguments to pass to |
Value
Examples
# Linear regression: BMI vs. age, sex, race, and treatment
fit <- glm(BMI ~ Age + Sex + Race + Group, data = tabdata)
tabglm(fit)
# Can also use piping
fit %>% tabglm()
# Logistic regression: 1-year mortality vs. age, sex, race, and treatment
fit <- glm(
death_1yr ~ Age + Sex + Race + Group,
data = tabdata,
family = binomial
)
fit %>% tabglm()
# Same as previous, but with custom labels for Age and Race and factors
# displayed in slightly more compressed format
fit %>%
tabglm(
xvarlabels = list(Age = "Age (years)", Race = "Race/ethnicity"),
factor.compression = 2
)
# Logistic regression model with some higher-order terms
fit <- glm(
death_1yr ~ poly(Age, 2, raw = TRUE) + Sex + BMI + Sex * BMI,
data = tabdata,
family = "binomial"
)
fit %>% tabglm()
Create Table Comparing Group Means
Description
Creates a table comparing the mean of y
across levels of x
.
Usage
tabmeans(
formula = NULL,
data = NULL,
x = NULL,
y = NULL,
columns = c("xgroups", "p"),
parenth = "sd",
sep.char = ", ",
variance = "unequal",
xlevels = NULL,
yname = NULL,
text.label = NULL,
quantiles = NULL,
quantile.vals = FALSE,
decimals = NULL,
formatp.list = NULL,
n.headings = TRUE,
kable = TRUE
)
Arguments
formula |
Formula, e.g. |
data |
Data frame containing variables named in |
x |
Vector of values for the categorical |
y |
Vector of values for the continuous |
columns |
Character vector specifying what columns to include. Choices
for each element are |
parenth |
Character string specifying what statistic to display in
parentheses after the means. Choices are |
sep.char |
Character string with separator to place between lower and
upper bound of confidence intervals. Typically |
variance |
Character string specifying which version of the two-sample
t-test to use if |
xlevels |
Character vector with labels for the levels of |
yname |
Character string with a label for the |
text.label |
Character string with text to put after the |
quantiles |
Numeric value. If specified, table compares |
quantile.vals |
Logical value for whether labels for |
decimals |
Numeric value specifying number of decimal places for numbers other than p-values. |
formatp.list |
List of arguments to pass to |
n.headings |
Logical value for whether to display group sample sizes in parentheses in column headings. |
kable |
Logical value for whether to return a
|
Details
A t-test is used to compare means if x
has two levels, and a one-way
analysis of variance is used if x
has more than two levels.
Observations with missing values for x
and/or y
are dropped.
Value
kable
or character matrix.
Examples
# Compare mean BMI in control vs. treatment group in sample dataset
(meanstable1 <- tabmeans(BMI ~ Group, data = tabdata))
# Compare mean baseline systolic BP across tertiles of BMI
(meanstable2 <- tabmeans(bp.1 ~ BMI, data = tabdata,
quantiles = 3, yname = "Systolic BP"))
Create Table Comparing Group Means (for Complex Survey Data)
Description
Creates a table comparing the mean of y
across levels of x
.
Usage
tabmeans.svy(
formula,
design,
columns = c("xgroups", "p"),
parenth = "sd",
sep.char = ", ",
xlevels = NULL,
yname = NULL,
text.label = NULL,
decimals = 1,
anova.svyglm.list = NULL,
formatp.list = NULL,
n.headings = FALSE,
N.headings = FALSE,
kable = TRUE
)
Arguments
formula |
Formula, e.g. |
design |
Survey design object from |
columns |
Character vector specifying what columns to include. Choices
for each element are |
parenth |
Character string specifying what statistic to display in
parentheses after the means. Choices are |
sep.char |
Character string with separator to place between lower and
upper bound of confidence intervals. Typically |
xlevels |
Character vector with labels for the levels of |
yname |
Character string with a label for the |
text.label |
Character string with text to put after the |
decimals |
Numeric value specifying number of decimal places for numbers other than p-values. |
anova.svyglm.list |
List of arguments to pass to
|
formatp.list |
List of arguments to pass to |
n.headings |
Logical value for whether to display group sample sizes in parentheses in column headings. |
N.headings |
Logical value for whether to display weighted sample sizes in parentheses in column headings. |
kable |
Logical value for whether to return a
|
Details
Basically tabmeans
for complex survey data. Relies heavily on
the survey package.
Value
kable
or character matrix.
Examples
# Create survey design object
library("survey")
design <- svydesign(
data = tabsvydata,
ids = ~sdmvpsu,
strata = ~sdmvstra,
weights = ~wtmec2yr,
nest = TRUE
)
# Compare mean BMI by sex
(meanstable <- tabmeans.svy(BMI ~ Sex, design = design))
Create Table Comparing Group Medians
Description
Creates a table comparing the median of y
across levels of x
.
Usage
tabmedians(
formula = NULL,
data = NULL,
x = NULL,
y = NULL,
columns = c("xgroups", "p"),
parenth = "iqr",
sep.char = ", ",
xlevels = NULL,
yname = NULL,
text.label = NULL,
quantiles = NULL,
quantile.vals = FALSE,
decimals = NULL,
formatp.list = NULL,
n.headings = TRUE,
kable = TRUE
)
Arguments
formula |
Formula, e.g. |
data |
Data frame containing variables named in |
x |
Vector of values for the categorical |
y |
Vector of values for the continuous |
columns |
Character vector specifying what columns to include. Choices
for each element are |
parenth |
Character string specifying what values are shown in
parentheses after the medians in each cell. Choices are |
sep.char |
Character string with separator to place between lower and
upper bound of confidence intervals. Typically |
xlevels |
Character vector with labels for the levels of |
yname |
Character string with a label for the |
text.label |
Character string with text to put after the |
quantiles |
Numeric value. If specified, table compares |
quantile.vals |
Logical value for whether labels for |
decimals |
Numeric value specifying number of decimal places for numbers other than p-values. |
formatp.list |
List of arguments to pass to |
n.headings |
Logical value for whether to display group sample sizes in parentheses in column headings. |
kable |
Logical value for whether to return a
|
Details
If x
has 2 levels, a Mann-Whitney U (also known as Wilcoxon
rank-sum) test is used to test whether the distribution of y
differs
in the two groups; if x
has more than 2 levels, a Kruskal-Wallis test
is used to test whether the distribution of y
differs across at
least two of the groups. Observations with missing values for x
and/or
y
are dropped.
Value
Examples
# Compare median BMI in control group vs. treatment group in sample dataset
(medtable1 <- tabmedians(BMI ~ Group, data = tabdata))
# Compare median baseline systolic BP across tertiles of BMI
(medtable2 <- tabmedians(bp.1 ~ BMI, data = tabdata,
quantiles = 3, yname = "Systolic BP"))
Create Table Comparing Group Medians (for Complex Survey Data)
Description
Creates a table comparing the median of y
across levels of x
.
Usage
tabmedians.svy(
formula,
design,
columns = c("xgroups", "p"),
parenth = "iqr",
sep.char = ", ",
xlevels = NULL,
yname = NULL,
text.label = NULL,
decimals = NULL,
svyranktest.list = NULL,
formatp.list = NULL,
n.headings = FALSE,
N.headings = FALSE,
kable = TRUE
)
Arguments
formula |
Formula, e.g. |
design |
Survey design object from |
columns |
Character vector specifying what columns to include. Choices
for each element are |
parenth |
Character string specifying what values are shown in
parentheses after the medians in each cell. Choices are |
sep.char |
Character string with separator to place between lower and
upper bound of confidence intervals. Typically |
xlevels |
Character vector with labels for the levels of |
yname |
Character string with a label for the |
text.label |
Character string with text to put after the |
decimals |
Numeric value specifying number of decimal places for numbers other than p-values. |
svyranktest.list |
List of arguments to pass to
|
formatp.list |
List of arguments to pass to |
n.headings |
Logical value for whether to display group sample sizes in parentheses in column headings. |
N.headings |
Logical value for whether to display weighted sample sizes in parentheses in column headings. |
kable |
Logical value for whether to return a
|
Details
Basically tabmedians
for complex survey data. Relies heavily on
the survey package.
Value
kable
or character matrix.
Examples
# Create survey design object
library("survey")
design <- svydesign(
data = tabsvydata,
ids = ~sdmvpsu,
strata = ~sdmvstra,
weights = ~wtmec2yr,
nest = TRUE
)
# Compare median BMI by sex
(medtable1 <- tabmedians.svy(BMI ~ Sex, design = design))
Create Table Comparing Characteristics Across Levels of a Categorical Variable
Description
Creates a table comparing multiple characteristics (e.g. median age, mean
BMI, and race/ethnicity distribution) across levels of x
.
Usage
tabmulti(
formula = NULL,
data,
xvarname = NULL,
yvarnames = NULL,
ymeasures = NULL,
columns = c("xgroups", "p"),
listwise.deletion = FALSE,
sep.char = ", ",
xlevels = NULL,
yvarlabels = NULL,
ylevels = NULL,
quantiles = NULL,
quantile.vals = FALSE,
decimals = NULL,
formatp.list = NULL,
n.headings = FALSE,
tabmeans.list = NULL,
tabmedians.list = NULL,
tabfreq.list = NULL,
kable = TRUE
)
Arguments
formula |
Formula, e.g. |
data |
Data frame containing variables named in |
xvarname |
Character string with name of column variable. Should be one
of |
yvarnames |
Character vector with names of row variables. Each element
should be one of |
ymeasures |
Character vector specifying whether each |
columns |
Character vector specifying what columns to include. Choices
for each element are |
listwise.deletion |
Logical value for whether observations with missing
values for any |
sep.char |
Character string with separator to place between lower and
upper bound of confidence intervals. Typically |
xlevels |
Character vector with labels for the levels of |
yvarlabels |
Named list specifying labels for certain |
ylevels |
Character vector (if only 1 frequency comparison) or list of
character vectors with labels for the levels of each categorical |
quantiles |
Numeric value. If specified, function compares |
quantile.vals |
Logical value for whether labels for |
decimals |
Numeric vector specifying number of decimal places for
numbers other than p-values for each |
formatp.list |
List of arguments to pass to |
n.headings |
Logical value for whether to display group sample sizes in parentheses in column headings. |
tabmeans.list |
List of arguments to pass to |
tabmedians.list |
List of arguments to pass to |
tabfreq.list |
List of arguments to pass to |
kable |
Logical value for whether to return a
|
Value
kable
or character matrix.
Examples
# Compare age, sex, race, and BMI in control vs. treatment group
tabmulti(Age + Sex + Race + BMI ~ Group, data = tabdata)
# Same as previous, but compare medians rather than means for BMI
tabmulti(Age + Sex + Race + BMI ~ Group, data = tabdata,
ymeasures = c("mean", "freq", "freq", "median"))
Create Table Comparing Characteristics Across Levels of a Categorical Variable (for Complex Survey Data)
Description
Creates a table comparing multiple characteristics (e.g. median age, mean
BMI, and race/ethnicity distribution) across levels of x
.
Usage
tabmulti.svy(
formula = NULL,
design,
xvarname = NULL,
yvarnames = NULL,
ymeasures = NULL,
columns = c("xgroups", "p"),
listwise.deletion = FALSE,
sep.char = ", ",
xlevels = NULL,
yvarlabels = NULL,
ylevels = NULL,
decimals = NULL,
formatp.list = NULL,
n.headings = FALSE,
N.headings = FALSE,
kable = TRUE,
tabmeans.svy.list = NULL,
tabmedians.svy.list = NULL,
tabfreq.svy.list = NULL
)
Arguments
formula |
Formula, e.g. |
design |
Survey design object from |
xvarname |
Character string with name of column variable. Should be one
of |
yvarnames |
Character vector with names of row variables. Each element
should be one of |
ymeasures |
Character vector specifying whether each |
columns |
Character vector specifying what columns to include. Choices
for each element are |
listwise.deletion |
Logical value for whether observations with missing
values for any |
sep.char |
Character string with separator to place between lower and
upper bound of confidence intervals. Typically |
xlevels |
Character vector with labels for the levels of |
yvarlabels |
Named list specifying labels for certain |
ylevels |
Character vector (if only 1 frequency comparison) or list of
character vectors with labels for the levels of each categorical |
decimals |
Numeric vector specifying number of decimal places for
numbers other than p-values for each |
formatp.list |
List of arguments to pass to |
n.headings |
Logical value for whether to display unweighted sample sizes in parentheses in column headings. |
N.headings |
Logical value for whether to display weighted sample sizes in parentheses in column headings. |
kable |
Logical value for whether to return a
|
tabmeans.svy.list |
List of arguments to pass to
|
tabmedians.svy.list |
List of arguments to pass to
|
tabfreq.svy.list |
List of arguments to pass to
|
Details
Basically tabmulti
for complex survey data. Relies heavily on
the survey package.
Value
kable
or character matrix.
Examples
# Create survey design object
library("survey")
design <- svydesign(
data = tabsvydata,
ids = ~sdmvpsu,
strata = ~sdmvstra,
weights = ~wtmec2yr,
nest = TRUE
)
# Compare age, race, and BMI by sex
tabmulti.svy(Age + Race + BMI ~ Sex, design)
Create Regression Table from Betas and Standard Errors
Description
Useful for quickly creating a summary table.
Usage
tabreg(
betas,
ses = NULL,
varcov = NULL,
columns = c("beta.se", "p"),
sep.char = ", ",
decimals = NULL,
formatp.list = NULL,
labels = NULL
)
Arguments
betas |
Numeric vector. |
ses |
Numeric vector. |
varcov |
Numeric matrix. |
columns |
Character vector specifying what columns to include. Choices
are |
sep.char |
Character string with separator to place between lower and
upper bound of confidence intervals. Typically |
decimals |
Numeric value specifying number of decimal places for numbers other than p-values. |
formatp.list |
List of arguments to pass to |
labels |
Character vector. |
Value
Examples
# Create summary table for mtcars regression
fit <- lm(mpg ~ wt + hp + drat, data = mtcars)
tabreg(
betas = fit$coef,
varcov = vcov(fit),
labels = c("Intercept", "Weight", "HP", "Rear axle ratio")
)
Sample Survey Dataset for tab Package
Description
Data frame with with 9 variables, used to illustrate certain functions. Data are derived from the National Health and Nutrition Examination Survey, years 2003-2004, although the variables 'time' and 'event' are simulated (fake).
Source
https://wwwn.cdc.gov/Nchs/Nhanes/2003-2004/DEMO_C.htm
References
Centers for Disease Control and Prevention (CDC). National Center for Health Statistics (NCHS). National Health and Nutrition Examination Survey Data. Hyattsville, MD: US Department of Health and Human Services, Centers for Disease Control and Prevention, 2003-2004. https://wwwn.cdc.gov/nchs/nhanes/continuousnhanes/default.aspx?BeginYear=2003. Accessed June 8, 2019.
Output a Table to the RStudio Viewer
Description
Does some basic formatting and then calls kable
and
kable_styling
to print table to Viewer.
Usage
toviewer(x)
Arguments
x |
Character matrix |