ucr.base.tab: Create a baseline table

View source: R/ucr_base_tab.r

ucr.base.tabR Documentation

Create a baseline table

Description

Creates a baseline table from a data frame. The data may be partitioned in two or more groups. A column for the "combined" group (all data) can also be included.

Usage

ucr.base.tab(
  data,
  group.name = NULL,
  combined.name = "Combined",
  x.names = setdiff(names(data), group.name),
  num.format = "median",
  median.format = "iqr",
  mean.format = "par",
  factor.format = "count.perc",
  perc.method = "group",
  print.perc = T,
  print.perc.space = F,
  omit.perc.decimal = F,
  use.texttt = F,
  omit.ref.level = F,
  separate.factor.row = F,
  show.missing = "none",
  digits = 1,
  spec.digits = NULL,
  include.combined = T,
  include.n = T,
  include.p = T,
  test.x.names = x.names,
  num.test = "nonparam",
  factor.test = "fisher",
  min.p = "0.001"
)

Arguments

data

The data frame.

group.name

Name of the variable in 'data' that defines the groups, or NULL (default) if there are no groups. The group variable must be a factor without missing..

combined.name

Column heading for the combined group. Defaults to "Combined".

x.names

Names and order of the variables in 'data' that shall be included in the table. By default, all variables except the group variable, if any, are included.

num.format

How to present numerical variables. Allowed values:

  • "median": Median with IQR or range.

  • "mean": Mean with standard deviation.

  • "both": Both. This gives "median stuff (mean stuff)".

median.format

What measure of dispersion to give together with medians. Allowed values:

  • "iqr": Interquartile range (Q1 and Q3).

  • "range": Range (min and max).

  • A numerical value strictly between 0 and 50. Example: If median.format = 10, then the 10th and 90th percentiles will be reported.

mean.format

How to present standard deviations. Allowed values:

  • "par": Mean (SD).

  • "pm": Mean plus/minus SD.

factor.format

How to present factor variables. Allowed values:

  • count.perc: Count (percentage).

  • perc.count: Percentage (count).

perc.method

How to compute percentages for factor variables. Allowed values:

  • "group": Computes n(group, level) / n(group).

  • "level": Computes n(group, level) / n(level). For the combined group, this would always give 100%. Hence, percentages are omitted in this case.

  • "total": Percentage n(group, level) / n.

print.perc

TRUE if a percent sign ('%') is to be printed for percentages.

print.perc.space

TRUE if a space is to be printed between the number and the percent sign, i.e. "12.3 %" rather than "12.3%". N/A if percent sign is disabled.

omit.perc.decimal

TRUE if the decimal is to be omitted for percentages above 1%, e.g. 13% rather than 13.3%.

use.texttt

logical; use latex texttt

omit.ref.level

TRUE if the reference (first) level of dichotomous factor variables should be omitted from the table.

separate.factor.row

TRUE if a separate row is added (first) for each factor, containing the variable name, number of inidividuals/missing etc.

show.missing

How should missing values, if any, per group be shown?

  • "none": Don't show missing values.

  • "in.row": Show the number of missing values within square brackets after the usual data.

  • "sep.row": Show the number of missing values is a separate row.

digits

An integer, giving the number of decimals for numeric variables, unless otherwise specified through the parameter 'spec.digits'.

spec.digits

A list, whose names form a subset of 'x.names', and whose values are the number of decimals for those (numeric) variables. The value NULL causes 'digits' to be used throughout.

include.combined

TRUE if the combined group should be included in a separate column.

include.n

TRUE if number of valid (non-NA) observations per variable should be included in a separate column.

include.p

TRUE if P-values are to be included in the table. They refer to univariate tests for identical distribution in the different groups. P-values can only be included if there are groups.

test.x.names

Names of variables to perform tests for.

num.test

Which kind of test to use for numerical variables. Allowed values:

  • "nonparam": A non-parametrical test:

    • Wilcoxon (Mann-Whitney) test for two groups.

    • Kruskal-Wallis test for three or more groups.

  • "param": A parametrical test:

    • t-test for two groups.

    • ANOVA for three or more groups.

  • "nonparam.trend": The non-parametric Jonckheere-Terpstra trend test, treating the group variable as ordinal. Only for 3+ groups.

  • "param.trend": A parametric trend test (likelihood ratio test for simple linear regression), converting the group variable to linear scores. Only for 3+ groups.

factor.test

Which test to use for factor variables. Allowed values:

  • "fisher": Fisher's exact test.

  • "pearson": Pearson's chi2 test.

  • "trend": Linear-by-linear association test, converting both the group variable and the baseline variable (possibly dichotomous) to linear scores. Only for 3+ groups.

min.p

Smallest P-value to be displayed. If smaller, then a text like "< 0.001" is given. NOTE: This value must be a string, e.g. "0.001" or "1e-3".

Value

The return value is an S3 object of class ucr.base.tab.

Author(s)

Lars Lindhagen


renlund/ucR documentation built on March 25, 2023, 10:10 a.m.