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?
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
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?](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fbed59e22-0eed-48e4-8876-1179a1046437%2Fcff21088-a70a-4206-9d49-92c1a6a6ac89%2F0kbhie8_processed.png&w=3840&q=75)
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
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