Question 3 We want to estimate a single unknown parameter in a certain model. Assume that in R we have defined a function log-post to calculate the log of the unnormalized posterior density as a function of 0. This function and the data y being analysed are not shown in the code extract below. The posterior density is p(0|y). Consider the following R code: nm = 10000 theta vector (length=nm) s = 0.4 theta0 = 2 log-post = log-post (theta0) for(i in 1:nm) { = thetal theta + s*rnorm (1) log-post1= log-post (thetal) if(log(runif(1)) < log-post1-log-post0){ theta = thetal log-post = log-post1 } theta[i] theta } quantile (theta, probs-c (0.5, 0.025, 0.975)) An explanation in words is all that is needed for this question. (a) What is the name of the algorithm that the code is carrying out? (b) Explain what the command thetal = theta0 + s*rnorm (1) is doing in the context of the algorithm. (c) When the code has run, what will the vector theta contain? (d) In statistical terms, what will the last line of code output? Suppose that the data y was a sample from an exponential distribution with parameter 8. The code below follows from the preceding code. v = rexp(length(theta), rate-theta) mean (v>5 & v<10) (e) When this code has run, what will v contain? (f) What will the last line of code output (in statistical terms)?

Calculus For The Life Sciences
2nd Edition
ISBN:9780321964038
Author:GREENWELL, Raymond N., RITCHEY, Nathan P., Lial, Margaret L.
Publisher:GREENWELL, Raymond N., RITCHEY, Nathan P., Lial, Margaret L.
Chapter9: Multivariable Calculus
Section9.1: Functions Of Several Variables
Problem 34E: The following table provides values of the function f(x,y). However, because of potential; errors in...
icon
Related questions
Question

answer all parts please

Question 3
We want to estimate a single unknown parameter in a certain model. Assume that in R we
have defined a function log-post to calculate the log of the unnormalized posterior density as
a function of 0. This function and the data y being analysed are not shown in the code extract
below. The posterior density is p(0|y). Consider the following R code:
nm = 10000
theta vector (length=nm)
s = 0.4
theta0 = 2
log-post = log-post (theta0)
for(i in 1:nm) {
=
thetal theta + s*rnorm (1)
log-post1= log-post (thetal)
if(log(runif(1)) < log-post1-log-post0){
theta = thetal
log-post = log-post1
}
theta[i] theta
}
quantile (theta, probs-c (0.5, 0.025, 0.975))
An explanation in words is all that is needed for this question.
(a) What is the name of the algorithm that the code is carrying out?
(b) Explain what the command thetal = theta0 + s*rnorm (1) is doing in the context
of the algorithm.
(c) When the code has run, what will the vector theta contain?
(d) In statistical terms, what will the last line of code output?
Suppose that the data y was a sample from an exponential distribution with parameter 8. The
code below follows from the preceding code.
v = rexp(length(theta), rate-theta)
mean (v>5 & v<10)
(e) When this code has run, what will v contain?
(f) What will the last line of code output (in statistical terms)?
Transcribed Image Text:Question 3 We want to estimate a single unknown parameter in a certain model. Assume that in R we have defined a function log-post to calculate the log of the unnormalized posterior density as a function of 0. This function and the data y being analysed are not shown in the code extract below. The posterior density is p(0|y). Consider the following R code: nm = 10000 theta vector (length=nm) s = 0.4 theta0 = 2 log-post = log-post (theta0) for(i in 1:nm) { = thetal theta + s*rnorm (1) log-post1= log-post (thetal) if(log(runif(1)) < log-post1-log-post0){ theta = thetal log-post = log-post1 } theta[i] theta } quantile (theta, probs-c (0.5, 0.025, 0.975)) An explanation in words is all that is needed for this question. (a) What is the name of the algorithm that the code is carrying out? (b) Explain what the command thetal = theta0 + s*rnorm (1) is doing in the context of the algorithm. (c) When the code has run, what will the vector theta contain? (d) In statistical terms, what will the last line of code output? Suppose that the data y was a sample from an exponential distribution with parameter 8. The code below follows from the preceding code. v = rexp(length(theta), rate-theta) mean (v>5 & v<10) (e) When this code has run, what will v contain? (f) What will the last line of code output (in statistical terms)?
AI-Generated Solution
AI-generated content may present inaccurate or offensive content that does not represent bartleby’s views.
steps

Unlock instant AI solutions

Tap the button
to generate a solution

Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Calculus For The Life Sciences
Calculus For The Life Sciences
Calculus
ISBN:
9780321964038
Author:
GREENWELL, Raymond N., RITCHEY, Nathan P., Lial, Margaret L.
Publisher:
Pearson Addison Wesley,
Algebra & Trigonometry with Analytic Geometry
Algebra & Trigonometry with Analytic Geometry
Algebra
ISBN:
9781133382119
Author:
Swokowski
Publisher:
Cengage