rTable.2x2xK {rTableICC} | R Documentation |
Randomly Generate 2x2xK Contingency Tables
Description
A generic function that generates 2 x 2 x K contingency tables under product multinomial, multinomial or Poisson sampling plans.
Usage
rTable.2x2xK(p,sampling="Multinomial",N,K=NULL,lambda=NULL,print.raw=FALSE)
Arguments
p |
A finite |
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 |
K |
Number of centers. It must be supplied if a scalar is entered as the value of |
lambda |
Mean number of individuals in each cell of table. It is either a |
print.raw |
If |
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 \sum_{ij}n_{ijk}=n_{ij+}
, we have the following multinomial form that rTable.RxC
uses (Agresti, 2002):
\frac{n_{ij+}!}{\prod_{ij}n_{ijk}!}\prod_{ij}p_{ij|k}^{n_{ijk}},
where k=1,\dots,K
, n_{ijk}
is the count of cell (i,j,k)
, and given that an individual is in k
th 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 |
rTable.raw |
Generated table in a |
N |
Total number of generated individuals. |
sampling |
Used sampling plan in data generation. |
K |
Number of centers. |
ICC |
Returns |
structure |
Returns "2 x 2 x K" to indicate structure of generated table is "2 x 2 x K." |
print.raw |
|
print.regular |
|
Author(s)
Haydar Demirhan
Maintainer: Haydar Demirhan <haydar.demirhan@rmit.edu.au>
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
# --- 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)