Skip to contents

Calculates geometric means and confidence intervals for groups.

Usage

groupwiseGeometric(
  formula = NULL,
  data = NULL,
  var = NULL,
  group = NULL,
  conf = 0.95,
  na.rm = TRUE,
  digits = 3,
  ...
)

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

conf

The confidence interval to use.

na.rm

If TRUE, removes NA values in the measurement variable.

digits

The number of significant figures to use in output.

...

Other arguments. Not currently used.

Value

A data frame of geometric means, standard deviations, standard errors, and confidence intervals.

Details

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

The function computes means, standard deviations, standard errors, and confidence intervals on log-transformed values. Confidence intervals are calculated in the traditional manner with the t-distribution on the transformed values, and then back-transforms the confidence interval limits. These statistics assume that the data are log-normally distributed. For data not meeting this assumption, medians and confidence intervals by bootstrap may be more appropriate.

Note

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.

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.

Author

Salvatore Mangiafico, mangiafico@njaes.rutgers.edu

Examples

### Example with formula notation 
data(Catbus)
groupwiseGeometric(Steps ~ Gender + Teacher,
                   data   = Catbus)
#>   Gender Teacher n Geo.mean sd.lower sd.upper se.lower se.upper ci.lower
#> 1 female  Catbus 6     7890     6590     9460     7330     8500     6530
#> 2 female Satsuki 4     8490     7930     9080     8200     8780     7620
#> 3 female  Totoro 5     8090     6680     9790     7420     8810     6380
#> 4   male  Catbus 4     6850     5380     8720     6070     7730     4670
#> 5   male Satsuki 3     6950     6020     8030     6400     7550     4860
#> 6   male  Totoro 4     6960     6190     7830     6570     7390     5780
#>   ci.upper
#> 1     9540
#> 2     9450
#> 3    10200
#> 4    10100
#> 5     9940
#> 6     8400

### Example with variable notation                                              
data(Catbus)
groupwiseGeometric(data   = Catbus,
                   var    = "Steps",
                   group  = c("Gender", "Teacher"))
#>   Gender Teacher n Geo.mean sd.lower sd.upper se.lower se.upper ci.lower
#> 1 female  Catbus 6     7890     6590     9460     7330     8500     6530
#> 2 female Satsuki 4     8490     7930     9080     8200     8780     7620
#> 3 female  Totoro 5     8090     6680     9790     7420     8810     6380
#> 4   male  Catbus 4     6850     5380     8720     6070     7730     4670
#> 5   male Satsuki 3     6950     6020     8030     6400     7550     4860
#> 6   male  Totoro 4     6960     6190     7830     6570     7390     5780
#>   ci.upper
#> 1     9540
#> 2     9450
#> 3    10200
#> 4    10100
#> 5     9940
#> 6     8400