single_binary_test: Perform goodness-of-fit tests on a single binary chain.

Description Usage Arguments Details Value Examples

Description

single_binary_test is used to preform goodness-of-fit tests on single binary chains of data to see if a Markov chain model is appropriate.

Usage

1
2
single_binary_test(binary_chain, swaps = 1000, n = 1000, run = 4,
  tiles = 30, bins = 30, success = NULL)

Arguments

binary_chain

A one dimensional vector with two unique values.

swaps

A positive nonzero integer value for the number of swaps to be attempted on the chain. Larger numbers will tend to yield "more independent" data. Generally, the number of swaps should be far greater than the length of binary_chain.

n

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

run

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

tiles

The number of chains to be represented in the tile plot when one plots objects generated by single_binary_test

bins

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

success

Denotes the data entry to be counted for run statistics.

Details

single_binary_test works by taking the supplied binary_chain parameter, counting the transitions between different elements, and then generating n new chains with the same number of transitions. It generates these new chains by attempting to swap random elements of the chain swaps times, only doing so if the attempted swap preserves the number of transitions between the two unique elements of the chain. single_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 matrix of new data. single_binary_test does this n times to generate the n new chains. These new chains are effectively independent of the original one.

Once single_binary_test has generated new data, it preforms various tests on 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

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

data, a matrix of data with binary_chain in the first row, and the generated n rows of data in the following columns.

test_stats_lrt, a vector of likelihood ratio test statistics for each row of data in data.

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

test_stats_run, a vector of run test statistics for a run of length run for each row of data in 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.

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

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

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

Examples

1
2
3
data <- c(1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,1,1,1,1,1,0,0,0)
foo <- single_binary_test(binary_chain = data, swaps = 10000, n = 10000,
run = 4, tiles = 32, bins = 100, success = 1)

cwcartmell/maRkov documentation built on May 14, 2019, 1:37 p.m.