Description Usage Arguments Value See Also Examples
Evaluates and plots the posterior density for mu, the mean of a normal distribution, with a discrete prior on mu
1 |
x |
a vector of observations from a normal distribution with unknown mean and known std. deviation. |
sigma.x |
the population std. deviation of the normal distribution |
mu |
a vector of possibilities for the probability of success in a single trial. If mu is NULL then a uniform prior is used. |
mu.prior |
the associated prior probability mass. |
n.mu |
the number of possible mu values in the prior |
... |
additional arguments that are passed to |
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 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | ## 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 uniform prior on mu
normdp(x,1)
## find the posterior density with a non-uniform prior on mu
mu = seq(-3,3,by=0.1)
mu.prior = runif(length(mu))
mu.prior = sort(mu.prior/sum(mu.prior))
normdp(x,1,mu,mu.prior)
## Let mu have the discrete distribution with 5 possible
## values, 2, 2.5, 3, 3.5 and 4, and associated prior probability of
## 0.1, 0.2, 0.4, 0.2, 0.1 respectively. Find the posterior
## distribution after a drawing random sample of n = 5 observations
## from a N(mu,1) distribution y = [1.52, 0.02, 3.35, 3.49, 1.82]
mu = seq(2,4,by=0.5)
mu.prior = c(0.1,0.2,0.4,0.2,0.1)
y = c(1.52,0.02,3.35,3.49,1.82)
normdp(y,1,mu,mu.prior)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.