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)?
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)?
MATLAB: An Introduction with Applications
6th Edition
ISBN:9781119256830
Author:Amos Gilat
Publisher:Amos Gilat
Chapter1: Starting With Matlab
Section: Chapter Questions
Problem 1P
Related questions
Question
answer all parts please
AI-Generated Solution
AI-generated content may present inaccurate or offensive content that does not represent bartleby’s views.
Unlock instant AI solutions
Tap the button
to generate a solution
Recommended textbooks for you
MATLAB: An Introduction with Applications
Statistics
ISBN:
9781119256830
Author:
Amos Gilat
Publisher:
John Wiley & Sons Inc
Probability and Statistics for Engineering and th…
Statistics
ISBN:
9781305251809
Author:
Jay L. Devore
Publisher:
Cengage Learning
Statistics for The Behavioral Sciences (MindTap C…
Statistics
ISBN:
9781305504912
Author:
Frederick J Gravetter, Larry B. Wallnau
Publisher:
Cengage Learning
MATLAB: An Introduction with Applications
Statistics
ISBN:
9781119256830
Author:
Amos Gilat
Publisher:
John Wiley & Sons Inc
Probability and Statistics for Engineering and th…
Statistics
ISBN:
9781305251809
Author:
Jay L. Devore
Publisher:
Cengage Learning
Statistics for The Behavioral Sciences (MindTap C…
Statistics
ISBN:
9781305504912
Author:
Frederick J Gravetter, Larry B. Wallnau
Publisher:
Cengage Learning
Elementary Statistics: Picturing the World (7th E…
Statistics
ISBN:
9780134683416
Author:
Ron Larson, Betsy Farber
Publisher:
PEARSON
The Basic Practice of Statistics
Statistics
ISBN:
9781319042578
Author:
David S. Moore, William I. Notz, Michael A. Fligner
Publisher:
W. H. Freeman
Introduction to the Practice of Statistics
Statistics
ISBN:
9781319013387
Author:
David S. Moore, George P. McCabe, Bruce A. Craig
Publisher:
W. H. Freeman