Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

INTRODUCTION TO BAYESIAN DATA ANALYSIS (STAT3016/4116/7016)

SEMESTER 2 2022

ASSIGNMENT

Problem 1 [20 marks]

The most recent statistics from Fundsquire show that 60 percent of Australian start-up businesses fail within their rst three years 1.  Suppose survival data is collected from a random sample of 50 start-ups that started since 01 January 2015 and the operational status of each company is recorded as at 30 June 2022. The data le "StartUp .csv"  contains two variables

● Status  (X)  - where Xi  = 1 if company i is still operational as at 30 June 2022, and Xi  = 0 if company i is no longer operational as at 30 June 2022.

● Time  (Y)  - the time (in years) to complete shutdown of the company if Xi  = 0, or the censoring time (ci) if Xi = 1.

Let Zi  denote the true lifetime of company i. Assume Zi  follows an Exponential distribution. The model is

Yi = -ci(Z)i

if Xi = 0

if Xi = 1 (that is Zi  > ci)

(1)

Z1 , ..., Znlθ  Exp(θ)

So Yi  is the observed survival or censoring time and Zi  is the true (but not always directly observed) survival time.   If the start-up fails before the study end date, then  Yi   =  Zi .   If the start-up is still operational at the study end date, then all we know is that Zi  > ci, and the observed life time is equal to the censoring time ci . The parameter θ is the rate parameter for the start-up true survival time. In this problem, the rate parameter θ and some of the true survival times Z = (Z1 , ..., Zn) are unknowns.  Our goal is to estimate the posterior density p(θlx, y) (where y = (y1 , ..., yn), x = (x1 , ..., xn))

(a)  [3 marks] Derive Jeffrey’s prior for θ for the Exponential sampling model Z1 , ..., Znlθ  Exp(θ). Is Jeffrey’s prior a proper prior for this model?

(b)  [2 marks] Assuming the prior you obtained in part (a), derive the full conditional posterior distribution p(θlz, x, y).

(c)  [3 marks] Derive the full conditional posterior distribution p(Zilθ, zi , x, y).

(d)  [4 marks] Implement a Gibbs sampling scheme that approximates the joint posterior distribution of θ and Z given y and x using the conditional distributions you derived in parts (b) and (c). Insert your computer code here.

(e)  [3 marks] Provide autocorrelation and traceplots for  θ  and a selection of the  Zi’s belonging to censored units. Comment on these plots. Also report the effective sample sizes.

(f)  [2 marks] Provide a 95% posterior interval estimate for θ . What is the expected survival time of a recent start-up in Australia given the data?

(g)  [3 marks] Is the Exponential distribution a valid sampling distribution assumption for this data? Run some checks to support your answer. Suggest how the model assumptions could be modified if your checks are not satisfied.

Problem 2 [20 marks]

An outlier is an observation that lies outside the overall pattern of a distribution 2.   Outliers are a common occurrence in survey data sets.  How to appropriately deal with outliers is open to debate.  In this problem we will look at the contaminated normal model as one approach to treat outliers that deviate from a normal sampling distribution assumption.

Suppose we have data points y1 , ..., yn . The assumed model is a normal model with mean µ and variance σ 2 . To allow for the possibility of outliers, the normal model is modified as follows:

yilµ, σ2 , δi, ui ~ Normal(µ + δiui, σ2 )

and

δilθ ~ Bern(θ)

So if δi  = 1 then the ith  observation is from a normal model with the same variance but location shifted by the factor ui .

Assume the following semiconjugate prior distributions:

µ ~ Normal(µ0 , τ0(2))

σ 2 ~ InvGamma(ν0 /2, ν0 σ0(2)/2)

ui ~ Normal(0, η2 )

θ ~ Beta(a, b)

(a)  [2 marks] Derive the conditional posterior distribution of µ .

(b)  [2 marks] Derive the conditional posterior distribution of σ 2 .

(c)  [2 marks] Derive the conditional posterior distribution of δi .

(d)  [2 marks] Derive the conditional posterior distribution of ui . (e)  [2 marks] Derive the conditional posterior distribution of θ .

(f)  [5  marks]  The  data  set  "FemaleLabour .csv"  contains  information  on  the  female  labour  force participation rate for different countries. Assuming the data follow a contaminated normal model as specified above, write some R code to implement the Gibbs sampling algorithm to obtain posterior draws of the model parameters using the full conditional distributions you derived in parts (a) to (e). Insert your computer code here. Run your algorithm for at least 100000 iterations. Assume weakly informative priors. You may ignore any missing values. Provide traceplots and autocorrelation plots for µ , σ 2  and θ .  Provide details on any burn-in period or thinning you applied to the sequence of Gibbs sampler draws to improve the convergence diagnostics.

