nvaricp {Bolstad} | R Documentation |
Bayesian inference for a normal standard deviation with a scaled
inverse chi-squared distribution
Description
Evaluates and plots the posterior density for sigma, the
standard deviation of a Normal distribution where the mean
mu is known
Usage
nvaricp(y, mu, S0, kappa, cred.int = FALSE, alpha = 0.05, ret = FALSE)
Arguments
y |
a random sample from a normal(mu,sigma^2) distribution. |
mu |
the known population mean of the random sample. |
S0 |
the prior scaling factor. |
kappa |
the degrees of freedom of the prior. |
cred.int |
if TRUE then a 100(1-alpha) percent credible
interval will be calculated for sigma |
alpha |
controls the width of the credible
interval. Ignored if cred.int is FALSE |
ret |
if true then the likelihood and posterior are returned as a list. |
Value
If ret is true, then a list will be returned with the following components:
sigma |
the vaules of sigma for which the prior,
likelihood and posterior have been calculated |
prior |
the prior density for sigma |
likelihood |
the likelihood function for sigma
given y |
posterior |
the posterior density of sigma given
y |
S1 |
the posterior scaling constant |
kappa1 |
the posterior degrees of freedom |
Examples
## Suppose we have five observations from a normal(mu, sigma^2)
## distribution mu = 200 which are 206.4, 197.4, 212.7, 208.5.
y<-c(206.4, 197.4, 212.7, 208.5, 203.4)
## We wish to choose a prior that has a median of 8. This happens when
## S0 = 29.11 and kappa = 1
nvaricp(y,200,29.11,1)
## Same as the previous example but a calculate a 95% credible
## interval for sigma
nvaricp(y,200,29.11,1,cred.int=TRUE)
## Same as the previous example but a calculate a 95% credible
## interval for sigma by hand
results<-nvaricp(y,200,29.11,1,cred.int=TRUE,ret=TRUE)
attach(results)
cdf<-sintegral(sigma,posterior,ret=TRUE)
Finv<-approxfun(cdf$y,cdf$x)
lb<-Finv(0.025)
ub<-Finv(0.975)
cat(paste("95% credible interval for sigma: [",
signif(lb,4),", ", signif(ub,4),"]\n",sep=""))
[Package
Bolstad version 0.2-14
Index]