bipf                   package:cat                   R Documentation

_B_a_y_e_s_i_a_n _I_t_e_r_a_t_i_v_e _P_r_o_p_o_r_t_i_o_n_a_l _F_i_t_t_i_n_g (_B_I_P_F)

_D_e_s_c_r_i_p_t_i_o_n:

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

_U_s_a_g_e:

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

_A_r_g_u_m_e_n_t_s:

  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. 

_V_a_l_u_e:

     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.

_N_o_t_e:

     The random number generator seed must be set at least once by the
     function 'rngseed' before this function can be used.

     The starting value must lie in the interior of the parameter
     space. Hence, caution should be used when using a maximum
     likelihood  estimate (e.g., from 'ipf') as a starting value.
     Random zeros in a  table may produce mle's with expected cell
     counts of zero, and any  zero in a starting value is interpreted
     by 'bipf' as a structural  zero. This difficulty can be overcome
     by using as a starting value calculated by 'ipf' after adding a
     small positive constant (e.g., 1/2) to each cell.

_R_e_f_e_r_e_n_c_e_s:

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

_S_e_e _A_l_s_o:

     'ipf' and 'rngseed'.

_E_x_a_m_p_l_e_s:

     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

