\[%% % Add your macros here; they'll be included in pdf and html output. %% \newcommand{\R}{\mathbb{R}} % reals \newcommand{\E}{\mathbb{E}} % expectation \renewcommand{\P}{\mathbb{P}} % probability \DeclareMathOperator{\logit}{logit} \DeclareMathOperator{\logistic}{logistic} \DeclareMathOperator{\sd}{sd} \DeclareMathOperator{\var}{var} \DeclareMathOperator{\cov}{cov} \DeclareMathOperator{\Normal}{Normal} \DeclareMathOperator{\Poisson}{Poisson} \DeclareMathOperator{\Beta}{Beta} \DeclareMathOperator{\Binom}{Binomial} \DeclareMathOperator{\Gam}{Gamma} \DeclareMathOperator{\Exp}{Exponential} \DeclareMathOperator{\Cauchy}{Cauchy} \DeclareMathOperator{\Unif}{Unif} \DeclareMathOperator{\Dirichlet}{Dirichlet} \DeclareMathOperator{\Wishart}{Wishart} \newcommand{\given}{\;\vert\;} \]
Assignment: You should use R for your work, and submit your work as both a final .Rmd file and rendered pdf or html files.
Due: Submit your work via Canvas by the end of the day (midnight) on Thursday, January 24. You can work with other members of class, but I expect each of you to construct and run all of the scripts yourself.
Here is a dataset (resistance.tsv
), of the structure described in last week’s homework.
Extend the model you fit last week to include a shape parameter \[\begin{aligned}
R_i &\sim \text{Gamma}(\text{rate}=k/\mu_i, \text{shape}=k) \\
\mu_i &= b_0 + b_T T_i + b_D D_i .
\end{aligned}\] (Since the Exponential distribution is the same as the Gamma with shape=1, this is a more general model.) (If you are suspicious of your implementation, you can use this Stan block: (exponential_regression.stan
).)
Fit the model to the data.
Include a quadratic term: \[\begin{aligned} R_i &\sim \text{Gamma}(\text{rate}=k/\mu_i, \text{shape}=k) \\ \mu_i &= b_0 + b_T T_i + b_D D_i + b_{DD} D_i^2. \end{aligned}\] and fit the model.
Compare the two models using some kind of model comparison (crossvalidation or posterior predictive simulation).