Learn R Programming

SMPracticals (version 1.4-3.1)

poi.beta.laplace: Laplace Approximation for Posterior Density, Practical 11.2

Description

This function computes the Laplace approximation to the posterior density of the parameter beta in a Poisson regression model. For more details see Practical 11.2 of Davison (2003).

Usage

poi.beta.laplace(data, alpha = get.alpha(data), phi = 1, nu = 0.1, 
                 beta = seq(from = 0, to = 7, length = 1000))

Value

int

Estimated integral of posterior density.

conv

Did the routine for the Laplace optimization converge?

x

Values of beta

y

Values of posterior density

Arguments

data

A data frame with vector components y and x of the same length. y contains the numbers of counts, and x the corresponding time intervals.

alpha

Prior value of a parameter, estimated from the data by default.

phi

Prior value of a parameter.

nu

Prior value of a parameter.

beta

Values for which posterior density of beta should be provided.

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.2.

Examples

Run this code
## From Practical 11.2:
get.alpha <- function(d)
{  # estimate alpha from data
  rho <- d$y/d$x
  n <- length(d$y)
  mean(rho)^2/( (n-1)*var(rho)/n - mean(rho)*mean(1/d$x) )
}
data(cloth)
attach(cloth)
plot(x,y)
beta <- seq(from=0,to=10,length=1000)
beta.post <- poi.beta.laplace(cloth,beta=beta,nu=1)
plot(beta.post,type="l",xlab="beta",ylab="Posterior density")
beta.post <- poi.beta.laplace(cloth,beta=beta,nu=5)
lines(beta.post,lty=2)

Run the code above in your browser using DataLab