0
$\begingroup$

I am trying to get better at statistical analysis by following the tidy tuesday screen cast by David Robinson and I had a question on this particular dataset he was analyzing. Essentially, he was trying to understand if there is a statistical trend in probability of award success over time. So, in the screenshot shared WI has a negative trend ( as in % of awards that it won decreases over the year) and he is trying to fit a logistic regression model to see if this trend is significant. enter image description here

The code he uses is essentially this

by_year_state %>% 
filter(state == "WI") %>% 
glm(cbind(n, year_total - n) ~ year., data = ., family = "binomial") %>% 
summary()

by_year_state dataframe is attached belowenter image description here I am quite a newbie at stats and was wondering if anyone can explain what the glm function with cbind is essentially trying to do? Or if anyone can point me to some resources to understand this better would be great. I have seen glm being used to predict stuff, but I am seeing this kind of approach for the first time

$\endgroup$

1 Answer 1

0
$\begingroup$

glm fits what is known as a Generalized Linear Model. Logistic regression happens to part of this class of models.

Let's break down the model call

glm(cbind(n, year_total - n) ~ year., data = ., family = "binomial")
  • glm is the function which fits logistic regression
  • cbind(n, year_total-n) creates the outcome for the model. n is the number of successes (so named in the data) for a given year and year_total-n is the number of failures) for a given year
  • ~ is read as "explained by". The left hand side of the ~ is explained by the right hand side.
  • year is what is doing the explaining. So we're looking at n/(year_total) over year.
  • data=. specifies where the data comes from. Since david is using the pipe %>%, using a dot . is a way to tell the function you're piping into to use the data being piped at the indicated place.
  • family=binomial tells glm to fit logsitic regression.
$\endgroup$
2
  • $\begingroup$ Thank you so much for the explanation. So if we do glm ( n/year_total ~ year, family = "binomial") would it give me the same result as glm(cbind(n, year_total - n) ~ year., data = ., family = "binomial")? I tried to do this but my estimates were different and hence the confusion $\endgroup$
    – sneha
    Feb 11 at 2:28
  • $\begingroup$ @sneha No, it would NOT give you the same output. If you have counts of successful trials, you're best to do cbind as shown here $\endgroup$ Feb 11 at 4:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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