Перевірте безпам'ятні властивості ланцюга Маркова


17

Я підозрюю, що ряд спостережуваних послідовностей є ланцюгом Маркова ...

X=(ACDDBACBAACADABCADABE)

Однак як я міг перевірити, чи справді вони поважають властивість

P(Xi=xi|Xj=xj)?

Або принаймні довести, що вони маркові за своєю природою? Зауважимо, що це емпірично спостережувані послідовності. Будь-які думки?

EDIT

Додамо лише, що мета - порівняння передбачуваного набору послідовностей із спостережуваними. Тому ми будемо вдячні за коментарі щодо того, як найкраще їх порівняти.

Матриця переходу першого порядку

Mij=xijmxik
де m = A..E

M=(0.18340.30770.07690.14790.28400.46970.11360.00760.25000.15910.18270.24040.22120.19230.16350.23780.18180.06290.33570.18180.24580.17880.11730.17880.2793)

Власні M

E=(1.0000000000.2283000000.1344000000.11360.0430i000000.1136+0.0430i)

Власні вектори M

V=(0.44720.58520.42190.23430.0421i0.2343+0.0421i0.44720.78380.42110.44790.2723i0.4479+0.2723i0.44720.20060.37250.63230.63230.44720.00100.70890.21230.0908i0.2123+0.0908i0.44720.05400.05890.2546+0.3881i0.25460.3881i)

Стовпці містять ряд, а рядки - елементи послідовностей? Яка спостерігається кількість рядків і стовпців?
mpiktas

2
Можливий дублікат: stats.stackexchange.com/questions/29490/…
mpiktas

@mpiktas Рядки представляють незалежні спостережувані послідовності переходів через стани AD. Є кілька 400 послідовностей ... Майте на увазі, що спостерігаються послідовності не всі однакової довжини. Насправді вищезазначена матриця у багатьох випадках доповнюється нулями. Дякую за посилання до речі. Складається враження, що в цій галузі ще є багато можливостей для роботи. Чи є у вас подальші думки? З повагою,
HCAI

1
Лінійна регресія була прикладом для посилення моєї суперечки. Тобто вам, можливо, не потрібно буде тестувати властивість Markov безпосередньо, вам потрібно лише встановити якийсь модем, який передбачає властивість Markov, а потім перевірити правильність моделі.
mpiktas

1
Я смутно пам'ятаю, що десь я бачив тест гіпотези H0 = {Марков} проти Н1 = {Марківський порядок 2}. Це може допомогти.
Стефан Лоран

Відповіді:


5

Цікаво, чи подано нижче дійсне Пірсон χ2 тест на пропорції наступним чином.

  1. Оцініть ймовірність переходу в один крок - ви це зробили.
  2. Отримання модельних ймовірностей двох
    p^U,V=Prob[Xi+2=U|Xi=V]=W{A,B,C,D}Prob[Xi+2=U|Xi+1=W]Prob[Xi+1=W|Xi=V]
  3. Отримаємо двошагові емпіричні ймовірності
    p~U,V=i#Xi=V,Xi+2=Ui#Xi=V
  4. Form Pearson test statistic
    TV=#{Xi=V}U(p^U,Vp~U,V)2p^U,V,T=TA+TB+TC+TD

It is tempting for me to think that each TUχ32, so that the total Tχ122. However, I am not entirely sure of that, and would appreciate your thoughts on this. I am not likewise not co sertain about whether one needs to be paranoid about independence, and would want to split the sample in halves to estimate p^ and p¯.


Don't the probabilities have to have a normal distribution with mean 0 and variance=1 for this to hold? I'd be very interested to know what anyone thinks here.
HCAI

That's what the terms in the sum are supposed to be, asymptotically with large counts.
StasK

6

Markov property might be hard to test directly. But it might be enough to fit a model which assumes Markov property and then test whether the model holds. It may turn out that the fitted model is a good approximation which is useful for you in practice, and you need not to be concerned whether Markov property really holds or not.

The parallel can be drawn to the linear regression. The usual practice is not to test whether linearity holds, but whether linear model is a useful approximation.


