Learn R Programming

rcompanion (version 2.4.30)

groupwiseMean: Groupwise means and confidence intervals

Description

Calculates means and confidence intervals for groups.

Usage

groupwiseMean(
  formula = NULL,
  data = NULL,
  var = NULL,
  group = NULL,
  trim = 0,
  na.rm = FALSE,
  conf = 0.95,
  R = 5000,
  boot = FALSE,
  traditional = TRUE,
  normal = FALSE,
  basic = FALSE,
  percentile = FALSE,
  bca = FALSE,
  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

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.)

trim

The proportion of observations trimmed from each end of the values before the mean is calculated. (As in mean())

na.rm

If TRUE, NA values are removed during calculations. (As in mean())

conf

The confidence interval to use.

R

The number of bootstrap replicates to use for bootstrapped statistics.

boot

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

traditional

If TRUE, includes the traditional confidence intervals for the group means, using the t-distribution. If trim is not 0, the traditional confidence interval will produce NA. Likewise, if there are NA values that are not removed, the traditional confidence interval will produce NA.

normal

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

basic

If TRUE, includes the basic 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).

Results for ungrouped (one-sample) data can be obtained by either setting the right side of the formula to 1, e.g. y ~ 1, or by setting group=NULL when using var.

References

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

See Also

groupwiseMedian, groupwiseHuber, groupwiseGeometric

Examples

Run this code
### Example with formula notation
data(Catbus)
groupwiseMean(Steps ~ Teacher + Gender,
              data        = Catbus,
              traditional = FALSE,
              percentile  = TRUE)

### Example with variable notation
data(Catbus)
groupwiseMean(data        = Catbus,
              var         = "Steps",
              group       = c("Teacher", "Gender"),
              traditional = FALSE,
              percentile  = TRUE)
                                     

Run the code above in your browser using DataLab