Question: Q4: This problem will make use of the cabbages data set from the MASS library. This contains data from a cabbage field trial. We will

Q4: This problem will make use of the cabbages data set from the MASS library. This contains data from a cabbage field trial. We will be interested in HeadWt (weight of the cabbage head, presumably in kg) and VitC asorbi acid content, in undefined units. (a) We are interested in the simple linear regression model where Ei ~ N(0, ?), Y = VitC and Xi = log(HeadWt), Plot Y against X. Using the function ln(), calculate the least squares estimates of ,1, and superimpose the estimated regression line on your plot. Is a linear relationship between X and Y plausible? (b) We will construct a Bayesian model for the inference of (A,A). The marginal prior densities will be 81 N(0,2), and under the prior assumption, 30 and 1 are independent. The conditional densities of Y; given (, ) are Yi ~ N(30 + 1x,e). Given (A, A) the response Y; can be assumed to be independent. Let 0(z;, 2) denote the density function for a N(, *) distribution. The joint posterior density of ( ,A) will therefore be proportional to where (%) = (Bu;ly, 8) and (A) simulate a sample from (A},1%, = (81,0, 1). ,Yo). Implement the following features. Create a Hastings-Metropolis algorithm to (i) Estimate fly using the sample mean of the responses Yi, and estimate using the MSE from the regression model in Part (a) (using data to estimate parameters in a Bayesian model can be referred to as the empirical Bayesian method). (ii) Use as a proposal rule something like beta, new = beta. old + runif(2,-1,1). This means the resulting state space is not discrete, but the algorithm will work in much the same way. Under this proposal rule we can take 1 QQy) when calculating the acceptance probability. (iii) Allow N 100,000 transitions. Capture in a single object all sampled values of (Bo. B1) (iv) Run the algorithm twice, first setting prior variance -2 ior-100, then 2rio-1000. A parameter defining a prior density is referred to as a hyperparameter. Sometimes, this is used to represent prior information (for example in this model). Otherwise, the hyperparameters are often set so as to make the prior density uniform, close to uniform, or otherwise highly variable, to reflect uncertainty regarding the parameter . This is known as a (v) When constructing an MCMC algorithm, rather than calculate a ratio of densities, it is better to calculate a difference in log-densities, and then calculate the exponential function of the difference, that is, e. This can be done using the log = TRUE option of the dnorm() function. This option is generally available for density functions in R. (c) Construct separate histograms for ) and 1 for each hyperparameter choice 2rir = 100, 1000. Also, superim pose on each histogram the least squares estimate of A, fron Part (a), as well as the confidence interval bounds teritSE the abline() function can be used). In general, is the Bayesian inference for and A consistent with the confidence intervals? (d) When a prior is intended to be diffuse, the usual practice is to investigate the sensitivity of the posterior density to the choice of prior. Ideally, in this case, the posterior density does not depend significantly on the prior. The simplest way to do this is to use a range of priors, then compare the resulting posterior densities. With this in mind, does the posterior density appear to be sensitive to the choice of 2nor? Q4: This problem will make use of the cabbages data set from the MASS library. This contains data from a cabbage field trial. We will be interested in HeadWt (weight of the cabbage head, presumably in kg) and VitC asorbi acid content, in undefined units. (a) We are interested in the simple linear regression model where Ei ~ N(0, ?), Y = VitC and Xi = log(HeadWt), Plot Y against X. Using the function ln(), calculate the least squares estimates of ,1, and superimpose the estimated regression line on your plot. Is a linear relationship between X and Y plausible? (b) We will construct a Bayesian model for the inference of (A,A). The marginal prior densities will be 81 N(0,2), and under the prior assumption, 30 and 1 are independent. The conditional densities of Y; given (, ) are Yi ~ N(30 + 1x,e). Given (A, A) the response Y; can be assumed to be independent. Let 0(z;, 2) denote the density function for a N(, *) distribution. The joint posterior density of ( ,A) will therefore be proportional to where (%) = (Bu;ly, 8) and (A) simulate a sample from (A},1%, = (81,0, 1). ,Yo). Implement the following features. Create a Hastings-Metropolis algorithm to (i) Estimate fly using the sample mean of the responses Yi, and estimate using the MSE from the regression model in Part (a) (using data to estimate parameters in a Bayesian model can be referred to as the empirical Bayesian method). (ii) Use as a proposal rule something like beta, new = beta. old + runif(2,-1,1). This means the resulting state space is not discrete, but the algorithm will work in much the same way. Under this proposal rule we can take 1 QQy) when calculating the acceptance probability. (iii) Allow N 100,000 transitions. Capture in a single object all sampled values of (Bo. B1) (iv) Run the algorithm twice, first setting prior variance -2 ior-100, then 2rio-1000. A parameter defining a prior density is referred to as a hyperparameter. Sometimes, this is used to represent prior information (for example in this model). Otherwise, the hyperparameters are often set so as to make the prior density uniform, close to uniform, or otherwise highly variable, to reflect uncertainty regarding the parameter . This is known as a (v) When constructing an MCMC algorithm, rather than calculate a ratio of densities, it is better to calculate a difference in log-densities, and then calculate the exponential function of the difference, that is, e. This can be done using the log = TRUE option of the dnorm() function. This option is generally available for density functions in R. (c) Construct separate histograms for ) and 1 for each hyperparameter choice 2rir = 100, 1000. Also, superim pose on each histogram the least squares estimate of A, fron Part (a), as well as the confidence interval bounds teritSE the abline() function can be used). In general, is the Bayesian inference for and A consistent with the confidence intervals? (d) When a prior is intended to be diffuse, the usual practice is to investigate the sensitivity of the posterior density to the choice of prior. Ideally, in this case, the posterior density does not depend significantly on the prior. The simplest way to do this is to use a range of priors, then compare the resulting posterior densities. With this in mind, does the posterior density appear to be sensitive to the choice of 2nor
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
