rTableICC.2x2xK {rTableICC} | R Documentation |
Randomly Generate 2x2xK Contingency Tables over Intraclass-Correlated Individuals
Description
A generic function that generates 2 x 2 x K contingency tables over intraclass-correlated cells under product multinomial, multinomial or Poisson sampling plans.
Usage
rTableICC.2x2xK(p,theta,M,sampling="Multinomial",N=0,lambda=NULL,zero.clusters=FALSE,
print.regular=TRUE,print.raw=FALSE)
Arguments
p |
A finite matrix of cell probabilities. Dimension of |
theta |
A finite and positive valued |
M |
The total number of clusters under each center. If number of clusters under each center is unbalanced, |
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 |
lambda |
Mean number of individuals in each cluster. It is either a |
zero.clusters |
If |
print.regular |
If |
print.raw |
If |
Details
To generate random tables under multinomial sampling plan, first total sample size is distributed to clusters with equal probabilities using the code rmultinom(1, N, rep(1/M,M))
. Then, for each center, the package partitions
is utilized to distribute individuals across cells of 2 x 2 tables under the pre-determined intraclass correlations. Let n
and m
be integer to be partitioned (cluster size) and order of partition, respectively. If there is more than one individual (n>1
) in a cluster, all possible compositions of order RC
of cluster size n
into at most m
parts are generated by using compositions
function. This provides all possible distributions of individuals in the cluster of interest into 2 x 2 table of interest. If all individuals are at the same cell, the following equation is used to calculate the probability that all individuals in the i
th cluster fall in the same cell of a contingency table of interest:
\theta_{t}p_{ij}+(1-\theta_{t})(p_{ij})^{t},
where i,j=1,2
, 0\le\theta\le 1
, \theta_{t}
is the intraclass correlation for clusters of size t
for t=2,\dots,T
, and \theta_{1}=0
. Otherwise, the probability that the individuals are in different but specified cells is calculated as follows:
(1-\theta_{t})\prod_{ij}(p_{ij})^{n_{rij}},
where n_{rij}
be the number of individuals from r
th cluster falling in the i
th row and j
th column of the considered 2 x 2 table (Altham, 1976; Nandram and Choi, 2006; Demirhan, 2013). This provides probability of each possible distribution. Then, calculated probabilities are normalized and the function rDiscrete
is utilized to randomly select one of the generated compositions. By this way, a realization is obtained for each cluster having more than one individual. If there is only one individual in a cluster, a realization is obtained by assigning the individual to cells according to the entered cell probabilities using the function rDiscrete
. The resulting random 2x2 table under one of K
centers is constructed by combining these realizations. This process is repeated for all of K
centers.
To generate random tables under product multinomial sampling plan, center margins must be entered by N
. Because both cell probabilities and fixed center margins are entered at the same time, margin probabilities calculated over the number of individuals in each center and entered K\times 4
matrix of cell probabilities must be equal to each other. To ensure intraclass correlations, the same manner as multinomial sampling plan is applied to 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 rTableICC.2x2xK
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 in the cell (i,j)
of 2 x 2 table. This multinomial form is used to generate data under each center.
To generate random tables under Poisson sampling plan, the same manner as multinomial sampling plan is taken except cluster sizes are generated from Poisson distribution with entered mean cluster counts and total sample size is calculated over the generated cluster sizes. If zero sized clusters are not allowed, truncated Poisson distribution is used to generate cluster counts.
Because total sample size is randomly distributed into the clusters, it is coincidentally possible to have clusters with more individuals than the allowed maximum cluster size. In this case, the following error message is generated:
Maximum number of individuals in one of the clusters is 14, which is greater than maximum allowed cluster size. (1) Re-run the function,
(2) increase maximum allowed cluster size by increasing the number of elements of theta, (3) increase total number of clusters, or (4) decrease total number of individuals!
and execution is stopped.
Value
Let C
be the set of clusters in which all individuals fall in a single cell of the contingency table and C'
be the complement of C
, K
be the number of centers, and T
be the maximum cluster size.
A list with the following elements is generated:
g.t |
A |
g.tilde |
A |
rTable |
A |
rTable.raw |
Generated table in a |
rTable.regular |
Generated table in a |
N |
Total number of generated individuals. |
cluster.size |
Size of each generated cluster. |
sampling |
Used sampling plan in data generation. |
M |
Total number of clusters under each center. |
K |
Number of centers. |
T |
Maximum allowed cluster size. |
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.
Altham, P.M. (1976) Discrete variable analysis for individuals grouped into families, Biometrika 63, 263–269.
Nandram, B. and Choi, J.W. (2006) Bayesian analysis of a two-way categorical table incorporating intraclass correlation, Journal of Statistical Computation and Simulation 76, 233–249.
Demirhan, H. (2013) Bayesian estimation of log odds ratios over two-way contingency tables with intraclass-correlated cells, Journal of Applied Statistics 40, 2303–2316.
Demirhan, H. and Hamurkaroglu, C. (2008) Bayesian estimation of log odds ratios from RxC and 2x2xK contingency tables, Statistica Neerlandica 62, 405–424.
Examples
# --- Generate a 2x2x4 contingency table under multinomial sampling plan ---
num.centers=4 # Number of centers
max.cluster.size=9 # Maximum allowed cluster size
num.cluster=95 # Total number of clusters under
# centers each center is equal across the
ICCs=array(0.1,dim=max.cluster.size) # Assign equal ICCs for this exmaple
ICCs[1]=0 # Assign zero ICC to clusters with
# one individual
sampl="Multinomial" # Generate table under multinomial
# sampling plan
num.obs=900 # Number of observations to be
# generated
cell.prob=array(0.0625,dim=c(num.centers,4)) # Cell probabilities sum up to one
zeros=FALSE # Do not allow zero sized clusters
x=rTableICC.2x2xK(p=cell.prob,theta=ICCs,M=num.cluster,sampling=sampl,zero.clusters=zeros,
N=num.obs,print.regular=TRUE,print.raw=FALSE)
print(x)
# --- Generate a 2x2x4 contingency table under product multinomial sampling plan ---
sampl="Product" # Generate table under product
# multinomial sampling plan
num.obs=c(200,200,200,200) # Number of observations to be generated
# under each center
cell.prob=array(0.0625,dim=c(num.centers,4)) # Cell probabilities sum up to one
zeros=FALSE # Do not allow zero sized clusters
y=rTableICC.2x2xK(p=cell.prob,theta=ICCs,M=num.cluster,sampling=sampl,
zero.clusters=zeros,N=num.obs,print.regular=TRUE,print.raw=FALSE)
print(y)
# --- Generate a 2x2x4 contingency table under Poisson sampling plan ---
sampl="Poisson" # Generate table under Poisson
# sampling plan
cell.mean=2 # Assign equal mean number of
# individual to all cells
cell.prob=array(0.0625,dim=c(num.centers,4)) # Cell probabilities sum up
# to one
z1=rTableICC.2x2xK(p=cell.prob,lambda=cell.mean,theta=ICCs,M=num.cluster,
sampling=sampl,N=num.obs,print.regular=TRUE,print.raw=FALSE)
print(z1)
cell.mean=c(2,3,3,2) # Assign equal mean number of individual
# to cells under each center
max.cluster.size=19 # Maximum allowed cluster size
ICCs=array(0.1,dim=max.cluster.size) # Assign equal ICCs for this exmaple
ICCs[1]=0 # Assign zero ICC to clusters with one
# individual
z2=rTableICC.2x2xK(p=cell.prob,lambda=cell.mean,theta=ICCs,M=num.cluster,
sampling=sampl,N=num.obs,print.regular=TRUE,print.raw=FALSE)
print(z2)