0
$\begingroup$

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.

$\endgroup$
1
$\begingroup$

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.

| cite | improve this answer | |
$\endgroup$
1
$\begingroup$

Your GLM statement will only work if the data are lined up one line per case. In your homework, the cases are aggregated, so the R code needs to be changed somewhat:

nonObese <- number - obese
glm(cbind(obese, nonObese)) ~ male + white + younger, family = binomial)

See here for a more in-depth tutorial.

| cite | improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.