groupwiseMean.RdCalculates means and confidence intervals for groups.
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,
...
)A formula indicating the measurement variable and the grouping variables. e.g. y ~ x1 + x2.
The data frame to use.
The measurement variable to use. The name is in double quotes.
The grouping variable to use. The name is in double quotes. Multiple names are listed as a vector. (See example.)
The proportion of observations trimmed from each end of the
values before the mean is calculated. (As in mean())
If TRUE, NA values are removed during
calculations. (As in mean())
The confidence interval to use.
The number of bootstrap replicates to use for bootstrapped statistics.
If TRUE, includes the mean of the bootstrapped means.
This can be used as an estimate of the mean for
the group.
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.
If TRUE, includes the normal confidence
intervals for the group means by bootstrap.
See boot.ci.
If TRUE, includes the basic confidence
intervals for the group means by bootstrap.
See boot.ci.
If TRUE, includes the percentile confidence
intervals for the group means by bootstrap.
See boot.ci.
If TRUE, includes the BCa confidence
intervals for the group means by bootstrap.
See boot.ci.
The number of significant figures to use in output.
Other arguments passed to the boot function.
A data frame of requested statistics by group.
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.
The parsing of the formula is simplistic. The first variable on the left side is used as the measurement variable. The variables on the right side are used for the grouping variables.
In general, it is advisable to handle NA values before
using this function.
With some options, the function may not handle missing values well,
or in the manner desired by the user.
In particular, if bca=TRUE and there are NA values,
the function may fail.
For a traditional method to calculate confidence intervals on trimmed means, see Rand Wilcox, Introduction to Robust Estimation and Hypothesis Testing.
### Example with formula notation
data(Catbus)
groupwiseMean(Steps ~ Teacher + Gender,
data = Catbus,
traditional = FALSE,
percentile = TRUE)
#> Teacher Gender n Mean Conf.level Percentile.lower Percentile.upper
#> 1 Catbus female 6 8000 0.95 7000 9000
#> 2 Catbus male 4 7000 0.95 5500 8500
#> 3 Satsuki female 4 8500 0.95 8000 9000
#> 4 Satsuki male 3 7000 0.95 6000 8000
#> 5 Totoro female 5 8200 0.95 7000 9400
#> 6 Totoro male 4 7000 0.95 6250 7750
### Example with variable notation
data(Catbus)
groupwiseMean(data = Catbus,
var = "Steps",
group = c("Teacher", "Gender"),
traditional = FALSE,
percentile = TRUE)
#> Teacher Gender n Mean Conf.level Percentile.lower Percentile.upper
#> 1 Catbus female 6 8000 0.95 7000 9000
#> 2 Catbus male 4 7000 0.95 5500 8500
#> 3 Satsuki female 4 8500 0.95 8000 9000
#> 4 Satsuki male 3 7000 0.95 6000 8000
#> 5 Totoro female 5 8200 0.95 7000 9400
#> 6 Totoro male 4 7000 0.95 6250 7750