binToBinom {glmmBUGS} | R Documentation |
Combines multiple Bernoulli observations with the same covariates into one Binomial response
binToBinom(obs, covariates)
obs |
logical vector of observations |
covariates |
Data frame or matrix of covariates |
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 |
Patrick Brown
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)