Question: # in R programming # Consider a Gibbs sampler for a bivariate distribution: ( f(x,y) = k x^2 exp( -x y^2 - y^2 + 2y

# in R programming #

Consider a Gibbs sampler for a bivariate distribution:

\( f(x,y) = k x^2 exp( -x y^2 - y^2 + 2y - 4x) \)

The conditional distributions will be

\( f(x|y) = (x^2)*exp(-x*(4+y*y)) \) a Gamma density kernel

\( f(y|x) = exp(-0.5*2*(x+1)*(y^2 - 2*y/(x+1)) \) a Gaussian kernel

1) write a gibbs sampler in R sampling for the 2 conditional distributions (use the in class example of the bivariate normal as template and sampke from the gamma and normal) for an N of 10,000 and a thin of 100.

2) rewrite the same sampler with a C code and the .C function

3) rewrite the same sampler with a C code and the .Call function

4) rewrite the same sampler using a C++ code and the sourceCpp of the Rcpp package

Please call the C codes G1.c, G2.c, and G3.cpp, for the first second and third question respectively. Attach the code to your homework, along with the R scripts. Please put your name on the R scripts.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!