(g)  [2 marks] Provide estimates of the posterior probability that each of the ve smallest observations are outliers.

(h  [3 marks] Display a plot of the marginal posterior density of µ . Compare this plot to one produced assuming a non-contaminated normal model, that is, yilµ, σ2  Normal(µ, σ2 )

Problem 3 [15 marks (STAT3016); 20 marks (STAT4116/STAT7016)]

The data set "topgear .csv"  contains information on cars featured on the website of the BBC television show TopGear. The data set is a subset of the data set available in the R package robustHD .  The data set has been uploaded onto the Wattle site. In this question you are going to t a Bayesian linear regression model to predict the response variables MPG  (fuel consumption in miles per gallon). Note that there are missing values in the data set (as indicated by an NA  entry).

(a)  [3 marks] Firstly, let’s ignore any missing values.  Using all other variables as candidate predictors write down the steps of your sampling algorithm to simultaneously perform Bayesian model selection and obtain posterior draws of the linear regression model parameters. Be sure to use mathematical expressions for your sequence of conditional posterior distributions. (You may ignore any interactions terms or higher order terms and consider main effects only). Assume the g-prior for your regression model.

(b)  [3 marks] Write some computer code to implement your sampling algorithm in part (a). Insert your computer code here.

(c)  [2 marks] Which variables are more strongly predictive of MPG?  Provide some output from your sampling algorithm as evidence.

(d)  [2 marks] Create a plot of posterior predictive residuals.  Comment on any lack of t of the linear model from looking at the residual graph.

(e)  [3 marks] Provide some diagnostic plots and other diagnostic measures to show convergence and stationarity of your sampling algorithm.

(f)  [2 marks] Discuss how your results might change if missing values are imputed at each iteration of the sampling algorithm rather than ignored.

(g)  [5 marks] [STAT4116/STAT7016 ONLY] State the additional steps in your sampling algorithm that you would need to implement in order to impute missing values at each iteration.  (Note, you do not actually need to run the modified algorithm that you propose here).

Problem 4 [20 marks]

The data set SPIndex .csv  contains percentage returns for the S&P 500 stock index over  1,250 days (observations), from 2001 to 2005.  The data set is part of the ISLR  library in R. The variables in the data set are:

● Year

● Lag  1  to Lag  5  - percentage returns for the ve previous days

● Volume  - the number of shares traded on the previous day

● Today  - percentage return on that date

● Direction  - whether the market was Up or Down on that date

Consider  a logistic regression model for predicting  Direction  as  a function of Lag  1  to Lag  5  and Volume .    In this question you are required to perform Bayesian model selection on the logistic regression model.

(a)  [2 marks] Write down the equation of the logistic regression model to be estimated.  Be sure to clearly define your notation for all parameters and data variables. Remember to include parameters to enable Bayesian model selection.

(b)  [2 marks] Specify the prior distributions (with reasons) that you will be assuming.

(c)  [5 marks] Write out the steps of a Metropolis-Hastings algorithm that you will run to obtain posterior draws of the parameters of your model.

(d)  [5 marks] Implement the Metropolis-Hastings algorithm your wrote in part (c) to approximate the posterior distribution of your model parameters.   Apply thinning and a burn-in period to your sequence of posterior draws as required.  Aim to achieve an acceptance rate of between 20%-50%. To achieve this, you might like to initially run your algorithm for 1000 iterations and check the acceptance rate.   If the acceptance rate is too low or too high,  adjust the tuning parameter of your proposal distribution accordingly.   Report the tuning parameter values you tested and the corresponding acceptance rates.

Note:  You must write your own code to run your Metropolis-Hastings algorithm and not use any existing computer package or function written specifically to perform Bayesian inference using posterior simulation.

(e)  [3 marks] Provide diagnostic plots to assess convergence of your Metropolis-Hastings algorithm and whether the sequence of posterior draws approximate an independent sample from the target posterior distribution.   If the diagnostics  are not satisfied,  discuss how you could modify your Metropolis-Hastings algorithm to improve the accuracy of your MCMC approximation.   (Note, please provide your diagnostic plots after any thinning or burn-in adjustment).

(f)  [3 marks] Which variables are important predictors of Direction? Provide some MCMC estimates or plot(s) to support your answer.  Obtain posterior means and posterior confidence intervals for the important variables thus identified.