Skip to contents

Calculates Huber M-estimator and confidence intervals for groups.

Usage

groupwiseHuber(
  formula = NULL,
  data = NULL,
  var = NULL,
  group = NULL,
  conf.level = 0.95,
  ci.type = "wald",
  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.level

The confidence interval to use.

ci.type

The type of confidence interval to use. Can be "wald" or "boot". See HuberM for details.

digits

The number of significant figures to use in output.

...

Other arguments passed to the HuberM function.

Value

A data frame of requested statistics by group.

Details

A wrapper for the DescTools::HuberM function to allow easy output for multiple groups.

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.

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.

It is recommended to remove NA values before using this function. At the time of writing, NA values will cause the function to fail if confidence intervals are requested.

At the time of writing, the ci.type="boot" option produces NA results. This is a result from the DescTools::HuberM function.

Author

Salvatore Mangiafico, mangiafico@njaes.rutgers.edu

Examples

### Example with formula notation
data(Catbus)
groupwiseHuber(Steps ~ Teacher + Gender,
               data      = Catbus,
               ci.type   = "wald")
#>   Teacher Gender n M.Huber lower.ci upper.ci
#> 1  Catbus female 6    8000     5970    10000
#> 2  Catbus   male 4    7000     2510    11500
#> 3 Satsuki female 4    8500     7700     9300
#> 4 Satsuki   male 3    7000     4970     9030
#> 5  Totoro female 5    8250     6320    10200
#> 6  Totoro   male 4    7000     4760     9240
               
### Example with variable notation
data(Catbus)
groupwiseHuber(data      = Catbus,
               var       = "Steps",
               group     = c("Teacher", "Gender"),
               ci.type   = "wald")
#>   Teacher Gender n M.Huber lower.ci upper.ci
#> 1  Catbus female 6    8000     5970    10000
#> 2  Catbus   male 4    7000     2510    11500
#> 3 Satsuki female 4    8500     7700     9300
#> 4 Satsuki   male 3    7000     4970     9030
#> 5  Totoro female 5    8250     6320    10200
#> 6  Totoro   male 4    7000     4760     9240

### Example with NA value and without confidence intervals
data(Catbus)
Catbus1 = Catbus
Catbus1[1, 'Steps'] = NA
groupwiseHuber(Steps ~ Teacher + Gender,
               data      = Catbus1,
               conf.level   = NA)
#>   Teacher Gender n M.Huber
#> 1  Catbus female 6      NA
#> 2  Catbus   male 4    7000
#> 3 Satsuki female 4    8500
#> 4 Satsuki   male 3    7000
#> 5  Totoro female 5    8250
#> 6  Totoro   male 4    7000