binToBinom {glmmBUGS}R Documentation

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:

y Number of positive observations for the corresponding covariate values
N Total number of observations for these covariates

Author(s)

Patrick Brown

Examples

  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)

[Package glmmBUGS version 1.5 Index]