{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# solution7 - Homework 7 solution 1 Problem 1 For this...

This preview shows pages 1–4. Sign up to view the full content.

Homework 7 solution 1 Problem 1 For this problem, all you need to do is to change r=0.3 if you are using the code in lab 6. R code: x2<-5 x1s<-NULL x2s<-NULL r<-0.5 for (i in 1:10000) { # Update x1 through conditional distribution of x1|x2 x1<-rnorm(1,r*x2,sqrt(1-r^2)) x1s<-c(x1s,x1) # Update x2 through conditional distribution of x2|x1 x2<-rnorm(1,r*x1,sqrt(1-r^2)) x2s<-c(x2s,x2) } mean(x1s) par(mfrow=c(2,1)) hist(x1s,main="histogram of samples simulated by Gibbs") hist(rnorm(10000),main="histogram of independent samples") 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
In my run, the estimated mean for X 1 is 0.01414714. histogram of samples simulated by Gibbs x1s Frequency -4 -2 0 2 4 0 1000 2000 histogram of independent samples rnorm(10000) Frequency -4 -2 0 2 4 0 1000 2000 Figure 1: Histograms for problem 1 2
2 Problem 2 Part 1: Algorithm: Step1: Initialize the X vector. Step2: For i = 1 , 2 , ..., d , calculate the conditional probability of X t +1 i = 1 | X t 1 , ..., X t i - 1 , X t i +1 , ..., X t d , p 1 = π ( X i =1 ,X 1 = X t 1 ,...,X i - 1 = X t i - 1 ,X i +1 = X t i +1 ,...,X d = X t d ) π ( X i =1 ,X 1 = X t 1 ,...,X i - 1 = X t i - 1 ,X i +1 = X t i +1 ,...,X d = X t d )+ π ( X i = - 1 ,X 1 = X t 1 ,...,X i - 1 = X t i - 1 ,X i +1 = X

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 6

solution7 - Homework 7 solution 1 Problem 1 For this...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online