Calculating function of posterior distribution of Gaussian? This is a problem from chapter 11 of All of Statistics.
The question is as follows: Let $X_1,\ldots,X_n \sim N(\mu,1)$. Let $\theta = e^\mu$. Find the posterior density for $\theta$ analytically and by simulation, where we have $f(\mu) = 1$ the flat prior.
My question is how I should be generating the density by simulation. I have that $\mu | X_1,\ldots,X_n \sim N(\bar{X}, \frac{1}{n})$, which I'm not sure is correct. 
Suppose that I do have the density $f_{\mu} = f(\mu | X_1,\ldots,X_n)$. If I were to simulate the density $f_{\theta} = f(\theta | X_1,\ldots,X_n)$, would I just sample repeatedly from $f_{\mu}$ and then apply the exponentiation to it? I feel like I'm missing something here.
Analytically, can I use the delta method here or do I have to apply $f_{\theta} \propto f(x_i|\theta)f(\theta)$ directly?
 A: Analytical:
We know that $\theta = e^\mu$ and $f(\mu) = 1$, so using the idea of change of variable:
$$
f(\theta) = f_{\mu}(\ln(\theta))\frac{d}{d\theta}(\ln(\theta)) \\ =\frac{1}{\theta}
$$
Now,
$$
f(\theta | X_1, \cdots, X_n) \propto f(X_1, \cdots, X_n | \theta)f(\theta)\\
\propto \frac{\exp( -n(\ln(\theta) - \bar{X})^2)}{\theta}
$$
which looks like a log-normal distribution with parameters - $(\bar{X}, 1/n)$
In fact, you can get to this by the definition of log-normal distribution as it is defined as a distribution whose logarithm ($\mu| X_1, \cdots, X_n$ in our case) is normal.
Simulation:
When doing the simulation we bear in mind that we only know the prior distribution & likelihood.
The following code produces the posterior distribution and plots it:
n = 100
mu = 5
std = 1
data <- rnorm(n, mean = mu, sd = std)
theta <- runif(1e4, min = 0.001, max = 250)
prior <- 1/theta # P(theta) = 1/theta
likelihood <- dnorm(mean(data), mean = log(theta), sd = 1/sqrt(n)) # P(data|theta,n) = N(data, ln(theta), 1/n)
posterior <- likelihood * prior
posterior <- posterior / sum(posterior)
samples <- sample(theta, size = 5e4, replace = T, prob = posterior)
hist(samples, freq = F, ylim = c(0, 0.03), col = "blue", 100, main = "posterior distribution", xlab = "theta")
curve(dlnorm(x, mean  = mean(data), sd = 1/sqrt(n)), from = 100, to = 250, add = T, col = "red", lwd = 4)
abline(v = exp(mu), col = "green", lwd = 4, lty = 2)

In words, this code generates points from a 1-dimensional grid over (0, 250] and then computes the posterior density at each sampled point. Finally, it samples the points based on the posterior probability to make the histogram.
Here what that looks like:

The true posterior density of the log-normal is overlayed on top with the red curve. The true value of $\theta$ ($ = e^5 = 148.4$) is shown with a green dashed line.
HTH.
