Learn R Programming

rcompanion (version 2.4.30)

groupwisePercentile: Groupwise percentiles and confidence intervals

Description

Calculates percentiles and confidence intervals for groups.

Usage

groupwisePercentile(
  formula = NULL,
  data = NULL,
  var = NULL,
  group = NULL,
  conf = 0.95,
  tau = 0.5,
  type = 7,
  R = 5000,
  boot = FALSE,
  basic = FALSE,
  normal = FALSE,
  percentile = FALSE,
  bca = TRUE,
  digits = 3,
  ...
)

Value

A data frame of requested statistics by group

Arguments

formula

A formula indicating the measurement variable and the grouping variables. e.g. y ~ x1 + x2.

data

The data frame to use.

var

If no formula is given, the measurement variable to use. The name is in double quotes.

group

The grouping variable to use. The name is in double quotes. Multiple names are listed as a vector. (See example.)

conf

The confidence interval to use.

tau

The percentile to use, expressed as a quantile, e.g. 0.5 for median, 0.25 for 25th percentile.

type

The type value passed to the quantile function.

R

The number of bootstrap replicates to use for bootstrapped statistics.

boot

If TRUE, includes the mean of the bootstrapped percentile. This can be used as an estimate of the percentile for the group.

basic

If TRUE, includes the basic confidence intervals for the group means by bootstrap. See boot.ci.

normal

If TRUE, includes the normal confidence intervals for the group means by bootstrap. See boot.ci.

percentile

If TRUE, includes the percentile confidence intervals for the group means by bootstrap. See boot.ci.

bca

If TRUE, includes the BCa confidence intervals for the group means by bootstrap. See boot.ci.

digits

The number of significant figures to use in output.

...

Other arguments passed to the boot function.

Author

Salvatore Mangiafico, mangiafico@njaes.rutgers.edu

Details

The input should include either formula and data; or data, var, and group. (See examples).

With some options, the function may not handle missing values well. This seems to happen particularly with bca = TRUE.

References

http://rcompanion.org/handbook/F_15.html

See Also

groupwiseMean, groupwiseHuber, groupwiseGeometric, groupwiseMedian

Examples

Run this code
### Example with formula notation
data(Catbus)
groupwisePercentile(Steps ~ Teacher + Gender,
                    data        = Catbus,
                    tau         = 0.25,
                    bca         = FALSE,
                    percentile  = TRUE,
                    R           = 1000)
                
### Example with variable notation
data(Catbus)
groupwisePercentile(data         = Catbus,
                    var         = "Steps",
                    group       = c("Teacher", "Gender"),
                    tau         = 0.25,
                    bca         = FALSE,
                    percentile  = TRUE,
                    R           = 1000)
                      

Run the code above in your browser using DataLab