Skip to content
tlamadon edited this page Feb 19, 2013 · 2 revisions

This demonstrate a simple example. It shows how to write an objective function and also how to write a sampler.

In this example we are going to estimate the mean of a simple joint normal distribution. We are given 2 moments which are the means in the population, and we want to recover those using sampling. This is a silly example since the mean is already the best estimator, however it will allow us to understand the structure of the program.

Objective function

The signature for the objective function is describe here.

true_mean = c(2,-1)
obj <- function(p) {
  # sample 50 draws according to means in p
  rr = expand.grid(true_mean,1:50)
  rr = ddply(rr,.(
  R1 = rnorm(50)+true_mean[1]
  R2 = rnorm(50)+true_mean[2]
Clone this wiki locally