Evaluates and plots the posterior density for pi, the probability
of a success in a Bernoulli trial, with binomial sampling and a continous
beta(a,b) prior.
Usage
binobp(x, n, a = 1, b = 1, pi = seq(0.01, 0.999, by = 0.001),
plot = TRUE)
Arguments
x
the number of observed successes in the binomial experiment.
n
the number of trials in the binomial experiment.
a
parameter for the beta prior - must be greater than zero
b
parameter for the beta prior - must be greater than zero
pi
A rannge of values for the prior to be calculated over.
plot
if TRUE then a plot showing the prior and the posterior
will be produced.
Value
An object of class 'Bolstad' is returned. This is a list with the
following components:
prior
the prior density of pi, i.e.
the beta(a,b) density
likelihood
the likelihood of x
given pi and n, i.e. the
binomial(n,pi) density
posterior
the
posterior density of pi given x and n - i.e. the
beta(a+x,b+n-x) density
pi
the values of pi for
which the posterior density was evaluated
mean
the posterior mean
var
the posterior variance
sd
the posterior std. deviation
quantiles
a set of quantiles from the posterior
cdf
a
cumulative distribution function for the posterior
quantileFun
a
quantile function for the posterior
See Also
binodpbinogcp
Examples
## simplest call with 6 successes observed in 8 trials and a beta(1,1) uniform
## prior
binobp(6,8)
## 6 successes observed in 8 trials and a non-uniform beta(0.5,6) prior
binobp(6,8,0.5,6)
## 4 successes observed in 12 trials with a non uniform beta(3,3) prior
## plot the stored prior, likelihood and posterior
results = binobp(4, 12, 3, 3)
decomp(results)
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/binobp.Rd_%03d_medium.png", width=480, height=480)
> ### Name: binobp
> ### Title: Binomial sampling with a beta prior
> ### Aliases: binobp
> ### Keywords: misc
>
> ### ** Examples
>
>
> ## simplest call with 6 successes observed in 8 trials and a beta(1,1) uniform
> ## prior
> binobp(6,8)
Posterior Mean : 0.7
Posterior Variance : 0.0190909
Posterior Std. Deviation : 0.1381699
Prob. Quantile
------ ---------
0.005 0.3073936
0.010 0.3436855
0.025 0.3999064
0.050 0.4503584
0.500 0.7137633
0.950 0.9022532
0.975 0.9251454
0.990 0.9466518
0.995 0.9584153
>
> ## 6 successes observed in 8 trials and a non-uniform beta(0.5,6) prior
> binobp(6,8,0.5,6)
Posterior Mean : 0.4482759
Posterior Variance : 0.0159564
Posterior Std. Deviation : 0.1263188
Prob. Quantile
------ ---------
0.005 0.1554803
0.010 0.1769862
0.025 0.2116211
0.050 0.2441832
0.500 0.4458341
0.950 0.6607604
0.975 0.6984390
0.990 0.7397328
0.995 0.7661081
>
> ## 4 successes observed in 12 trials with a non uniform beta(3,3) prior
> ## plot the stored prior, likelihood and posterior
> results = binobp(4, 12, 3, 3)
Posterior Mean : 0.3888889
Posterior Variance : 0.0125081
Posterior Std. Deviation : 0.1118397
Prob. Quantile
------ ---------
0.005 0.1370832
0.010 0.1552348
0.025 0.1844370
0.050 0.2119082
0.500 0.3846872
0.950 0.5802946
0.975 0.6167163
0.990 0.6577095
0.995 0.6845936
> decomp(results)
>
>
>
>
>
>
>
> dev.off()
null device
1
>