Solved – categorical predictors in a GLM

logisticrregressionself-study

I need some help answering a homework question,

Question

I have entered the data into R using assignments

data <- data.frame(category=c(1:8),
                   obese =c(597,380,665,524,1014,365,942,552),
                   number = c(2346,1659,2576,1732,1499,639,1491,769), 
                   male=c(1,0,1,0,1,0,1,0),
                   white =c(1,1,0,0,1,1,0,0),
                   younger =c(1,1,1,1,0,0,0,0))

I then used

output = glm(obese ~ male + white + younger, family = binomial)

to model the data. But this doesn't seem to be working. I've not really used much R before for GLMs or logistic regression and I don't understand how to get GLM from categorial, binary predictor variables.
If someone could explain the theory behind because searching online I have only found answers where the response variable is binary and this seems straight forward.

Best Answer

Your data already seems to be summarized: in the 1st category (younger white males), 597 out of 2346 subjects are obese. At least, that's my understanding - it's always good to really understand the data you are modeling.

If my interpretation is right, then an easy way to do this seems to be to turn your first row into 597 rows with obese=1 and 2346-597 rows with obese=0, then your GLM should work fine.