mcexact           package:exactLoglinTest           R Documentation

_C_o_m_p_u_t_e_s _M_o_n_t_e _C_a_r_l_o _e_x_a_c_t _P-_v_a_l_u_e_s _f_o_r _g_e_n_e_r_a_l _l_o_g-_l_i_n_e_a_r _m_o_d_e_l_s.

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

     This function computes Monte Carlo estimates of conditional
     P-values for goodness of fit tests for general log-linear models.

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

     mcexact(formula,
             data,
             stat = gof,
             dens = hyper,
             nosim = 10 ^ 3,
             method = "bab",
             savechain = FALSE,
             tdf = 3,
             maxiter = nosim,
             p = NULL,
             batchsize = NULL)

     build.mcx.obj(formula,
             data,
             stat = gof,
             dens = hyper,
             nosim = 10 ^ 3,
             method = "bab",
             savechain = FALSE,
             tdf = 3,
             maxiter = nosim,
             p = NULL,
             batchsize = NULL)

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

 formula: Null model formula specified as in 'glm'

    data: Data frame

    stat: The test statistic, a function of the form 'function(y,
          mu.hat)' where 'y' is the observed and 'mu.hat' are the
          fitted values. Current default 'gof' is a bivariate function
          of the deviance and the Pearson chi-squared.

    dens: The target density on the log scale up to a constant of
          proportionallity. A function of the form 'function(y)'.
          Current default is (proportional to) the log of the
          generalized hypergeometric density.

   nosim: Desired number of simulations.

  method: Possibly two values, the importance sampling method of Booth
          and Butler, 'method = "bab"' or the MCMC approach of Caffo
          and Booth 'method = "cab"'.

savechain: If 'TRUE' saves the values of the chain.

     tdf: A tuning parameter

 maxiter: For 'method = "bab"' number of iterations is different from
          the number of simulations. 'maxiter' is a bound on the total
          number of iterations.

       p: A tuning parameter for 'method = "cab"'.

batchsize: Required batchsizes for 'method = "cab"'.

_D_e_t_a_i_l_s:

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

     Returns a list of class either '"bab"' or '"cab"' depending on
     'method'. The list contains all of the inputs plus all required
     information to resume the simulation. Generic functions 'print'
     and 'summary' format the output while 'update' can be used to
     resume simulations. 'mcexact' is the front end while
     'build.mcx.obj' simply builds the basic object that 'mcexact'
     applies to. 'simulate.conditional' generates a matrix of simulated
     tables.

_N_o_t_e:

_A_u_t_h_o_r(_s):

     Brian Caffo

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

     Booth and Butler (1999), "An importance sampling algorithm for
     exact conditional tests in log-linear models", Biometrika 86:
     321-332. 

     Caffo and Booth (2001). "A Markov Chain Monte Carlo Algorithm for
     Approximating Exact Conditional Probabilities", The Journal of
     Computational and Graphical Statistics 10: 730-45.

     http://www.biostat.jhsph.edu/~bcaffo/downloads.htm

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

     'fisher.test'

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

     #library(mcexact)
     set.seed(1)

     #importance sampling
     data(residence.dat)
     mcx <- mcexact(y ~ res.1985 + res.1980 + factor(sym.pair), data = residence.dat) 
     summary(mcx)

     #mcmc
     data(pathologist.dat)
     mcx <- mcexact(y ~ factor(A) + factor(B) + I(A * B),
                    data = pathologist.dat,
                    method = "cab",
                    p = .5,
                    nosim = 10 ^ 4,
                    batchsize = 100)
     summary(mcx)

