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 8. 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: nb = 1000 nm 10000 theta = vector (length=nm) S = 0.4 theta = 2 log-post for (i in 1: (nb+nm)) { log-post (thetao) thetal = rnorm(1, mean-theta®, sd=s) log-post1 = log-post (thetal) if(log (runif(1)) nb) theta[i-nb] = theta stheta sort (theta) stheta [nm/2] stheta [nm*0.025] stheta [nm*0.975] Except where stated, 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 = rnorm(1, mean-thetad, sd=s) is doing in the context of the algorithm. (c) Explain what the command if(log (runi f(1)) < log-postl-log-posto) is doing in the context of the algorithm. In your answer, include a formula involving p(0|y) that the code is implementing. (d) What are the effects on the behaviour of the algorithm of making the variable called s smaller? What are the effects of making it larger? (e) What is the purpose of the variable called nb? (f) When the code has run, what will the vector theta contain? (g) In statistical terms, what will the command stheta [nm/2] output? (h) In statistical terms, what will the last two lines of code output?

MATLAB: An Introduction with Applications
6th Edition
ISBN:9781119256830
Author:Amos Gilat
Publisher:Amos Gilat
Chapter1: Starting With Matlab
Section: Chapter Questions
Problem 1P
icon
Related questions
Question

answer all parts

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 8. 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:
nb = 1000
nm 10000
theta = vector (length=nm)
S = 0.4
theta = 2
log-post
for (i in 1: (nb+nm)) {
log-post (thetao)
thetal = rnorm(1, mean-theta®, sd=s)
log-post1 = log-post (thetal)
if(log (runif(1)) <log-post1-log-post0) {
thetao
thetal
log-post = log-post1
}
if(i>nb) theta[i-nb] = theta
stheta sort (theta)
stheta [nm/2]
stheta [nm*0.025]
stheta [nm*0.975]
Except where stated, 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 = rnorm(1, mean-thetad, sd=s) is doing in
the context of the algorithm.
(c) Explain what the command if(log (runi f(1)) < log-postl-log-posto) is doing
in the context of the algorithm. In your answer, include a formula involving p(0|y) that
the code is implementing.
(d) What are the effects on the behaviour of the algorithm of making the variable called s
smaller? What are the effects of making it larger?
(e) What is the purpose of the variable called nb?
(f) When the code has run, what will the vector theta contain?
(g) In statistical terms, what will the command stheta [nm/2] output?
(h) In statistical terms, what will the last two lines of code output?
Transcribed Image Text: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 8. 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: nb = 1000 nm 10000 theta = vector (length=nm) S = 0.4 theta = 2 log-post for (i in 1: (nb+nm)) { log-post (thetao) thetal = rnorm(1, mean-theta®, sd=s) log-post1 = log-post (thetal) if(log (runif(1)) <log-post1-log-post0) { thetao thetal log-post = log-post1 } if(i>nb) theta[i-nb] = theta stheta sort (theta) stheta [nm/2] stheta [nm*0.025] stheta [nm*0.975] Except where stated, 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 = rnorm(1, mean-thetad, sd=s) is doing in the context of the algorithm. (c) Explain what the command if(log (runi f(1)) < log-postl-log-posto) is doing in the context of the algorithm. In your answer, include a formula involving p(0|y) that the code is implementing. (d) What are the effects on the behaviour of the algorithm of making the variable called s smaller? What are the effects of making it larger? (e) What is the purpose of the variable called nb? (f) When the code has run, what will the vector theta contain? (g) In statistical terms, what will the command stheta [nm/2] output? (h) In statistical terms, what will the last two lines of code output?
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

Recommended textbooks for you
MATLAB: An Introduction with Applications
MATLAB: An Introduction with Applications
Statistics
ISBN:
9781119256830
Author:
Amos Gilat
Publisher:
John Wiley & Sons Inc
Probability and Statistics for Engineering and th…
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 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…
Elementary Statistics: Picturing the World (7th E…
Statistics
ISBN:
9780134683416
Author:
Ron Larson, Betsy Farber
Publisher:
PEARSON
The Basic Practice of Statistics
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
Introduction to the Practice of Statistics
Statistics
ISBN:
9781319013387
Author:
David S. Moore, George P. McCabe, Bruce A. Craig
Publisher:
W. H. Freeman