This seems like the best option in reality, only I cannot actually compare a linear model to any actual experimental data. Or did you have something else in mind?
HCAI

6

To concretize the suggestion of the previous reply, you first want to estimate the Markov probabilities - assuming it's Markov. See the reply here Estimating Markov Chain Probabilities

You should get a 4 x 4 matrix based on the proportion of transitions from state A to A, A to B, etc. Call this matrix M. M2 should then be the two-step transition matrix: A to A in 2 steps, and so on. You can then test if your observed 2 step transition matrix is similar to M2.

Since you have a lot of data for the number of states, you could estimate M from one half of the data and test M2 using the other half - you are testing observed frequencies against theoretical probabilities of a multinomial. That should give you an idea of how far off you are.

Another possibility would be to see if the basic state proportions: proportion time spent in A, time spent in B, matches the eigenvector of the unit eigenvalue of M. If your series has reached some sort of steady state, the proportion of time in each state should tend to that limit.


There's a bit to take in there.I have calculated the Transition matrix M, but I'm not sure how you'd calculate the M2 empirically. Could you clarify that point? Regards,
HCAI

Also, the latter comment is very interesting, although I don't have the time spent in each state of my observed sequences. I only have the total time for each row. So that may limit the applicability of that method. What are your thoughts?
HCAI

1
Do it the same way you did M, only instead of looking at nearest neighbour transitions, (say, sequences AB), look at pairs that are 2 apart. So, if a subject goes ACB, that counts towards your AB transition count. So does ABB. Create a matrix where item in row i, column j contains the i to j transitions. Then divide by the column totals. You want the columns to sum to 1. Under the Markov property, this matrix should be close to M2
Placidia

RE: equilibrium. I was assuming that the transitions occur at set moments - say every second, you transition from current state to next state. You could take the frequency of A, B, C, and D states near the ends of the sequences, or across sequences to estimate the limit behaviour.
Placidia

In R, if you do eigen(M), you should get the eigenvalues and eigenvectors of M. One eigenvalue will be 1. The corresponding eigenvector should be proportional to your steady state proportions .... if Markov.
Placidia

2

Beyond Markov Property (MP), a further property is Time Homogeneity (TH): Xt can be Markov but with its transition matrix P(t) depending on time t. E.g., it may depend on the weekday at t if observations are daily, and then a dependence Xt on Xt7 conditional on Xt1 may be diagnosed if TH is unduly assumed.

Assuming TH holds, a possible check for MP is testing that Xt is independent from Xt2 conditional on Xt1, as Michael Chernick and StasK suggested. This can be done by using a test for contingency table. We can build the n contingency tables of Xt and Xt2 conditional on {Xt1=xj} for the n possible values xj, and test for independence. This can also be done using Xt with >1 in place of Xt2.

In R, contingency tables or arrays are easily produced thanks to the factor facility and the functions apply, sweep. The idea above can also be exploited graphically. Packages ggplot2 or lattice easily provide conditional plots to compare conditional distributions p(Xt|Xt1=xj,Xt2=xi). For instance setting i as row index and j as column index in trellis should under MP lead to similar distributions within a column.

The chap. 5 of the book The statistical analysis of stochastic processes in time by J.K Lindsey contains other ideas for checking assumptions.

enter image description here

