Computes mean, sd and se for each sub-group (indicated by grp) of dv.

grpmean(x, dv, grp, weight.by = NULL, digits = 2, out = c("txt", "viewer",
  "browser"))

Arguments

x

A (grouped) data frame.

dv

Name of the dependent variable, for which the mean value, grouped by grp, is computed.

grp

Factor with the cross-classifying variable, where dv is grouped into the categories represented by grp. Numeric vectors are coerced to factors.

weight.by

Name of variable in x that indicated the vector of weights that will be applied to weight all observations. Default is NULL, so no weights are used.

digits

Numeric, amount of digits after decimal point when rounding estimates and values.

out

Character vector, indicating whether the results should be printed to console (out = "txt") or as HTML-table in the viewer-pane (out = "viewer") or browser (out = "browser"), of if the results should be plotted (out = "plot", only applies to certain functions). May be abbreviated.

Value

For non-grouped data frames, grpmean() returns a data frame with following columns: term, mean, N, std.dev, std.error and p.value. For grouped data frames, returns a list of such data frames.

Details

This function performs a One-Way-Anova with dv as dependent and grp as independent variable, by calling lm(count ~ as.factor(grp)). Then contrast is called to get p-values for each sub-group. P-values indicate whether each group-mean is significantly different from the total mean.

Examples

data(efc) grpmean(efc, c12hour, e42dep)
#> #> # Grouped Means for average number of hours of care per week by elder's dependency #> #> term mean N std.dev std.error p.value #> 1 independent 9.91 66 8.01 0.99 <0.001 #> 2 slightly dependent 17.54 225 17.74 1.18 <0.001 #> 3 moderately dependent 34.52 306 41.54 2.37 0.98 #> 4 severely dependent 75.90 304 61.72 3.54 <0.001 #> 5 Total 42.44 901 50.82 1.69 #> #> Anova: R2=0.245; adj.R2=0.242; F=96.908; p=0.000
data(iris) grpmean(iris, Sepal.Width, Species)
#> #> # Grouped Means for Sepal.Width by Species #> #> term mean N std.dev std.error p.value #> 1 setosa 3.43 50 0.38 0.05 <0.001 #> 2 versicolor 2.77 50 0.31 0.04 <0.001 #> 3 virginica 2.97 50 0.32 0.05 0.04 #> 4 Total 3.06 150 0.44 0.04 #> #> Anova: R2=0.401; adj.R2=0.393; F=49.160; p=0.000
# also works for grouped data frames library(dplyr) efc %>% group_by(c172code) %>% grpmean(c12hour, e42dep)
#> #> Grouped by: #> carer's level of education: low level of education #> #> # Grouped Means for average number of hours of care per week by elder's dependency #> #> term mean N std.dev std.error p.value #> 1 independent 16.33 12 10.74 3.10 0.02 #> 2 slightly dependent 15.38 42 9.55 1.47 <0.001 #> 3 moderately dependent 42.05 61 46.53 5.96 0.70 #> 4 severely dependent 85.52 65 56.42 7.00 <0.001 #> 5 Total 49.81 180 52.24 3.89 #> #> Anova: R2=0.307; adj.R2=0.295; F=25.955; p=0.000 #> #> #> Grouped by: #> carer's level of education: intermediate level of education #> #> # Grouped Means for average number of hours of care per week by elder's dependency #> #> term mean N std.dev std.error p.value #> 1 independent 7.96 45 3.91 0.58 <0.001 #> 2 slightly dependent 17.12 135 16.52 1.42 <0.001 #> 3 moderately dependent 33.55 163 41.05 3.22 0.75 #> 4 severely dependent 79.71 163 63.13 4.94 <0.001 #> 5 Total 41.76 506 51.42 2.29 #> #> Anova: R2=0.284; adj.R2=0.280; F=66.374; p=0.000 #> #> #> Grouped by: #> carer's level of education: high level of education #> #> # Grouped Means for average number of hours of care per week by elder's dependency #> #> term mean N std.dev std.error p.value #> 1 independent 15.20 5 18.43 8.24 0.36 #> 2 slightly dependent 18.08 39 12.98 2.08 0.15 #> 3 moderately dependent 28.42 62 35.64 4.53 0.67 #> 4 severely dependent 63.38 50 62.69 8.87 <0.001 #> 5 Total 36.62 156 46.38 3.71 #> #> Anova: R2=0.167; adj.R2=0.151; F=10.155; p=0.000 #> #>
# weighting efc$weight <- abs(rnorm(n = nrow(efc), mean = 1, sd = .5)) grpmean(efc, c12hour, e42dep, weight.by = weight)
#> #> # Grouped Means for average number of hours of care per week by elder's dependency #> #> term mean N std.dev std.error p.value #> 1 independent 9.58 66 8.01 0.99 <0.001 #> 2 slightly dependent 16.94 225 17.74 1.18 <0.001 #> 3 moderately dependent 35.20 306 41.54 2.37 0.62 #> 4 severely dependent 74.11 304 61.72 3.54 <0.001 #> 5 Total 41.87 901 50.82 1.69 #> #> Anova: R2=0.233; adj.R2=0.231; F=91.047; p=0.000