mcm: Monte Carlo simulation of multinomial process

Description Usage Arguments Value Details Examples

View source: R/mtest.R

Description

Monte Carlo simulation of multinomial process

Usage

1
mcm(experiments = list(), n = 10000, algo = 4, NRUNIF = 0)

Arguments

experiments

List of multinomial trials. Each trial is codified as a vector with the number of results in each category. The number and order of categories must be the same in every experiment. In a binomial experiment, this would be c(number_of_successes, number_of_failures). The function also accepts a matrix (one column per experiment).

n

Number of simulations to run

algo

Algorithm for generating the pseudorandom matrix. The two most relevant algorithms are 4 (two-sided) and 5 (one-sided).

NRUNIF

number of decimal places in the pseudo-random numbers. Only for debugging purposes.

Value

List of results, as described in bernDist

Details

Algorithms 1-4 assume that the probability of each outcome is the same in every experiment, and therefore the alternative hypothesis is that at least one of the probabilities is different (either higer or lower) in at least one experiment. Algorithm 5 only works on 2x2 tables and assumes that the probability of success in the first experiment is higher than in the second experiment. Each algorithm divides the interval [0, 1] in as many sub-intervals as outcomes (nc), with the first sub-interval [0, p_1] and the last (p_nc-1, 1]:

  1. Generate nc - 1 pseudo-random numbers and divide by their sum. The resulting values are biased towards 0.5.

  2. Generate a pseudo-random number p1 between 0 and 1. Then recursively generate numbers between 1-sum(p1, p2, ...) until nc - 1 numbers have been provided. Assign every sub-interval to a pseudo-randomly chosen outcome. The resulting values are biased towards 0 if nc > 2.

  3. Like 2, but the sub-interval that is sub-divided is always the largest remaining. Less biased than 2 if nc > 2.

  4. Generate nc - 1 pseudo-random numbers in [0, 1], sort them and use them to divide the interval. This is the default algorithm.

  5. Same as 4, but one-sided and only for 2x2 tables. The sub-intervals are generated twice, and the result with a lower probability of success is assigned to the second experiment.

  6. Same as 5, but results are not sorted.

Examples

1
mcm(list(c(4, 5), c(6, 7)), n=1000, algo=4)

vqf/mtest documentation built on Dec. 23, 2021, 4:11 p.m.