| Type: | Package |
| Title: | Create Demographic Table |
| Version: | 0.2.4 |
| Date: | 2026-09-25 |
| Description: | To create demographic table with simple summary statistics, with optional comparison(s) over one or more groups. |
| License: | GPL-2 |
| Encoding: | UTF-8 |
| Language: | en-US |
| Depends: | R (≥ 4.6) |
| Imports: | cli, flextable, officer, scales |
| Suggests: | knitr, quarto, rmarkdown |
| VignetteBuilder: | quarto |
| Config/roxygen2/version: | 8.1.0 |
| Config/roxygen2/markdown: | TRUE |
| NeedsCompilation: | no |
| Packaged: | 2026-09-25 23:37:19 UTC; tingtingzhan |
| Author: | Tingting Zhan [aut, cre] |
| Maintainer: | Tingting Zhan <tingtingzhan@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-09-25 23:50:10 UTC |
DemographicTable: Create Demographic Table
Description
To create demographic table with simple summary statistics, with optional comparison(s) over one or more groups.
Note
Help files of individual functions are intentionally suppressed in the pdf manual.
Users are encouraged to get started with
vignette('intro', package = 'DemographicTable')
Author(s)
Maintainer: Tingting Zhan tingtingzhan@gmail.com
Authors:
Tingting Zhan tingtingzhan@gmail.com
Demographic Table
Description
To create a demographic table with simple summary statistics, with optional comparison(s) over one or more groups.
Usage
DemographicTable(data, data.name = substitute(data), by = NULL, ...)
Arguments
data |
|
data.name |
character scalar,
or the argument call of |
by |
one-sided formula,
the name(s) of sub-group(s) for which the summary statistics are provided.
Default |
... |
additional parameters, currently not in use |
Details
A demographic table with simple summary statistics, with optional comparison(s) over one or more groups, is created.
numeric variables are summarized in means, standard deviations, medians, inter-quartile-ranges (IQR),
p-value of Shapiro-Wilk normality test and ranges.
If group is specified, they are compared using two-sample t.test,
wilcox.test (Wilcoxon / Mann-Whitney), one-way aov (ANOVA) and/or
kruskal.test (Kruskal-Wallis).
logical and factor variables are summarized in counts and percentages.
If group is specified, they are compared using prop.test (chi-squared)
and/or fisher.test (Fisher's exact).
Value
The function DemographicTable() returns an object of S3 class 'DemographicTable',
which is a listof 'sumtab' elements.
p-value from modified Shapiro-Wilk Normality Test
Description
Obtain p-value from shapiro.test,
taking into consideration of several exceptions.
Usage
pval_shapiro(x, CLT = FALSE, ...)
Arguments
x |
|
CLT |
logical scalar, whether to allow the use of Central Limit Theorem, default |
... |
additional parameters, currently not in use |
Details
The function pval_shapiro() provides a pseudo p-value for several exceptions of
shapiro.test, serving as a criteria of whether robust statistics/tests need to be used
length(x) < 3Lreturns
p=0, indicating that robust methods are needed.length(x) > 5e3Lreturns
p=1, indicating that no robust method is needed. For such large sample size, robust methods could be too slow.CLT & length(x) > 30Lreturns
p=1, indicating that no robust method is needed because of the use of Central Limit Theorem.- all
xvalues are identical (or all.equal, to be implemented in future release) returns
p=0, indicating that robust methods are needed.- Otherwise
use the
p-value from shapiro.test.
Value
The function pval_shapiro() returns a double scalar.
Note
The function shapiro.test return does not contain sample size (as of R 4.5.2).
Examples
rnorm(5) |>
pval_shapiro()
airquality |>
with.default(expr = split(Ozone, f = Month)) |>
sapply(FUN = pval_shapiro)
Summary Statistics
Description
Summary statistics to be presented in a DemographicTable.
Usage
.sumstat(x, fmt, ...)
## Default S3 method:
.sumstat(x, fmt = "%.2f", ...)
## S3 method for class 'factor'
.sumstat(x, ...)
## S3 method for class 'character'
.sumstat(x, ...)
## S3 method for class 'logical'
.sumstat(x, ...)
Arguments
x |
an R object |
fmt |
(optional) character scalar, only for the function |
... |
additional parameters, currently not in use |
Details
The function .sumstat.default() accepts all R objects of typeof double and integer.
Statistics of mean, sd and range are reported.
If the normality assumption via shapiro.test is not satisfied, then median and mad are also reported.
Value
The function .sumstat() returns a character scalar.
Examples
airquality$Solar.R |> .sumstat()
state.region |> .sumstat()