Learn R Programming

plotrix (version 2.8-2)

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,maxlevels=10,mct=mean,lmd=std.error,umd=lmd,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.
maxlevels
The maximum number of levels in any categorical element. Mainly to prevent the mess caused by breaking down by a huge number of categories.
mct
The measure of central tendency function to use (default is the mean).
lmd
The lower measure of dispersion function to use (default is standard error).
umd
The upper measure of dispersion function to use.
trueval
The value to use in calculating proportions of a categorical response variable. See Details.

Value

  • A list with four elements:
  • mctlistThe list of arrays produced by the function passed as the mct argument.
  • lcllistThe list of arrays produced by the function passed as the lmd argument.
  • ucllistThe list of arrays produced by the function passed as the umd argument.
  • barlabelsA list containing the unique elements of the variables on the right side of the formula (or the levels if they are factors), in the order in which they appear in the formula. These will be the default labels for the barNest function.
  • This function is similar to brkdn in the prettyR package, but is structured to be used with the barNest function. It produces a set of 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 mct, lmd and umd. If trueval is not NA, brkdnNest will calculate the proportion of trueval values in the response variable out of the total valid responses. Remember that lcllist and ucllist will be meaningless in this case.

The user should take care when specifying different summary functions. barNest expects a measure of central tendency as the first function and measures of dispersion as the second and third, if "error bars" are to be displayed. The user must also decide whether the "error bars" have any useful meaning.

See Also

by

Examples

Run this code
test.df<-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=test.df)

Run the code above in your browser using DataLab