| Title: | Create Elegant Table 1 in HTML/'LaTeX' for Bio-Statistics |
|---|---|
| Description: | Creates the "table one" of bio-medical papers. Fill it with your data and the name of the variable which you'll make the group(s) out of and it will make univariate and bivariate analysis, and parse the result into an HTML or 'LaTeX' table ready to paste into a paper. |
| Authors: | Edouard Baudouin [aut, cre] (ORCID: <https://orcid.org/0000-0002-8324-6908>) |
| Maintainer: | Edouard Baudouin <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 2.2.0 |
| Built: | 2026-09-26 10:19:00 UTC |
| Source: | https://github.com/tiago972/doudpackage |
Method to access parseClass initialize,parseClass-method() elements by name
## S4 method for signature 'parseClass' x[i]## S4 method for signature 'parseClass' x[i]
x |
: Object |
i |
: Element name |
object
Method to access Var elements by name
## S4 method for signature 'Var' x[i]## S4 method for signature 'Var' x[i]
x |
: object |
i |
: value |
object of Var
Method to access VarGroup initialize,VarGroup-method() elements by name
## S4 method for signature 'VarGroup' x[i]## S4 method for signature 'VarGroup' x[i]
x |
: object |
i |
: value |
object element
Method to modify parseClass initialize,parseClass-method() elements by name
## S4 replacement method for signature 'parseClass' x[i] <- value## S4 replacement method for signature 'parseClass' x[i] <- value
x |
: Object |
i |
: Element name |
value |
: Value to be added |
parseClass Object
Method to modify Var elements by name
## S4 replacement method for signature 'Var' x[i] <- value## S4 replacement method for signature 'Var' x[i] <- value
x |
: object |
i |
: Element name |
value |
: Value to be added |
object
Method to modify VarGroup initialize,VarGroup-method() elements by name
## S4 replacement method for signature 'VarGroup' x[i] <- value## S4 replacement method for signature 'VarGroup' x[i] <- value
x |
Object |
i |
Element name |
value |
Value to be added |
object
Generic function of anaBiv which gives bivariate analysis according to group
anaBiv(var, group, parallel, ...)anaBiv(var, group, parallel, ...)
var |
listVar object or data.frame |
group |
Name of the factor variable to make subgroups with |
parallel |
Logical. Make analysis using parallel from |
... |
Further arguments: |
A list of VarGroup object or data.frame
Generic function of anaBiv which gives bivariate analysis according to group
## S4 method for signature 'data.frame,character' anaBiv(var, group, parallel, normality = "normal", digits.p = 3L, ...)## S4 method for signature 'data.frame,character' anaBiv(var, group, parallel, normality = "normal", digits.p = 3L, ...)
var |
listVar object or data.frame |
group |
Name of the factor variable to make subgroups with |
parallel |
Logical. Make analysis using parallel from |
normality |
One of "normal", "non normal" or "assess", as in |
digits.p |
Integer. Significant digits for p value. |
... |
Further arguments: |
A list of VarGroup object or data.frame
# A small simulated clinical trial set.seed(42) n <- 200 patients <- data.frame( arm = factor(sample(c("Placebo", "Treatment"), n, replace = TRUE)), age = round(rnorm(n, mean = 65, sd = 10)), crp = round(rlnorm(n, meanlog = 2, sdlog = 1), 1), sex = factor(sample(c("Female", "Male"), n, replace = TRUE)), diabetes = factor(sample(c("No", "Yes"), n, replace = TRUE, prob = c(0.7, 0.3))), nyha = factor(sample(c("I", "II", "III", "IV"), n, replace = TRUE), ordered = TRUE) ) patients$crp[sample(n, 15)] <- NA # p values only, without the descriptive table res <- anaBiv(patients, group = "arm", parallel = FALSE, normality = "assess") data.frame(variable = sapply(res, function(x) x["name"]), pvalue = sapply(res, function(x) x["pvalue"]))# A small simulated clinical trial set.seed(42) n <- 200 patients <- data.frame( arm = factor(sample(c("Placebo", "Treatment"), n, replace = TRUE)), age = round(rnorm(n, mean = 65, sd = 10)), crp = round(rlnorm(n, meanlog = 2, sdlog = 1), 1), sex = factor(sample(c("Female", "Male"), n, replace = TRUE)), diabetes = factor(sample(c("No", "Yes"), n, replace = TRUE, prob = c(0.7, 0.3))), nyha = factor(sample(c("I", "II", "III", "IV"), n, replace = TRUE), ordered = TRUE) ) patients$crp[sample(n, 15)] <- NA # p values only, without the descriptive table res <- anaBiv(patients, group = "arm", parallel = FALSE, normality = "assess") data.frame(variable = sapply(res, function(x) x["name"]), pvalue = sapply(res, function(x) x["pvalue"]))
Generic function of anaBiv which gives bivariate analysis according to group
## S4 method for signature 'listVar,character' anaBiv(var, group, parallel, ...)## S4 method for signature 'listVar,character' anaBiv(var, group, parallel, ...)
var |
listVar object or data.frame |
group |
Name of the factor variable to make subgroups with |
parallel |
Logical. Make analysis using parallel from |
... |
Further arguments: |
A list of VarGroup object or data.frame
Displays together the univariate analysis (mean/median; SD/IQR; proportions)
and the bivariate analysis (t test/Wilcoxon, ANOVA/Kruskal-Wallis, Chi2 or
Fisher) of every variable of a dataset. The univariate analysis can be
sub-grouped by a variable of interest of n levels; the test applied to each
variable follows from its type and from normality.
descTab( data, group = "", quanti = TRUE, quali = TRUE, na.print = FALSE, pvalue = TRUE, digits.p = 3L, digits.qt = 1L, digits.ql = 1L, normality = "normal", parallel = FALSE, mc.cores = 0 )descTab( data, group = "", quanti = TRUE, quali = TRUE, na.print = FALSE, pvalue = TRUE, digits.p = 3L, digits.qt = 1L, digits.ql = 1L, normality = "normal", parallel = FALSE, mc.cores = 0 )
data |
A dataset. Needs to be a data.frame or a tibble. |
group |
Optional. The name of the factor variable to make sub-groups
comparisons with; it must have at least two non empty levels. Omitted,
|
quanti, quali, na.print, pvalue
|
Logical. If false, won't display
quantitative/qualitative/Missing values/pvalues variable results. |
digits.p |
Integer. Significant digits for p value |
digits.qt |
Integer. Significant digits for mean/median, SD/IQR |
digits.ql |
Integer. Significant digits for proportions |
normality |
One of "normal", "non normal" or "assess". "normal" applies the parametric tests (mean (SD), t test/ANOVA) to every quantitative variable, "non normal" the non parametric ones (median (IQR), Wilcoxon/Kruskal-Wallis), and "assess" decides variable by variable with a Shapiro-Wilk test at the 5% level. |
parallel |
Logical. Make analysis using parallel from |
mc.cores |
If parallel is TRUE, how many cores to use. The default, 0, uses all the cores but one. |
Only numeric, integer and factor (including ordered factor) variables are
described. A variable of any other type is ignored with a warning, as is a
variable whose test cannot be computed: its p value is then NA and the rest
of the table is still produced.
An S4 object of class parseClass. Its ["table"] element is a
data.frame (whether or not there is a group, and also when data is a
tibble) with a var column, one column per level of group, a Total
column and, if there is a group and pvalue = TRUE, a pvalue column.
parseClassFun() to turn the result into an HTML/LaTeX table.
# A small simulated clinical trial set.seed(42) n <- 200 patients <- data.frame( arm = factor(sample(c("Placebo", "Treatment"), n, replace = TRUE)), age = round(rnorm(n, mean = 65, sd = 10)), crp = round(rlnorm(n, meanlog = 2, sdlog = 1), 1), sex = factor(sample(c("Female", "Male"), n, replace = TRUE)), diabetes = factor(sample(c("No", "Yes"), n, replace = TRUE, prob = c(0.7, 0.3))), nyha = factor(sample(c("I", "II", "III", "IV"), n, replace = TRUE), ordered = TRUE) ) patients$crp[sample(n, 15)] <- NA # Compare the two arms. With normality = "assess", age (normal) is described # by mean (SD) with a t test, crp (skewed) by median (IQR) with a Wilcoxon test tab <- descTab(patients, group = "arm", normality = "assess", na.print = TRUE) tab["table"] # No group: a single Total column, no test descTab(patients)["table"] # Quantitative variables only, two decimals descTab(patients, group = "arm", quali = FALSE, digits.qt = 2)["table"] # Render it (see parseClassFun() for the layout options) parseClassFun(tab)# A small simulated clinical trial set.seed(42) n <- 200 patients <- data.frame( arm = factor(sample(c("Placebo", "Treatment"), n, replace = TRUE)), age = round(rnorm(n, mean = 65, sd = 10)), crp = round(rlnorm(n, meanlog = 2, sdlog = 1), 1), sex = factor(sample(c("Female", "Male"), n, replace = TRUE)), diabetes = factor(sample(c("No", "Yes"), n, replace = TRUE, prob = c(0.7, 0.3))), nyha = factor(sample(c("I", "II", "III", "IV"), n, replace = TRUE), ordered = TRUE) ) patients$crp[sample(n, 15)] <- NA # Compare the two arms. With normality = "assess", age (normal) is described # by mean (SD) with a t test, crp (skewed) by median (IQR) with a Wilcoxon test tab <- descTab(patients, group = "arm", normality = "assess", na.print = TRUE) tab["table"] # No group: a single Total column, no test descTab(patients)["table"] # Quantitative variables only, two decimals descTab(patients, group = "arm", quali = FALSE, digits.qt = 2)["table"] # Render it (see parseClassFun() for the layout options) parseClassFun(tab)
anaBiv()
This function is depreciated, please use anaBiv(). anaBiv()
ft_ana_biv(...)ft_ana_biv(...)
... |
None |
No return value, depreciated
descTab()
This function is depreciated, please use anaBiv(). descTab()
ft_desc_tab(...)ft_desc_tab(...)
... |
None |
No return value, depreciated
parseClassFun()
This function is depreciated, please use parseClassFun()
ft_parse(...)ft_parse(...)
... |
None |
No return value, depreciated
Initialization function for parseClass object initialize,parseClass-method()
## S4 method for signature 'parseClass' initialize( .Object, table, group, pvalue, na.print, quanti, quali, var_list, data, digits.qt, digits.ql )## S4 method for signature 'parseClass' initialize( .Object, table, group, pvalue, na.print, quanti, quali, var_list, data, digits.qt, digits.ql )
.Object |
The object to create |
table |
The result of descTab |
group |
The variable from which to make subgroups |
pvalue, na.print, quanti, quali
|
Values from descTab |
var_list |
An object of listVar |
data |
The dataset provided in descTab |
digits.qt, digits.ql
|
As provided in descTab |
parseClass object
Initialization function for Var initialize,Var-method()
## S4 method for signature 'Var' initialize(.Object, name, type, normal)## S4 method for signature 'Var' initialize(.Object, name, type, normal)
.Object |
Object to be initialized |
name |
A character taking name of the variable |
type |
A character taking name of the variable type |
normal |
Logical, if variable, is numeric; is it normal |
Var Object
Initialization function for VarGroup initialize,VarGroup-method()
## S4 method for signature 'VarGroup' initialize( .Object, x, group_var, pvalue, parsed_name, value, missing.value, missing.value.name )## S4 method for signature 'VarGroup' initialize( .Object, x, group_var, pvalue, parsed_name, value, missing.value, missing.value.name )
.Object |
Object to be initialized |
x |
A Var object |
group_var |
The subgroup for which proportions, mean/sd were calculated and missing values |
pvalue |
The calculated pvalue |
parsed_name |
The name of the variable parsed with the n (%), mean (SD) |
value |
The values calculated parsed |
missing.value |
Missing values numbers and proportions n (%) |
missing.value.name |
Missing values concatenate with the level of the variable if it factor |
VarGroup object
Initialization function for parseClass object initialize,parseClass-method()
parseClass( table, group, pvalue, na.print, quanti, quali, var_list, data, digits.qt, digits.ql )parseClass( table, group, pvalue, na.print, quanti, quali, var_list, data, digits.qt, digits.ql )
table |
The result of descTab |
group |
The variable from which to make subgroups |
pvalue, na.print, quanti, quali
|
Values from descTab |
var_list |
An object of listVar |
data |
The dataset provided in descTab |
digits.qt, digits.ql
|
As provided in descTab |
parseClass object
A S4 class containing all the information needed for parsClassFun the missing values and the group for which it was calculated
tableThe result of descTab
groupThe variable from which to make subgroups
pvalue,na.print,quanti,qualiValues from descTab descTab()
var_listAn object of listVar listVar-class()
dataThe dataset provided in descTab
digits.qt,digits.qlAs provided in descTab
Make the LaTeX/HTML table. Generic function
parseClassFun( table, col.order = NULL, levels_to_keep = NULL, group_rows_labels = NULL, font = "arial" )parseClassFun( table, col.order = NULL, levels_to_keep = NULL, group_rows_labels = NULL, font = "arial" )
table |
|
col.order |
Optional. A vector containing the column order. If set, must contain at least all levels of group, without duplicates. Three columns created are "var", "Total", and "pvalue" which can be present in the vector |
levels_to_keep |
Optional, named list. If the variable is binary, which level to keep. Default is the last level of levels(variable). Must be as: list("variable name" = "level to keep"). |
group_rows_labels |
Optional, named list. Create row labels in order to regroup them. Must be as list("label" = c("var1", "var2"), "label2" = c("var3", "var4")). Variable names are matched exactly, and a variable with no row in the table is an error. Rows are reordered to follow the order of the labels and of the variables within each label. |
font |
The HTML font of the table. Default "arial". |
An HTML/LaTex file which can be used directly in Rmarkdown and copy paste
descTab() which produces the object this function renders.
# A small simulated clinical trial set.seed(42) n <- 200 patients <- data.frame( arm = factor(sample(c("Placebo", "Treatment"), n, replace = TRUE)), age = round(rnorm(n, mean = 65, sd = 10)), crp = round(rlnorm(n, meanlog = 2, sdlog = 1), 1), sex = factor(sample(c("Female", "Male"), n, replace = TRUE)), diabetes = factor(sample(c("No", "Yes"), n, replace = TRUE, prob = c(0.7, 0.3))), nyha = factor(sample(c("I", "II", "III", "IV"), n, replace = TRUE), ordered = TRUE) ) patients$crp[sample(n, 15)] <- NA tab <- descTab(patients, group = "arm", normality = "assess", na.print = TRUE) # Default layout parseClassFun(tab) # One line for the binary variables, rows grouped under labels, the Total # column after the arms, and a custom font parseClassFun( tab, levels_to_keep = list(sex = "Female", diabetes = "Yes"), group_rows_labels = list("Demographics" = c("age", "sex"), "Clinical" = c("crp", "diabetes", "nyha")), col.order = c("var", "Placebo", "Treatment", "Total", "pvalue"), font = "Times New Roman" )# A small simulated clinical trial set.seed(42) n <- 200 patients <- data.frame( arm = factor(sample(c("Placebo", "Treatment"), n, replace = TRUE)), age = round(rnorm(n, mean = 65, sd = 10)), crp = round(rlnorm(n, meanlog = 2, sdlog = 1), 1), sex = factor(sample(c("Female", "Male"), n, replace = TRUE)), diabetes = factor(sample(c("No", "Yes"), n, replace = TRUE, prob = c(0.7, 0.3))), nyha = factor(sample(c("I", "II", "III", "IV"), n, replace = TRUE), ordered = TRUE) ) patients$crp[sample(n, 15)] <- NA tab <- descTab(patients, group = "arm", normality = "assess", na.print = TRUE) # Default layout parseClassFun(tab) # One line for the binary variables, rows grouped under labels, the Total # column after the arms, and a custom font parseClassFun( tab, levels_to_keep = list(sex = "Female", diabetes = "Yes"), group_rows_labels = list("Demographics" = c("age", "sex"), "Clinical" = c("crp", "diabetes", "nyha")), col.order = c("var", "Placebo", "Treatment", "Total", "pvalue"), font = "Times New Roman" )
This functions takes the S4 output of descTab to create an HTML parsed table
## S4 method for signature 'parseClass' parseClassFun( table, col.order = NULL, levels_to_keep = NULL, group_rows_labels = NULL, font = "arial" )## S4 method for signature 'parseClass' parseClassFun( table, col.order = NULL, levels_to_keep = NULL, group_rows_labels = NULL, font = "arial" )
table |
|
col.order |
Optional. A vector containing the column order. If set, must contain at least all levels of group, without duplicates. Three columns created are "var", "Total", and "pvalue" which can be present in the vector |
levels_to_keep |
Optional, named list. If the variable is binary, which level to keep. Default is the last level of levels(variable). Must be as: list("variable name" = "level to keep"). |
group_rows_labels |
Optional, named list. Create row labels in order to regroup them. Must be as list("label" = c("var1", "var2"), "label2" = c("var3", "var4")). Variable names are matched exactly, and a variable with no row in the table is an error. Rows are reordered to follow the order of the labels and of the variables within each label. |
font |
The HTML font of the table. Default "arial". |
An HTML/LaTex file which can be used directly in Rmarkdown and copy paste
descTab() which produces the object this function renders.
# A small simulated clinical trial set.seed(42) n <- 200 patients <- data.frame( arm = factor(sample(c("Placebo", "Treatment"), n, replace = TRUE)), age = round(rnorm(n, mean = 65, sd = 10)), crp = round(rlnorm(n, meanlog = 2, sdlog = 1), 1), sex = factor(sample(c("Female", "Male"), n, replace = TRUE)), diabetes = factor(sample(c("No", "Yes"), n, replace = TRUE, prob = c(0.7, 0.3))), nyha = factor(sample(c("I", "II", "III", "IV"), n, replace = TRUE), ordered = TRUE) ) patients$crp[sample(n, 15)] <- NA tab <- descTab(patients, group = "arm", normality = "assess", na.print = TRUE) # Default layout parseClassFun(tab) # One line for the binary variables, rows grouped under labels, the Total # column after the arms, and a custom font parseClassFun( tab, levels_to_keep = list(sex = "Female", diabetes = "Yes"), group_rows_labels = list("Demographics" = c("age", "sex"), "Clinical" = c("crp", "diabetes", "nyha")), col.order = c("var", "Placebo", "Treatment", "Total", "pvalue"), font = "Times New Roman" )# A small simulated clinical trial set.seed(42) n <- 200 patients <- data.frame( arm = factor(sample(c("Placebo", "Treatment"), n, replace = TRUE)), age = round(rnorm(n, mean = 65, sd = 10)), crp = round(rlnorm(n, meanlog = 2, sdlog = 1), 1), sex = factor(sample(c("Female", "Male"), n, replace = TRUE)), diabetes = factor(sample(c("No", "Yes"), n, replace = TRUE, prob = c(0.7, 0.3))), nyha = factor(sample(c("I", "II", "III", "IV"), n, replace = TRUE), ordered = TRUE) ) patients$crp[sample(n, 15)] <- NA tab <- descTab(patients, group = "arm", normality = "assess", na.print = TRUE) # Default layout parseClassFun(tab) # One line for the binary variables, rows grouped under labels, the Total # column after the arms, and a custom font parseClassFun( tab, levels_to_keep = list(sex = "Female", diabetes = "Yes"), group_rows_labels = list("Demographics" = c("age", "sex"), "Clinical" = c("crp", "diabetes", "nyha")), col.order = c("var", "Placebo", "Treatment", "Total", "pvalue"), font = "Times New Roman" )
Initialization function for Var initialize,Var-method()
Var(name, type = "", normal = TRUE)Var(name, type = "", normal = TRUE)
name |
A character taking name of the variable |
type |
A character taking name of the variable type |
normal |
Logical, if variable, is numeric; is it normal |
Var Object
A S4 class containing name, type and normality assessment of variable
nameA character taking name of the variable
typeA character taking name of the variable type
normalLogical, if variable, is numeric; is it normal
A S4 class containing Var initialize,Var-method() It also contains the pvalue, the parsed value
the missing values and the group for which it was calculated
group_varThe subgroup for which proportions, mean/sd were calculated and missing values
pvalueThe calculated pvalue
parsed_nameThe name of the variable parsed with the n (%), mean (SD)
valueThe values calculated parsed
missing.valueMissing values numbers and proportions n (%)
missing.value.nameMissing values concatenate with the level of the variable if it factor