summaries: Simple Univariate Summary Functions

summariesR Documentation

Simple Univariate Summary Functions

Description

Simple univariate summary functions which are applied to each level of a grouping factor. These functions include arguments for labeling and formatting the summary.

Usage

nequals(x, lab = NULL)
npct(x, lab = NULL, ref = NULL, dig = 0, p = NULL, p.args = NULL, ...)
mediqr(x, lab = NULL, dig = 0, p = NULL, p.args = NULL, ...)
meansd(x, lab = NULL, dig = 0, p = NULL, p.args = NULL, ...)

Arguments

x

The variable to summarize. If x is a categorical variable, it is suggested that it be a factor.

lab

A length-one character vector indicating the label to give to the summary.

ref

A length-one character vector indicating the single “reference level” to use for a number-and-percentage summary provided by npct. For example, with a factor variable with levels of "Yes" and "No", ref = "Yes" would give the number and percentage only for the Yeses. By default ref is NULL which means to summarize all levels of a factor.

dig

The number of digits past the decimal place to display in the formatted summary.

p

The abbreviation for the function to call for calculating a p-value.

tt t.test
ct chisq.test
p.args

A list of further arguments that is passed to the p-value function. For example, yat(outcome ~ npct(treatment, p = "ct", p.args = list(correct = FALSE))).

...

Currently ignored.

Value

nequals

a character vector giving the number at each level of x in the form of the level followed by the number in parentheses. For example, c("<group1> (n=<number1>)", ...). This kind of output often appears at the top of a summary table.

npct

a character vector giving, by default, the number and percentage at each level of x. If ref is specified, the result is a length-one character vector giving the number and percent for just the “reference” level.

mediqr

a length-one character vector providing the formatted numeric summary of the median and inter-quartile range of x.

meansd

a length-one character vector providing the formatted numeric summary of the mean and SD of x.

Each of these functions attaches the value of lab as a comment attribute. For the npct function, the comment will be a character vector where the first element is the value of lab and the other elements are the categories or levels summarized. This use (or abuse) of the comment attribute stems from model.frame allowing the comment attribute to “pass through” to the resulting data.frame.

Note

If these functions are called on a vector of data the p and p.args arguments are ignored. It is only when these functions are used in a formula with a grouping variable on the left hand side that yat will calculate a p-value.

Author(s)

Stephen Weigand <weigand.stephen@mayo.edu>

Examples


set.seed(1)

nequals(rpois(25, 1), lab = "Poisson lambda=1")

npct(factor(rbinom(25, size = 1, prob = 0.5),
            labels = c("Heads", "Tails")),
     lab = "Number (%)",
     ref = "Heads")

mediqr(rnorm(25), dig = 1)

## 'p' ignored in univariate case
mediqr(rnorm(25), dig = 1, p = "tt")

meansd(rnorm(25), lab = "Mean (SD) of 25 N(0, 1)s", dig = 1)


data(warpbreaks)
yat(1 + wool ~
      meansd(breaks, p = "tt"),
    data = warpbreaks)

yat(1 + wool ~ npct(tension) + mediqr(breaks), warpbreaks)


yat documentation built on April 29, 2022, 3 p.m.

Related to summaries in yat...