Learn R Programming

glmmBUGS (version 1.0)

binToBinom: Convert Bernoulli observations to Binomial

Description

Combines multiple Bernoulli observations with the same covariates into one Binomial response

Usage

binToBinom(obs, covariates)

Arguments

obs
logical vector of observations
covariates
Data frame or matrix of covariates

Value

  • A data frame with one row for each unique value for the covariates, including the covariates and the following additional columns:
  • yNumber of positive observations for the corresponding covariate values
  • NTotal number of observations for these covariates

Examples

Run this code
thedata = data.frame(sex = rep(c("m", "f"), 10), age=rep(c(20,30), c(10, 10)))
  y = rbinom(dim(thedata)[1], 1, 0.5)
  bindata = binToBinom(y, thedata)
  bindata$zeros = bindata$N - bindata$y
  glm(as.matrix(bindata[,c("y", "zeros")]) ~ sex, data=bindata, family=binomial)

Run the code above in your browser using DataLab