multiple_binary_test: Perform goodness-of-fit tests on multiple binary chains.

Description Usage Arguments Details Value Examples

View source: R/multiple_binary_test.R

Description

multiple_binary_test is used to preform goodness-of-fit tests on multiple binary chains of data of the same length to see if a Markov chain model is appropriate.

Usage

1
2
multiple_binary_test(binary_chains, swaps = 1000, n = 1000, run = 4,
  bins = 30, success = NULL)

Arguments

binary_chains

A two dimensional matrix, in which there are two unique values.

swaps

A positive nonzero integer value for the number of swaps to be attempted on the chain. Larger values will tend to yield "more independent" data. Generally, the number of swaps should be much larger then the number of elements in the matrix binary_chains.

n

A positive nonzero integer representing the number of new sets of chains to be generated.

run

The length of the run to test for if one is interested in run test statistics.

bins

The number of bins to be displayed in histograms of test statistics when one plots objects generated by multiple_binary_test.

success

Denotes the data entry to be counted for run statistics.

Details

multiple_binary_test works by taking the supplied binary_chains parameter, counting the transitions between different elements, and then generating n new sets of chains with the same number of transitions. It generates these new sets of chains by attempting to swap random elements of the chains swaps times, only doing so if the attempted swap preserves the number of transitions between the two unique elements of the chains. multiple_binary_test then saves the chain generated by this process, then preforms a number of swaps equivalent to the value of swaps on that chain again, then recording the result in a new entry in a list of data. multiple_binary_test does this n times to generate the n new sets of chains. These new sets of chains are effectively independent of the original one.

Once multiple_binary_test has generated new data, it preforms various tests of that data. included in the function are the likelihood ratio test, the Pearson's chi square test, and a run test for a run of length specified by the argument run.

Value

multiple_binary_test returns a list of class "multiple_binary_test" with the following elements:

data, a list of matrices, the first of which is binary_chains, and the rest of which are the generated data.

test_stats_lrt, vector of likelihood ratio test statistics for each element of list data.

test_stats_chi_sq, a vector of Pearson's chi square test statistics for each element of list data.

test_stats_run, a vector of run test statistics for a run of length run for each element of list data.

p_value_lrt, the p-value of binary_chain, calculated exactly from the distribution of test_stats_lrt.

p_value_chi_sq, the p-value of binary_chain, calculated exactly from the distribution of test_stats_chi_sq.

p_value_run, the p-value of binary_chain, calculated exactly from the distribution of test_stats_run.

call, the function call.

bins, the number of bins specified in the function call.

run, the length of run specified in the function call.

Examples

1
2
3
data <- as.matrix(maRkov::snoqualmie)
foo <- multiple_binary_test(binary_chains = data, swaps = 10000, n = 10000,
                            run = 3, bins = 50)

cwcartmell/maRkov documentation built on May 12, 2017, 2:25 p.m.