agg_binomial function

Aggregate Binomial Data

Aggregate Binomial Data

A simple function for aggregating binomial data, from a form where y contains only 0 and 1

and X could contain duplicated rows, into a format where y is the matrix of counted successes and failures and X does not contain duplicates. If X contains factor variables, the model matrix corresponding to X

will be returned.

agg_binomial(formula, data, as_list = TRUE)

Arguments

  • formula: a formula object defining the aggregation.
  • data: a data.frame to be aggregated.
  • as_list: a logical giving if the return value should be a list. If FALSE the return value is a data.frame.

Returns

A list (or data.frame) containing aggregated binomial data with counted successes and failures.

Examples

set.seed(12345) data <- data.frame(y = rbinom(50, 1, 0.7), a = factor(sample(c(1, 2), 50, TRUE)), b = factor(sample(c(1, 2, 3), 50, TRUE))) agg_binomial(y ~ ., data)
  • Maintainer: Benjamin Schwendinger
  • License: GPL-3
  • Last published: 2024-12-20

Useful links