normnp {Bolstad}R Documentation

Bayesian inference on a normal mean with a normal prior

Description

Evaluates and plots the posterior density for mu, the mean of a normal distribution, with a normal prior on mu

Usage

normnp(
  x,
  m.x = 0,
  s.x = 1,
  sigma.x = NULL,
  mu = NULL,
  n.mu = max(100, length(mu)),
  ...
)

Arguments

x

a vector of observations from a normal distribution with unknown mean and known std. deviation.

m.x

the mean of the normal prior

s.x

the standard deviation of the normal prior

sigma.x

the population std. deviation of the normal distribution. If this value is NULL, which it is by default, then a flat prior is used and m.x and s.x are ignored

mu

a vector of prior possibilities for the true mean. If this is null, then a set of values centered on the sample mean is used.

n.mu

the number of possible mu values in the prior

...

optional control arguments. See Bolstad.control

Value

A list will be returned with the following components:

mu

the vector of possible mu values used in the prior

mu.prior

the associated probability mass for the values in mu

likelihood

the scaled likelihood function for mu given x and sigma.x

posterior

the posterior probability of mu given x and sigma.x

mean

the posterior mean

sd

the posterior standard deviation

qtls

a selection of quantiles from the posterior density

See Also

normdp normgcp

Examples


## generate a sample of 20 observations from a N(-0.5,1) population
x = rnorm(20,-0.5,1)

## find the posterior density with a N(0,1) prior on mu
normnp(x,sigma=1)

## find the posterior density with N(0.5,3) prior on mu
normnp(x,0.5,3,1)

## Find the posterior density for mu, given a random sample of 4
## observations from N(mu,sigma^2=1), y = [2.99, 5.56, 2.83, 3.47],
## and a N(3,sd=2)$ prior for mu
y = c(2.99,5.56,2.83,3.47)
normnp(y,3,2,1)


[Package Bolstad version 0.2-41 Index]