See Due date in Sakai
Please look at before class Tuesday in case there are questions or clarifications needed (or post on Piazza). Use LaTeX or write by hand (must be legible) and scan to submit via Sakai.
Exercise B.21 in Christensen
Let $X$ denote the $n$ by $p$ design matrix where $X^T 1 = 0$ and partition $X = [X_\gamma \, X_{1-\gamma}]$ where $X_\gamma$ denotes the design matrix under model $\gamma$ which includes the columns of $X$ where $\gamma_j = 1$ (and intercept) $X_{1-\gamma}$ are the columns of $X$ where $\gamma_j = 0.$ Similarly partition $\beta = (\beta_\gamma^T, \beta_{1-\gamma}^T)^T$ the vector of regression coefficients. Using Zellner’s $g$ prior for $$\beta \mid g, \sigma^2 \sim N(0, g \sigma^2 (X^TX)^{-1})$$ under the full model, show that the conditional distribution $\beta_\gamma \mid g, \sigma^2, \beta_{1 - \gamma} = 0$ and show that this is also a $g$ prior. Hint use Problem 1 above or consider partitioning the quadratic form into a marginal and conditional covariance.
Consider the model where $$Y \mid \beta_0, \beta_\gamma, \phi \sim N(1_n \beta_0 + X_{\gamma} \beta_\gamma, I/\phi)$$ We will go through the steps to derive the Bayes Factor under the $g$-prior. a. Start by writing $X_\gamma = P_1 X_\gamma + (I - P_1) X_{\gamma}$ and show that you can reparameterize the model so that the mean is $1\alpha + (I - P_1)X_\gamma \beta_\gamma$. What is $\alpha$ as a function of the other parameters? (If you wish relabel $(I - P_1)X_\gamma = X_\gamma^c$; the centered predictors.)
b. Using the g-prior $\beta_\gamma \mid g, \phi, \gamma \sim N(0, g (X_\gamma^T(I - P_1)X_\gamma)^{-1}/\phi)$ find the marginal distribution of $Y \mid \alpha, \phi$ by representing $Y$ as a linear combination of normals and express the covariance as a function of $P_{X_\gamma^c}$. For the energetic student, integrate by completing the square too.
c. Use the Binomial Inverse Theorem to find the inverse of $I + g P_{X_\gamma^c}$ (re-express in terms of $I$ and $P_{X_\gamma^c}$. For the energetic student without an internet connection, find the inverse using properties of projection matrices! (i.e. recall what the Spectral decomposition of a projection matrix must be)
d. Substituting the inverse into the (marginal) likelihood, integrate out $\alpha$ and then $\phi$ using the reference prior $p(\alpha,\phi) \propto1/\phi$ being sure to keep track of any constants that depend on $\gamma$ or the model size. Call the result the marginal likelihood of $\gamma$, $m(\gamma) \propto p(Y \mid M_\gamma)$.
e. Re-express the result as a function of $R^2_{\gamma} = Y^T P_{X_\gamma^c}Y/ Y^T(I - P_1)Y$ to verify the equation for the marginal likelihood in notes.
f. Show that the constant in the notes is the marginal likelihood under the null model where $\beta_\gamma = 0$.
g. Verify that the Bayes factor for comparing model $\gamma$ to the null model under the g-prior is then the ratio of the marginal likelihoods: $$BF[M_\gamma : M_0] = (1 + g)^{(n - p_\gamma - 1)/2} (1 + g(1 - R^2_{\gamma}))^{- \frac{n-1}{2}}$$
We will explore the data behind The Ultimate Halloween Candy Power Ranking. Download the Halloween Candy Dataset
and read into R
using the command read.csv
with the option header=T
.
The data includes attributes for each candy along with its ranking. For binary variables, 1 means yes, 0 means no. The data contains the following fields:
Header | Description |
---|---|
chocolate | Does it contain chocolate? |
fruity | Is it fruit flavored? |
caramel | Is there caramel in the candy? |
peanutalmondy | Does it contain peanuts, peanut butter or almonds? |
nougat | Does it contain nougat? |
crispedricewafer | Does it contain crisped rice, wafers, or a cookie component? |
hard | Is it a hard candy? |
bar | Is it a candy bar? |
pluribus | Is it one of many candies in a bag or box? |
sugarpercent | The percentile of sugar it falls under within the data set. |
pricepercent | The unit price percentile compared to the rest of the set. |
winpercent | The overall win percentage according to 269,000 matchups. |
Answer the following questions using R and Rmarkdown (or knitr). You should submit your Rmd file and pdf to Sakai.
a. Explore the association between winpercent
and the other other variables graphically and comment.
b. Fit the full model with all predictors and plot residuals versus fitted values. Comment on whether the model seems appropriate. Create confidence intervals for all of the coefficients and present in a table sorted by the estimates from high to low. (present as a nicely formated table - see kable
.
c. Using the step
function with AIC
which variables are in the final model?
d. Fit the model selected using AIC
and create confidence intervals for each of the coefficients formated as above. Do any of the intervals contain zero?
e. Using BMA to fit a model to explore which features predict winpercent
. According to your model which features are associated with high overall win percentage? What features are associated with low overall win percentage?
Which features do not seem to be important?
Provide a table of estimates and credible intervals (sorted as above) and comment on how they compare to the estimates under the best AIC model.
f. If you were to design a new candy to optimize the win percent, what features would it have? Create a prediction interval under BMA for your designer candy.
g. Summarize your modeling efforts in a couple of paragraphs suitable for readers of 538, providing interpretation of coefficients and how the they impact the winning percent. (see the 538 blog linked above)