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

MTHM017 Advanced Topics in Statistics

Ref/Def Assignment

The assignment has three main parts. Part A involves (i) fitting a Poisson regression model to assess the effect of using different priors, and (ii) fitting an auto-regressive process to time series data using the BUGS language in order to estimate missing data. Part B involves using different methods for classification of data into two groups. Part C involves producing a narrated power point presentation based on question 3 of part

.

Part A and B gives 80% of your nal marks and Part C gives 20% of your nal marks.  [Assignment:  125 marks in total]

A. Bayesian Inference [66 marks]

1.  The rst question of part A involves tting a Poisson regression model using the Ohio_Data dataset, which contains the observed and expected counts of lung cancer for counties in Ohio for 1988.

(i)  [3 marks] Calculate the Standard Mortality Ratios (SMRs) for each county and plot the distribution of the SMRs. Next, plot a map of the SMRs by county. You may want to use the following code using the OhioMap function which uses random numbers (the le with the code is attached), or you can write your own.

source ("OhioMap .R")

library(maps)

map .text("county" ,  "ohio")

testdat  <-  runif(88)  #  need  to  read  in  the  OhioMap  function

OhioMap(testdat,ncol=8 ,type="e" ,figmain= "Ohio  random  numbers" ,lower=0 ,upper=2)

We are interested in estimating the relative risk (RR) for each county and we are going to t a Poisson

model of the following form:

Obsi  ~ Pois(µi )

log(µi ) = log(Expi ) + β0 + log(θi )

RRi  = exp(β0 ) * θi

Where the prior distributions for θi  are Gamma(α, α). Here, the Exp(ected) numbers are an offset’, i.e. we don’t assign a coefficient to them (or another way of putting it is that we x the coefficient to be one).

(ii)  [4 marks] Describe the role of β0  and the set of θ’s in this model and how they contribute to the

estimation of RR.

(iii)  [14 marks] Code up this Poisson-Gamma model in JAGS to analyse the Ohio data. Use the priors p(β0 ) ~ Unif(-100, 100) and α ~ Gamma(1, 1). Initialise 2 chains and run the model with these two chains. You will have to decide on the appropriate values of n .iter and burnin. Produce

trace plots for the chains and summaries of all the parameters. Investigate whether the chains for all the parameters have converged.

(iv)  [6 marks] Extract the posterior means for the RR and map them. Then calculate the posterior

probabilities that the relative risk in each area exceeds 1.2.  Extract these probabilities and map

them.

(v)  [6 marks] Repeat the analysis with different priors for β0  and α . The exact choice is yours, but explain why you have chosen them and what they mean. Map the two sets of RRs and explain any differences you see in the summaries of the posteriors for the parameters of the model.

2.  One factor that affects the relative risk of lung cancer is air pollution.  The dataset ohio_pm25 .csv contains measurements of particulate matter (PM2.5) air pollution in Ohio for 1988-1989. However there is missing data. We will use JAGS to impute this missing data so that the PM2.5 measurements can be fed into the relative risk analysis at a later stage (note that this last step is not part of the assignment).

(i)  [4  marks]  Do  some  exploratory  data  analysis:   summarise  the  data,  then  plot  the  PM2.5 measurements against time, highlighting (showing clearly) the periods of missing data.

We  are  going  to  t  a  model  that  allows  us  to  estimate  these  previously  seen  missing data  by  treating  them  as  model  parameters  that  will  be  estimated  (and  we  nd  posterior distributions for them). As we have time series data, we are going to use the fact that day-to-day measurements will be correlated, i.e. today’s measurement will correlate with yesterday’s.

A random walk process of order 1, RW(1), is dened at time t as

Yt - Yt − 1  = wt

Yt  = Yt − 1 + wt

Where wt  are a set of realisations of random (or white) noise, e.g. wt  ~ N (0, σw(2)). Note the first line refers to the differences in the values at consecutive time points being white noise.

We  are  interested  in  tting  a  random  walk  model  to  the  Ohio  data.    The  model  will  be of the following form:

Ohiot  ~ N(Yt , σv(2))

Yt  ~ N(Yt 1 , σw(2))

Where σw(2)  is the variance of the white noise process associated to the random walk. We then make noisy measurements of this random walk process, thus Ohiot , the measurement we have at time t, equals to the true value of the underlying process Yt  plus some measurement error. In the formula above, σv(2)  is the variance of this measurement error.

