Chapter 11 - God Spiked the Integers

This chapter described some of the most common generalized linear models, those used to model counts. It is important to never convert counts to proportions before analysis, because doing so destroys information about sample size. A fundamental difficulty with these models is that parameters are on a different scale, typically log-odds (for binomial) or log-rate (for Poisson), than the outcome variable they describe. Therefore computing implied predictions is even more important than before.

Place each answer inside the code chunk (grey box). The code chunks should contain a text response or a code that completes/answers the question or activity requested. Problems are labeled Easy (E), Medium (M), and Hard(H).

Finally, upon completion, name your final output .html file as: YourName_ANLY505-Year-Semester.html and publish the assignment to your R Pubs account and submit the link to Canvas. Each question is worth 5 points.

Questions

11E1. If an event has probability 0.35, what are the log-odds of this event?

log( 0.35 / (1 - 0.35))
## [1] -0.6190392

11E2. If an event has log-odds 3.2, what is the probability of this event?

1 / (1 + exp(-3.2))
## [1] 0.9608343

11E3. Suppose that a coefficient in a logistic regression has value 1.7. What does this imply about the proportional change in odds of the outcome?

exp(1.7)
## [1] 5.473947
#The odds would increase by 447%

11E4. Why do Poisson regressions sometimes require the use of an offset? Provide an example.

#Poisson Regression assumes that the rate of an event is constant and an offset is needed to account for the different times of an event. For example, in one city, they might collect garbage every week while another city collects garbage every two weeks. 

11M1. As explained in the chapter, binomial data can be organized in aggregated and disaggregated forms, without any impact on inference. But the likelihood of the data does change when the data are converted between the two formats. Can you explain why?

#The data change when it gets converted between the two format because the aggregated form involves a extra log-odd factor

11M2. If a coefficient in a Poisson regression has value 1.7, what does this imply about the change in the outcome?

#It means that there are 5.5 times more events happening in the same time interval

11M3. Explain why the logit link is appropriate for a binomial generalized linear model.

#The binominal generalized linear model has probability as its main parameter and the logit link maps a probability onto the real line.

11M4. Explain why the log link is appropriate for a Poisson generalized linear model.

#The Poisson linear model has the rate which gives the number of events per time interval and has to be positive. 

11M5. What would it imply to use a logit link for the mean of a Poisson generalized linear model? Can you think of a real research problem for which this would make sense?

#Using a logit link implies that it is between 0 to 1 so on average there are less than one event in that interval. This would make sense for the garbage truck scenario within a short time period as the chances of the event happening is low.

11M6. State the constraints for which the binomial and Poisson distributions have maximum entropy.Are the constraints different at all for binomial and Poisson? Why or why not?

#They have maximum entropy when each trial results in one of the two events and the expected value is constant. 

11M7. Use quap to construct a quadratic approximate posterior distribution for the chimpanzee model that includes a unique intercept for each actor, m11.4 (page 330). Compare the quadratic approximation to the posterior distribution produced instead from MCMC. Can you explain both the differences and the similarities between the approximate and the MCMC distributions? Relax the prior on the actor intercepts to Normal(0,10). Re-estimate the posterior using both ulam and quap. Do the differences increase or decrease? Why?

11M8. Revisit the data(Kline) islands example. This time drop Hawaii from the sample and refit the models. What changes do you observe?

11H1. Use WAIC or PSIS to compare the chimpanzee model that includes a unique intercept for each actor, m11.4 (page 330), to the simpler models fit in the same section. Interpret the results.