Generate random contingency tables for adverse event (across rows) and drug (across columns) combinations given row and column marginal totals, embedded signals, and possibly with zero inflation
Generate random contingency tables for adverse event (across rows) and drug (across columns) combinations given row and column marginal totals, embedded signals, and possibly with zero inflation
row_marginals, col_marginals: (possibly named) vector of row and column marginal totals. Must add up to the same total. If named, the names are passed on to the randomly generated matrix/matrices.
signal_mat: numeric matrix of dimension length(row_marginals) x length(col_marginals). The (i, j)-th entry of signal_mat determines the signal strength of the i-th adverse event and j-th drug pair. The default is 1 for each pair, which means no signal for the pair.
omega_vec: vector of zero inflation probabilities. Must be of the same length as col_marginals.
no_zi_idx: List of pairs (i, j) where zero inflation is not allowed. To specify the entirety i-th row (or j-th column) use c(i, 0) (or c(0, j)). See examples.
...: Additional arguments. Currently unused.
Returns
A list of length n, with each entry being a length(row_marginal) by length(col_marginal) matrix.
Examples
set.seed(42)# first load the 46 statin datadata(statin46)# zero inflation probabilitiesomega_tru <- c(rep(0.15, ncol(statin46)-1),0)# signal matrixsignal_mat <- matrix(1, nrow(statin46), ncol(statin46))# "positive" signal at the (1, 1) entry# the first columnsignal_mat[1,1]<-10# Now simulate data with the same row/column marginals# as in statin46, with embedded signals as specified in# the above signal_mat# no zero inflation at (1, 1)# (where signal is elicited) and the last row ("Other PT")# and at the last column ("Other drugs") of the simulated matrixsim_statin <- r_contin_table_zip( n =1, row_marginals = rowSums(statin46), col_marginals = colSums(statin46), signal_mat = signal_mat, omega_vec = omega_tru, no_zi_idx = list( c(1,1), c(nrow(statin46),0),# the entire last row c(0, ncol(statin46))# the entire last column))[[1]]# now analyze the above simulated data# using a pseudo LRT with a ZIP modeltest1 <- pvlrt( contin_table = sim_statin, nsim =500# set to 500 for demonstration purposes only,# we recommend the default 10000 or bigger)extract_zi_probability(test1)extract_significant_pairs(test1)# LRT with a poisson modeltest2 <- lrt_poisson( contin_table = sim_statin, nsim =500# set to 500 for demonstration purposes only,# we recommend the default 10000 or bigger)extract_zi_probability(test2)extract_significant_pairs(test2)# LRT with true omega suppliedtest3 <- pvlrt( contin_table = sim_statin, zi_prob = omega_tru, nsim =500# set to 500 for demonstration purposes only,# we recommend the default 10000 or bigger)extract_zi_probability(test3)extract_significant_pairs(test3)