View source: R/independenceTest.R
| assessIndependence | R Documentation |
Tests the null hypothesis that consecutive observations are independent,
P(X_{t+1} = j \mid X_t = i) = P(X_{t+1} = j) for all i, j,
against the alternative of a first-order Markov chain. This is the
classical test of Anderson and Goodman (1957): a chi-squared (or
likelihood-ratio) test of independence applied to the table of observed
one-step transition counts, whose rows are the state at time t and
whose columns are the state at time t + 1.
assessIndependence(sequence, method = c("Pearson", "G"), verbose = TRUE)
sequence |
An empirical sequence of states (at least three observations, without missing values). |
method |
Test statistic: |
verbose |
Should test results be printed? |
Only states actually observed as a departure state (rows) or as an arrival
state (columns) contribute to the degrees of freedom, which are
(r - 1)(c - 1) for r such rows and c such columns. When
r or c is 1 (for instance a constant sequence) the test is not
defined: the degrees of freedom are 0 and the p-value is NA.
The statistic is asymptotic and, as for any chi-squared test on a table of counts, unreliable when many expected counts are small (say below 5). Successive transitions overlap (each observation is the arrival state of one transition and the departure state of the next); this is the standard treatment of the Anderson-Goodman test and is asymptotically valid under the null hypothesis.
An htest object, returned invisibly, with the additional
components observed (transition counts, rows are departure states) and
expected (counts expected under independence).
Anderson, T. W. and Goodman, L. A. (1957). Statistical inference about Markov chains. The Annals of Mathematical Statistics, 28(1), 89–110.
verifyMarkovProperty, assessOrder,
assessStationarity
Other statisticalTests:
verifyMarkovProperty()
# an independent sequence: the test should not reject
set.seed(1)
iid <- sample(c("a", "b", "c"), 500, replace = TRUE)
assessIndependence(iid)
# a strongly dependent (Markov) sequence: the test rejects
mc <- new("markovchain", states = c("a", "b"),
transitionMatrix = matrix(c(0.9, 0.1, 0.2, 0.8), nrow = 2, byrow = TRUE))
dep <- rmarkovchain(500, mc, t0 = "a")
assessIndependence(dep, method = "G")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.