R: Calculate a credible interval from a numerically specified...
credIntSamp
R Documentation
Calculate a credible interval from a numerically specified
posterior CDF
Description
Calculates a lower, upper, or two-sided credible interval
from the numerical posterior CDF.
Usage
credIntSamp(theta, conf = 0.95, type="twosided")
Arguments
theta
a sample from the posterior density
conf
the desired 'confidence' level
type
the type of interval to return, 'lower' = one sided lower
bound, 'two-sided' = two - sided, or 'upper' = one sided upper
bound. It is sufficient to use 'l','t' or 'u'
Details
This function uses linear interpolation to calculate bounds for points
that may not be specified by CDF
Value
a list containing the elements lower.bound, uppper.bound or both
depending on type
Examples
## posterior is N(0,1)
theta <- rnorm(1000)
ci<-credIntSamp(theta)
plot(density(theta))
abline(v=c(unlist(ci)))
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(Bolstad2)
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/Bolstad2/credIntSamp.Rd_%03d_medium.png", width=480, height=480)
> ### Name: credIntSamp
> ### Title: Calculate a credible interval from a numerically specified
> ### posterior CDF
> ### Aliases: credIntSamp
>
> ### ** Examples
>
> ## posterior is N(0,1)
> theta <- rnorm(1000)
> ci<-credIntSamp(theta)
Credible interval is (-2.02543363759709,1.93846680202266)
> plot(density(theta))
> abline(v=c(unlist(ci)))
>
>
>
>
>
> dev.off()
null device
1
>