Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

MCnormalnormal

Monte Carlo Simulation from a Normal Likelihood (with known variance) with a Normal Prior


Description

This function generates a sample from the posterior distribution of a Normal likelihood (with known variance) with a Normal prior.

Usage

MCnormalnormal(y, sigma2, mu0, tau20, mc = 1000, ...)

Arguments

y

The data.

sigma2

The known variance of y.

mu0

The prior mean of mu.

tau20

The prior variance of mu.

mc

The number of Monte Carlo draws to make.

...

further arguments to be passed

Details

MCnormalnormal directly simulates from the posterior distribution. This model is designed primarily for instructional use. μ is the parameter of interest of the Normal distribution. We assume a conjugate normal prior:

μ \sim \mathcal{N}(μ_0, τ^2_0)

y is a vector of observed data.

Value

An mcmc object that contains the posterior sample. This object can be summarized by functions provided by the coda package.

See Also

Examples

## Not run: 
y <- c(2.65, 1.80, 2.29, 2.11, 2.27, 2.61, 2.49, 0.96, 1.72, 2.40)
posterior <- MCMCpack:::MCnormalnormal(y, 1, 0, 1, 5000)
summary(posterior)
plot(posterior)
grid <- seq(-3,3,0.01)
plot(grid, dnorm(grid, 0, 1), type="l", col="red", lwd=3, ylim=c(0,1.4),
   xlab="mu", ylab="density")
lines(density(posterior), col="blue", lwd=3)
legend(-3, 1.4, c("prior", "posterior"), lwd=3, col=c("red", "blue"))

## End(Not run)

MCMCpack

Markov Chain Monte Carlo (MCMC) Package

v1.5-0
GPL-3
Authors
Andrew D. Martin [aut], Kevin M. Quinn [aut], Jong Hee Park [aut,cre], Ghislain Vieilledent [ctb], Michael Malecki[ctb], Matthew Blackwell [ctb], Keith Poole [ctb], Craig Reed [ctb], Ben Goodrich [ctb], Ross Ihaka [cph], The R Development Core Team [cph], The R Foundation [cph], Pierre L'Ecuyer [cph], Makoto Matsumoto [cph], Takuji Nishimura [cph]
Initial release
2021-01-19

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.