Hi everyone,
   
  My goal is to sample from a two-dimensional grid. Consider the following example of code:
   
  n.grid <- 500
muA.grid <- seq(-4,4, length=n.grid)
muB.grid <- seq(-4,4, length=n.grid)
mu.p <- matrix(NA, nrow=n.grid, ncol=n.grid)
for(i in 1:n.grid){
  for(j in 1:n.grid){
    mu.p[i,j] <- dnorm(muA.grid[i], 0, 1)*dnorm(muB.grid[j], 0, 0.5)
    }
}
   
  mu.p <- mu.p/sum(mu.p)
   
  I would now like to sample the grid of points from the probabilities in mu.p. Im using the multivariate normal here for illustration as my real problem is a more complicated probability density. If this problem were only one-dimensional, this is easy:
   
  n.samples <- 1000 
  # assuming mu.p and muA.grid are now the appropriate vectors
  mu <- sample(muA.grid, n.samples, replace=T, prob=mu.p)
   
  However, im not sure how to do this in two-dimensions in R.
   
  Thanks in advance for any help.
   
  All the best,
  Gregory Gentlemen

       
---------------------------------

	[[alternative HTML version deleted]]