[## simulates a MC with transition matrix in 'trans', starting from 'ini'
simMC <- function(trans, ini = 1, N) {
  X <- rep(NA, N)
  Pcum <- t(apply(trans, 1, cumsum))
  X[1] <- ini 
  for (t in 2:N) {
    U <- runif(1)
    X[t] <- findInterval(U, Pcum[X[t-1], ]) + 1
  }
  X
}
set.seed(1234)
## transition matrix
P <- matrix(c(0.1, 0.1, 0.1, 0.7,
              0.1, 0.1, 0.6, 0.2,
              0.1, 0.3, 0.2, 0.4,
              0.2, 0.2, 0.3, 0.3),
            nrow = 4, ncol = 4, byrow = TRUE)
N <- 2000
X <- simMC(trans = P, ini = 1, N = N)
## it is better to work with factors
X <- as.factor(X)
levels(X) <- LETTERS[1:4]
## table transitions and normalize each row
Phat <- table(X[1:(N-1)], X[2:N])
Phat <- sweep(x = Phat, MARGIN = 1, STATS = apply(Phat, 1, sum), FUN = "/")
## explicit dimnames
dimnames(Phat) <- lapply(list("X(t-1)=" ,"X(t)="),
                         paste, sep = "", levels(as.factor(X)))
## transition 3-fold contingency array
P3 <- table(X[1:(N-2)], X[2:(N-1)], X[3:N])
dimnames(P3) <- lapply(list("X(t-2)=", "X(t-1)=" ,"X(t)="),
                       paste, sep = "", levels(as.factor(X)))
## apply ONE indendence test 
fisher.test(P3[ , 1, ], simulate.p.value = TRUE)
## plot conditional distr.
library(lattice)
X3 <- data.frame(X = X[3:N], lag1X =  X[2:(N-1)], lag2X = X[1:(N-2)])
histogram( ~ X | lag1X + lag2X, data = X3, col = "SteelBlue3")

]


2

I think placida and mpiktas have both given very thoughtful and excellent approaches.

I am answering because I just want to add that one could construct a test to see if P(Xi=x|Xi1=y) is different from P(Xi=x|Xi1=y and Xi2=z).

I would pick values for x, y and z for which there are a large number of cases where the transition from z to y to x occurs. Compute sample estimates for both probabilities. Then test for difference in proportions. The difficult aspect of this is to get the variances of the two estimates under the null hypothesis that say the proportions are equal and the chain is stationary and Markov. In that case under the null hypothesis if we just look at all 2 stage transitions and compare them to their corresponding three stage transitions but only include outcomes where these sets of paired outcomes are separate by at least 2 time points then the sequence of joint outcomes where success is defined as a z to y to x transition and all other two stage transitions to x as failures represent a set of independent Bernoulli trials under the null hypothesis. The same would work for defining all y to x transitions as successes and other one stage transitions to x as failures.

Then the test statistic would be the difference between these estimated proportions. The complication to the standard comparison of the Bernoulli sequences is that they are correlated. But you could do a bootstrap test of binomial proportions in this case.

The other possibility is to construct a two by two table of the two stage and three stage paired outcomes where 0 is failure and 1 is success and the cell frequencies are counts for the pairs (0,0), (0,1), (1,0) and (1,1) where the first component is the two stage outcome and the second is the corresponding three stage outcome. You can then apply McNemar's test to the table.


I see what you are referring to here although I'm finding the first paragraph very terse however. For example "Compute sample estimates[...], then test for difference in proportions". What do you mean by sample estimates? Surely there would be no variance in
P(Xi|Xi1=y)
or am I misunderstanding your train of thought?
HCAI

@user1134241 You mentioned "empirically observed", I assumed that you have data from this stochastic sequence. If you want to estimate P(Xi=x|Xi1=y) for each index i-1 where Xi1=y, count the number of times Xi = x and divide it by the number of times Xi1 = y (regardless of what Xi equals). That is an estimate because the observed finite sequence is just a sample of a portion of a sequence of the stochastic process.
Michael R. Chernick

In your last paragraph, let me ask what constitute a success and exactly? In the case where you say a two-step transition: are you saying iji and a 3-step would be ijki?
HCAI

1

You could bin the data into evenly spaced intervals, then compute the unbiased sample variances of subsets {Xn+1:Xn=x1,Xnk=x2}. By the law of total variance,

Var[E(Xn+1|Xn,Xnk)|Xn]=Var[Xn+1|Xn]E(Var[Xn+1|Xn])

The LHS, if it is almost zero, provides evidence that the transition probabilities do not depend on Xnk, though it is clearly a weaker statement: e.g., let Xn+1N(Xn,Xn1). Taking the expected value of both sides of the above equation, the RHS can be computed from the sample variances (i.e., replacing expected values with averages). If the expected value of the variance is zero then the variance is 0 almost always.

Використовуючи наш веб-сайт, ви визнаєте, що прочитали та зрозуміли наші Політику щодо файлів cookie та Політику конфіденційності.
Licensed under cc by-sa 3.0 with attribution required.