Question 1 -
Consider a set of data relating two score tests, LSAT and GPA, at a sample of 15 American law schools. Of interest is the correlation θ = cor(lsat, gpa) between these measurements and the variance ratio ψ = var(lsat)/var(gpa).
list(lsat = c(576, 635, 558, 578, 666, 580, 555, 661, 651, 605, 653, 575, 545, 572, 594),
gpa = c(3.39, 3.30, 2.81, 3.03, 3.55, 3.07, 3.00, 3.43, 3.36, 3.13, 3.12, 2.74, 2.76, 2.88, 2.96),
n = 15)
1. Write a function in R called CI.cor that returns 95% bootstrap confidence intervals for the correlation parameter θ using the basic bootstrap interval method and the percentile interval method. Your answer should contain the R function CI.var.cor.
2. Write a function in R called CI.var.ratio. that returns 95% bootstrap confidence intervals for the variance ratio ψ using the basic bootstrap interval method and the percentile interval method.
Your answer should contain the R function CI.var.ratio.
Question 3 -
Consider the following dataset
list(t = c(94.3, 15.7, 62.9, 126, 5.24, 31.4, 1.05, 1.05, 2.1, 10.5),
x = c(5, 1, 5, 14, 3, 19, 1, 1, 4, 22),
n = 10)
on observed failures xi of n = 10 power plant pumps. Here ti denotes the length of operation time of the pump (in 1000s of hours). The number of failures Xi is assumed to follow a Poisson distribution Xi| θi ∼ Poisson(θiti). Consider the hierarchical model
θi| α, β ∼ Gamma(α, β)
where
α ∼ Exp(λ), β ∼ Gamma(γ, δ), λ = 1 and γ = δ = 0.01.
1. What are the conditional posterior distributions of
- θi| θ-i, α, β, x;
- β | θ, α, x;
- α | θ, β, x?
Write your answer in a section called Question 3 (a) of the file.
2. Write a function in R called mcmc.pumps that implements a general McMC algorithm with components θ, β, α where θ and β are updated from the posterior conditional distribution and log α is updated via a random walk Metropolis step with normal increments. The function should return samples from the posterior distribution of θ, β and α as well as an estimate of the probability of accepting α.
Your answer must contain the code of the function mcmc.pumps.
3. Write a function in R called predictive.pumps that returns estimates of the predictive distribution of failures for the i-th pump for a given length of operation time t∗i, using Monte Carlo integration.
Your answer must contain the code of the function predictive.pumps.
Question 4 -
Let x1, . . . , xn be a sample of independent and identically distributed observations assumed to have been generated from a t-distribution with ν degrees of freedom located at µ, i.e.,
f(x | µ) ∝ {1 + 1/ν(x - µ)2}-(ν+1)/2 x ∈ R. (1)
Assume ν = 10 and suppose µ ∼ N(0, 1).
1. Write down, up to proportionality constant, the posterior µ | x. Is this a recognisable density? Write a function in R called mcmc.t that implements an McMC algorithm for evaluating the posterior distribution of µ where the updating is done using random walk Metropolis with a normal candidate generator.
Your answer should contain the posterior density of µ | x in a section called Question 4 (1) of the =matriculationA2math= file and the function mcmc.t separately in and scriptA2.R
2. Using the fact that the t-distribution is a scale mixture of normals, the sampling model in (1) can alternatively be represented as
xi| µ, zi ∼ N(µ, 1/zi)
where zi are a priori independent of µ and
f(zi) ∝ zi(ν/2)-1 exp{-(ν/2) zi}.
Using this representation together with the prior distribution µ ∼ N(0, 1), write down, up to proportionality constant, the conditional posterior densities of µ and of each zi , i = 1, . . . , n and identify the distributions corresponding to each of these densities. Write a function in R called mcmc.gibbs that implements a Gibbs sampling algorithm for computing the posterior distribution of µ.
Your answer should contain the conditional posterior densities of µ and each of the zis in the file in a section called Question 4 (2) of the =matriculationA2math= file and the function mcmc.gibbs separately in and scriptA2.R
3. Let x∗ denote a future observable. Write a function in R called predictive.t that returns estimates of the predictive distribution x∗| x using Monte Carlo integration. Your answer must contain the code of the function predictive.t.
4. Write a function in R called predictive.quantile that estimates the pth quantile of the predictive distribution
xp : Pr (x∗ ≤ xp | x) = p
and use it to construct a 95% predictive interval.
Your answer must contain the code of the function predictive.quantile as well the code used to obtain the 95% predictive interval.
I Need help with questions 1, 3, 4.
Attachment:- Assignment File.rar