R: Bayesian inference for a normal standard deviation with a...
nvaricp
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, plot = TRUE, ...)
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.
plot
if TRUE then a plot showing the prior and the posterior
will be produced.
...
this allows the arguments cred.int (which is logical), and
alpha (numerical between 0 and 1 exclusive) to be specified for compatibility
with previous versions. A warning will be issued about these arguments being
deprecated which is why there are no examples using them.
Value
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. NOTE this method has changed
results = nvaricp(y,200,29.11,1)
quantile(results, probs = c(0.025, 0.975))
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(Bolstad)
Attaching package: 'Bolstad'
The following objects are masked from 'package:stats':
IQR, sd, var
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/Bolstad/nvaricp.Rd_%03d_medium.png", width=480, height=480)
> ### Name: nvaricp
> ### Title: Bayesian inference for a normal standard deviation with a scaled
> ### inverse chi-squared distribution
> ### Aliases: nvaricp
> ### Keywords: misc
>
> ### ** 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)
S1: 321.9 kappa1 :6
>
> ## Same as the previous example but a calculate a 95% credible
> ## interval for sigma. NOTE this method has changed
> results = nvaricp(y,200,29.11,1)
S1: 321.9 kappa1 :6
> quantile(results, probs = c(0.025, 0.975))
[1] 4.720154 16.130040
>
>
>
>
>
> dev.off()
null device
1
>