Starting from:

$35

BSDA-Homework 6 Solved

1. Generalized linear model: Bioassay with Stan

Replicate the computations for the bioassay example of section 3.7 (BDA3) using Stan.

1.    Write down the model for the bioassay data in Stan syntax. For instructions in reporting your implementation, you can refer to parts 2 c) - g) in Assignment 5. More information on the bioassay data can be found in Section 3.7 of the course book. To get access to data, use the following code:

library(bsda) data("bioassay")

Use the Gaussian prior

                             ,              where µ        and                              .

Hint! You will need Stan functions multi_normal and binomial_logit for implementing the prior and observation model, respectively. In Stan code, it is easiest to declare a variable (say theta) which is a two-element vector so that the rst value denotes α and latter one β. This is because the multi_normal function that you need for implementing the prior requires a vector as an input.

2.    Use Rb for convergence analysis. You can either use Eq. (11.4) in BDA3 or the later version that can be found here. You should specify which Rb you used. In R the best choice is to use function Rhat from package rstan (see ?rstan::Rhat). To check Rb and other diagnostics, you can also call monitor(fit), where fit is the t object returned by Stan’s sampling function. Report the Rb values both for α and β and discuss the convergence of the chains. Brie y explain in your own words how to interpret the obtained Rb values.

3.    Plot the draws for α and β (scatter plot) and include this plot in your report. You can compare the results to Figure 3.3b in BDA3 to verify that your code gives sensible results. Notice though that the results in Figure 3.3b are generated from posterior with a uniform prior, so even when your algorithm works perfectly, the results will look slightly di erent (although fairly similar).

More products