Learn R Programming

SMPracticals (version 1.4-3.1)

coin.spin: Function for Coin Spinning, Practical 11.1

Description

This function computes the posterior distribution of the success probability theta when a coin is spun on its edge (or tossed), when the prior density for that probability is a mixture of beta densities.

Usage

coin.spin(para, r = 0, n = 0, n.points = 199)

Value

x

Values of theta

y

Values of posterior density for theta

Arguments

para

A matrix with 3 columns and k rows, where k is the number of components of the mixture. The first column contains the probabilities, and the next two the shape parameters a and b for the components.

r

Number of successes

n

Number of trials

n.points

The number of values of theta, equally-spaced between 0 and 1.

Author

Anthony Davison (anthony.davison@epfl.ch)

Details

This is provided simply so that readers spend less time typing. It is not intended to be robust and general code.

References

Davison, A. C. (2003) Statistical Models. Cambridge University Press. Practical 11.1.

Examples

Run this code
## From Practical 11.1:
para <- matrix( c(0.5, 10, 20, 0.5, 20, 10), nrow=2, ncol=3, byrow=TRUE)
prior <- coin.spin(para)
plot(prior, xlab="theta",ylab="PDF", type="l",ylim=c(0,6))
post <- coin.spin(para, r=4, n=10)

Run the code above in your browser using DataLab