(ii)  [12 marks] Code this model using the model definition below in JAGS to analyse the Ohio data for 1988(!). Due to the nature of the model you will have to explicitly specify a value for Y1 in the model (i.e. for the rst time point as Y0  doesn’t exist). One suggestion might be Y1  ~ dnorm(6, 0.001).

The model denition can be found below.

Run the model for 10,000 iterations, with 2 chains, discarding the rst 5,000 as burn-in’. Produce trace plots for the chains and summaries for the tted parameters (including the missing data). In your solution le you should include a representative sample of this output.

Hint: You will have to initialise both chains. One suggestion might be using the mean and median to initialise the missing values of Ohio, and using random uniforms (with a narrow interval centred around say 6) to initialise Y.

#  model

jags .mod  <-  function(){

#  Observation  model

for  (i  in  2   :  N)  {

Ohio[i]  ~  dnorm (Y[i],tau .v)

}

Ohio[1]  ~  dnorm (Y[1],tau .v)

tau .v  ~  dgamma(1 ,0.01)

#  System  model

for(i  in  2:N){

Y[i]  ~  dnorm (Y[i-1],tau .w)

}

Y[1]  ~  dnorm(6 ,0.001)

tau .w  ~  dgamma(1 ,0.01)

sigma .w  <-  1/sqrt(tau .w)

}

(iii)  [3 marks] Comment on whether the chains for all the parameters have converged.  You should include evidence that supports your claim.

(iv)  [4 marks] Extract the posterior means and 95% credible intervals for t , and plot them against

 

(v)  [6 marks] Use your model to predict the measurements of PM2.5 at Ohio for the rst week of 1989. Plot the predicted values of PM2.5 for the rst week of 2004, along with the actual measurements, against time.  Calculate the root mean squared error of this prediction. For this you may want to re-run the model with an extra line to calculate ′     , noting that this value will also have a posterior distribution as it is a function of the predicted values (that are treated as unknown paramaters that need to be estimated).

(vi)  [4 marks] Suppose that after doing this analysis we receive some PM2.5 measurements from a site that has similar parameters to our original monitoring location. We want to repeat the analysis and fill in the missing data for this new site as well. What priors should we use for the precision parameters? Explain your choice.

B. Classication [34 marks]

The following gure shows the information in the dataset Classification .csv - it shows two different groups, plotted against two explanatory variables.  This is simulated data - the aim is to nd a suitable method for classifying the 200 datapoints into two groups from a selection of possible approaches.

4

 

 

2

 

 

0 

 

 

−2 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

−2                                                                                    0                                                                                     2

X1

Group

  0

  1

1.  [4 marks] Summarise the two groups in terms of the variables X1  and X2 .  Describe your ndings. Considering the plot showing the observations and the numerical summaries, which of the following classification methods do you think are suitable for classifying this data and why?

a.  Linear discriminant analysis.

b.  Quadratic discriminant analysis.

c.  K-nearest neighbour regression.

d.  Support vector machines.

e.  Random forests.

2.  [1 marks] Select 75% of the data to act as a training set, with the remaining 25% for testing/evaluation.

3.  [27 marks] Choose four of the methods listed in Question 1 that might be suitable to classify the data. Perform classification using these methods. In each case, briefly describe how the classification

method works, present the results of an evaluation of the method (highlighting different aspects of the model performance) and describe your ndings. Where appropriate optimise the (hyper)parameters of the method.

4.  [2 marks] Compare the results from your chosen four approaches and select what you think is the best method for classification in this case, explaining your reasoning.

C. Presentation [25 marks]

The presentation is based on PartB/Q3 only. You should submit a narrated power-point presentation that should be 5 minutes long, and you should aim for 5-6 slides in total (this includes the introduction/summary and a slide on each method).

In the presentation you should explain what the problem is, how you approached it, and what your ndings

are.

You should pay attention to the clarity/pace/coherency of the delivery, the style/information-balance on the slides, clear description of methodology and time management.

The deadline for submission is Noon (12pm), 8th August.

You should submit the narrated power point presentation and a pdf that will contain your answers (and relevant output!)  to the questions via eBart.  In Part A you should use the R programming language, but in Part B you can choose to use R or Python (or both).