# rTable.2x2xK: Randomly Generate 2x2xK Contingency Tables In rTableICC: Random Generation of Contingency Tables

## Description

A generic function that generates 2 x 2 x K contingency tables under product multinomial, multinomial or Poisson sampling plans.

## Usage

 1 rTable.2x2xK(p,sampling="Multinomial",N,K=NULL,lambda=NULL,print.raw=FALSE) 

## Arguments

 p A finite 2\times 2\times K matrix of cell probabilities. sampling Sampling plan. It takes 'Product' for product multinomial sampling, 'Multinomial' for multinomial sampling, and 'Poisson' for Poisson sampling plans. N Total number of individuals to be generated under product multinomial or multinomial sampling plans. It is a vector of positive integers containing total number of observations in each center under product multinomial sampling plan, a positive integer of total sample size under all centers under multinomial sampling plan, and not required under Poisson sampling plan. If N is not a positive integer, its converted to do so. K Number of centers. It must be supplied if a scalar is entered as the value of lambda. lambda Mean number of individuals in each cell of table. It is either a 2\times 2\times K positive matrix or a positive scalar under Poisson sampling plan and not required for both multinomial and product multinomial sampling plans. If a positive scalar is entered, mean number of individuals in each cell will be equal to each other. print.raw If TRUE, generated raw data is printed on the screen.

## Details

To generate random tables under multinomial sampling plan, multinomial distribution with entered cell probabilities and total number of observations is directly used.

To generate random tables under product multinomial sampling plan, center totals must be entered by N. It is not possible to fix any dimension of 2x2 table under each center. Suppose that center totals are denoted by n_{ij+}, where i,j=1,2. Then with the counts satisfying ∑_{ij}n_{ijk}=n_{ij+}, we have the following multinomial form that rTable.RxC uses (Agresti, 2002):

\frac{n_{ij+}!}{∏_{ij}n_{ijk}!}∏_{ij}p_{ij|k}^{n_{ijk}},

where k=1,…,K, n_{ijk} is the count of cell (i,j,k), and given that an individual is in kth center, p_{ij|k} is the conditional probability of being the cell (i,j) of 2x2 table. This multinomial form is used to generate data under each center.

To generate random tables under Poisson sampling plan, Poisson distribution with entered mean cell counts is directly used.

## Value

A list with the following elements:

 rTable A 2\times 2\times K dimensional array including generated 2 x 2 x K contingency table. rTable.raw Generated table in a N\times 3 dimensional matrix in raw data format. First columns represent 2x2 table and the third is for center. N Total number of generated individuals. sampling Used sampling plan in data generation. K Number of centers. ICC Returns FALSE to indicate the data is generated without intraclass-correlated clusters. structure Returns "2 x 2 x K" to indicate structure of generated table is "2 x 2 x K." print.raw TRUE if generated table will be printed in raw data format. print.regular TRUE if generated table will be printed in the format determined by structure.

## Author(s)

Haydar Demirhan

Maintainer: Haydar Demirhan <[email protected]>

## References

Agresti A. (2002) Categorical Data Analysis, Wiley, New York.

Demirhan, H. and Hamurkaroglu, C. (2008) Bayesian estimation of log odds ratios from RxC and 2 x 2 x K contingency tables, Statistica Neerlandica 62, 405-424.

Kroese D.P., Taimre T., Botev Z.I. (2011) Handbook of Monte Carlo Methods, Wiley, New York.

## Examples

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 # --- Generate a 2x2x8 contingency table under multinomial sampling plan --- num.centers=8 # Number of centers sampl="Multinomial" # Generate table under multinomial # sampling plan cell.prob=array(0.03125,dim=c(2,2,num.centers)) # Enter cell probabilities in 2x2xK format num.obs=124 # Number of observations x=rTable.2x2xK(p=cell.prob,sampling=sampl,N=num.obs) print(x) # --- Generate a 2x2x8 contingency table under product multinomial sampling plan --- sampl="Product" # Generate table under product # multinomial sampling plan center.margins=array(10,num.centers) # Enter center margins y=rTable.2x2xK(p=cell.prob,sampling=sampl,N=center.margins) print(y) # --- Generate a 2x2x8 contingency table under Poisson sampling plan --- num.centers=3 sampl="Poisson" # Generate table under Poisson # sampling plan cell.mean=array(3,dim=c(2,2,num.centers)) # Enter mean number of individuals # in each cell z=rTable.2x2xK(sampling=sampl,lambda=cell.mean) print(z) 

rTableICC documentation built on Jan. 20, 2018, 9:36 a.m.