# GLMEM vs LM on proportions within random effects

I'm doing a project involving outcomes measured for people clustered within departments. The departments had previously been randomized to a treatment or control condition.

One of the main outcomes is the proportion of women within each department (technically the proportion of new hires that are women). So, I'm interested in the relative proportion of women in treatment and control departments.

My initial impression as to how to analyze these data was to simply calculate the proportion of women within each department, then fit a plain old linear model with condition as a predictor variable. However, on further thought it seems like this might be an appropriate situation in which to use a GLMEM (Generalized Linear Mixed Effects Model) in which condition predicts gender, with random intercepts for department.

What are the implications of fitting a linear model on proportions calculated within departments vs fitting a full GLMEM?

Here is some very simple R code showing these two approaches:

set.seed(1343)

d <- data.frame(id = 1:2000, dept_id = rep(1:100, 20))
d$condition <- ifelse(d$dept_id %in% 1:50, "control", "experimental")
d\$gender <- sample(rep(c(1, 0), 1000))

mod1 <- glmer(gender ~ condition + (1|dept_id), family = binomial, data = d)
summary(mod1)

dept_stats <- ddply(d, "dept_id", summarize,
condition = unique(condition),
prop_m = sum(gender == 1)/length(gender))

mod2 <- lm(prop_m ~ condition, data = dept_stats)
summary(mod2)


1. A linear model should be less powerful, since you are throwing data away (e.g., 4 values 0, 1, 0, 1 becomes one value: .5).
• (2) refers to the fact that the LM would need to include a predictor called, for example, num_hires and not to the fact that weighting by number of hires is necessary in the GLMEM, correct? – Patrick S. Forscher Nov 23 '15 at 19:50
• I would not use num_hires as a covariate. I would weight your observations with num_hires (or at least, I would do that if I were going to use lm for some strange reason). Also, I don't mean that the y-hats in your dataset will be outside the acceptable range, but that it is possible for them to be b/c the model is incorrect. You have a binary treatment indicator--that provides some protection against seeing this in your dataset, but if you had continuous variables (or a continuous covariate) you could have predicted values outside the bounds. – gung - Reinstate Monica Nov 23 '15 at 20:00
• I see. Assuming that I use glmer instead of lm, is it true that it is unnecessary to use the weights argument in glmer to weight by num_hires? – Patrick S. Forscher Nov 23 '15 at 20:04
• If you enter a vector of 1's & 0's (each hire is male or female), or if you enter a matrix cbind(num_males, num_females) for each department, as your LHS, you do not need to use the weights argument. (I'd have to check the documentation, but it may not work the same as weights in lm--at least it doesn't in glm.) – gung - Reinstate Monica Nov 23 '15 at 20:10