Learn R Programming

cat (version 0.0-9)

bipf: Bayesian Iterative Proportional Fitting (BIPF)

Description

Markov-Chain Monte Carlo method for simulating posterior draws of cell probabilities under a hierarchical loglinear model

Usage

bipf(table,margins, prior=0.5, start, steps=1, showits=FALSE)

Value

array like table, but containing simulated cell probabilities that satisfy the loglinear model. If the algorithm has converged, this will be a draw from the actual posterior distribution of the parameters.

Arguments

table

contingency table (array) to be fitted by a log-linear model. All elements must be non-negative.

margins

vector describing the marginal totals to be fitted. A margin is described by the factors not summed over, and margins are separated by zeros. Thus c(1,2,0,2,3,0,1,3) would indicate fitting the (1,2), (2,3), and (1,3) margins in a three-way table, i.e., the model of no three-way association.

prior

optional array of hyperparameters specifying a Dirichlet prior distribution. The default is the Jeffreys prior (all hyperparameters = .5). If structural zeros appear in table, a prior should be supplied with hyperparameters set to NA for those cells.

start

starting value for the algorithm. The default is a uniform table. If structural zeros appear in table, start should contain zeros in those cells and ones elsewhere.

steps

number of cycles of Bayesian IPF to be performed.

showits

if TRUE, reports the iterations so the user can monitor the progress of the algorithm.

References

Schafer (1996) Analysis of Incomplete Multivariate Data. Chapman & Hall, Chapter 8.

See Also

ipf and rngseed.

Examples

Run this code
data(HairEyeColor)                     # load data
m=c(1,2,0,1,3,0,2,3)                   # no three-way interaction
thetahat <- ipf(HairEyeColor,margins=m,
            showits=TRUE)              # fit model
thetahat <- ipf(HairEyeColor+.5,m)     # find an interior starting value 
rngseed(1234567)                       # set random generator seed
theta <- bipf(HairEyeColor,m,
              start=thetahat,prior=0.5,
              steps=50)                # take 50 steps

Run the code above in your browser using DataLab