binommh: Function for Bayesian Estimation in Binomial Models

Description Usage Arguments Details Value Author(s) References Examples

View source: R/bglm_v3.R

Description

In this function the transition kernel proposed by Gamerman (1997) is implemented for a Metropolis Hastings algorithm, in order to sample the posterior distribution of the regression parameters given de data in a binomial distribution model. A normal Prior is assumed for the regression parameters. For now only the logit link is implemented.

Usage

1
2
3
4
5
## Default S3 method:
binommh(y, m, X, b = rep(0, dim(X)[2]), 
B = diag(rep(10000, dim(X)[2])),N = 3000, flag = F,...)
## S3 method for class 'formula'
binommh(formula, data = list(), weights, ...)

Arguments

formula

an object of class formula: a symbolic description of the model to be fitted.

data

A data frame containing the variables in the model.

weights

Vector indicating the total number of experiments in each observation. Note: it is not searched in the data environment.

y

Response variable, a vector codding for counts of success in a given number of trials, where m is a vector indicating the total number of experiments in each observation.

m

Vector indicating the total number of experiments in each observation.

X

Design matrix.

b

Mean of the normal prior distribution of the regression parameters.

B

Covariance matrix of the normal prior distribution of the regression parameters.

N

Number mcmc simulations of the posterior distributions of the regression parameters given de data.

flag

Logical, if TRUE iterations and acceptance ratio of the samples is printed to monitor the mcmc progress.

...

When using binommh.formula, the formula object encapsulates the arguments y and X of binommh.default, thus ... represents all other arguments needed in binommh.default to be passed to binommh.formula

Details

See Gamerman (1997) for the details.

Value

A list with the following objects:

chain

A matrix where mcmc simulations of the posterior distributions of the regression parameters given the data is stored. Rows correspond to mcmc simulation and columns correspond to the regression parameters.

Deviance

a vector with -2*l(y,chain[i,]), where l(.,.) is the log-likelihood of the model.

Accepted_samples

An integer with the number of samples accepted by the M-H algorithm.

Author(s)

Nicolas Molano-Gonzalez, Edilberto Cepeda-Cuervo

References

Gamerman, D. 1997. Sampling from the posterior distribution in generalized linear mixed models. Statistics and Computing, 7, 57-68.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
library(faraway)
data(babyfood)
summary(babyfood)
g2<- glm(cbind(disease, nondisease) ~ sex+food,family=binomial,babyfood)
#####use N > 8000 for more accurate results
bmen<-binommh(disease~ sex+food,babyfood$disease+babyfood$nondisease,N=1000,
data=babyfood)
#####compare Bayesian estimation vs clasical
data.frame(R.coef=coef(g2),R.sd=sqrt(diag(summary(g2)$cov.unscaled)),
           mh.mean=apply(bmen$chain,2,mean),mh.sd=apply(bmen$chain,2,sd))

bglm documentation built on May 30, 2017, 1:23 a.m.