11E1. If an event has probability 0.35, what are the log-odds of this event?
p <- 0.35
p/(1-p)
## [1] 0.5384615
11E2. If an event has log-odds 3.2, what is the probability of this event?
# 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?
# A unit increase in x results in a 1.7 increase in log-odds of the outcome.
11E4. Why do Poisson regressions sometimes require the use of an offset? Provide an example.
# Offset is needed when time is differnt for two events. For example, event A took one year to accumulate the same amount of cases event B one year does.
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?
# Because the data are organized in the way, the the aggregated model contains an extra factor in its log-probabilities.
11M2. If a coefficient in a Poisson regression has value 1.7, what does this imply about the change in the outcome?
# A log of unit increase in x results in a 1.7 increase in log of outcome.
11M3. Explain why the logit link is appropriate for a binomial generalized linear model.
# logt link is appropriate for a binomial generalized linear model because logit link maps a parameter that is defined as a probability mass and therefore lies between 0 and 1. This is very useful when working with binormial GLMs.
11M4. Explain why the log link is appropriate for a Poisson generalized linear model.
#Because the log link may contain the parameter when it is 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?
# Log link function maps a parameter that is defined over only positive real values onto a linear model. This works well with Poisson distribution, where the outcome are counts and always positive values.
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?
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?
#q2 <- map(alist(
# pulled_left ~ dbinom( 1 , p ) ,
# logit(p) <- a[actor] + (bp + bpC*condition)*prosoc_left ,
# a[actor] ~ dnorm(0,10),
# bp ~ dnorm(0,10),
# bpC ~ dnorm(0,10)
#) ,
#data=d)
#pairs(q2)
11M8. Revisit the data(Kline) islands example. This time drop Hawaii from the sample and refit the models. What changes do you observe?
data(Kline)
d <- Kline
d$P <- scale( log(d$population) )
d$contact_id <- ifelse( d$contact=="high" , 2 , 1 )
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.
data("chimpanzees")
d <- chimpanzees
m11.1 <- map(
alist(
pulled_left ~ dbinom(1, p),
logit(p) <- a ,
a ~ dnorm(0,10)
),
data=d )
## 10.4
m11.2 <- map(
alist(
pulled_left ~ dbinom(1, p) ,
logit(p) <- a + bp*prosoc_left ,
a ~ dnorm(0,10) ,
bp ~ dnorm(0,10)
),
data=d )
m11.3 <- map(
alist(
pulled_left ~ dbinom(1, p) ,
logit(p) <- a + (bp + bpC*condition)*prosoc_left ,
a ~ dnorm(0,10) ,
bp ~ dnorm(0,10) ,
bpC ~ dnorm(0,10)
), data=d )
m11.4 <- map(
alist(
pulled_left ~ dbinom(1, p),
logit(p) <- a[actor] + (bp + bpC*condition)*prosoc_left,
a[actor] ~ dnorm(0, 10),
bp ~ dnorm(0, 10),
bpC ~ dnorm(0, 10)
),
data = d)
# compare
compare(m11.1,m11.2,m11.3,m11.4)
## WAIC SE dWAIC dSE pWAIC weight
## m11.4 546.0075 18.777357 0.0000 NA 13.8774589 1.000000e+00
## m11.2 680.2984 9.329050 134.2910 18.19650 1.9010536 6.903797e-30
## m11.3 682.0549 9.342492 136.0474 18.13662 2.8564347 2.868651e-30
## m11.1 687.9270 7.173665 141.9195 19.00479 0.9931616 1.522550e-31