Learn R Programming

plotrix (version 3.4-5)

brkdnNest: Perform a nested breakdown of numeric values

Description

Breaks down a numeric or categorical element of a data frame by one or more categorical elements.

Usage

brkdnNest(formula,data,FUN=c("mean","sd"),label1="Overall",trueval=NA)

Arguments

formula
A formula with a numeric element of a data frame on the left and one or more categorical elements on the right.
data
A data frame containing the elements in formula.
FUN
The functions to be applied to successive breakdowns.
label1
The label to use for the overall value of the first function.
trueval
The value to use in calculating proportions or sums of a categorical response variable. See Details.

Value

  • A list with as many elements as there are functions in FUN. This function is similar to brkdn in the prettyR package, but is structured to be used with the barNest function. It produces one or more measures for the overall data, then the subsets of the data defined by the first variable to the right of the tilde, then the subsets defined by the first and second variable, and so on.

Details

brkdnNest performs a nested breakdown of an element of a data frame by one or more categorical elements. For each category and optionally subcategories, the variable on the left of the formula is summarized as specified by the functions named in FUN.

If trueval is not NA, brkdnNest will calculate the proportion of trueval values in the response variable out of the total valid responses. If the function valid.n is the first function in FUN, the counts of the groups and subgroups will be returned.

Two specialized summary functions are defined within brkdnNest for use when the trueval argument is not NA. sumbrk returns the count of values in a factor equal to trueval, while propbrk returns the proportion of values equal to trueval.

The user should take care when specifying different summary functions. barNest expects a measure of central tendency or counting function as the first function and measures of dispersion as the second and optionally third, if "error bars" are to be displayed. If two confidence interval functions are passed, the first must calculate the upper and the second the lower CI. The user must also decide whether the "error bars" have any useful meaning.

See Also

by

Examples

Run this code
brkdntest<-data.frame(Age=rnorm(100,25,10),
  Sex=sample(c("M","F"),100,TRUE),
  Marital=sample(c("M","X","S","W"),100,TRUE),
  Employ=sample(c("FT","PT","NO"),100,TRUE))
 brkdnNest(formula=Age~Sex+Marital+Employ,data=brkdntest)
 # show the proportion of unemployed with binomial confidence intervals
 brkdnNest(formula=Employ~Sex+Marital,data=brkdntest,
  FUN=c("propbrk","binciWu","binciWl"),trueval="NO")

Run the code above in your browser using DataLab