# Pattern statistics on Markov chains and sensitivity to parameter estimation

## Abstract

### Background:

In order to compute pattern statistics in computational biology a Markov model is commonly used to take into account the sequence composition. Usually its parameter must be estimated. The aim of this paper is to determine how sensitive these statistics are to parameter estimation, and what are the consequences of this variability on pattern studies (finding the most over-represented words in a genome, the most significant common words to a set of sequences,...).

### Results:

In the particular case where pattern statistics (overlap counting only) computed through binomial approximations we use the delta-method to give an explicit expression of σ, the standard deviation of a pattern statistic. This result is validated using simulations and a simple pattern study is also considered.

### Conclusion:

We establish that the use of high order Markov model could easily lead to major mistakes due to the high sensitivity of pattern statistics to parameter estimation.

## Background

In order to study pattern occurrences in biological sequences, simple frequencies are not relevant in most cases because of pattern overlapping structure as well as composition bias in the sequences. A common workaround consists to compute the significance of an observation assuming the sequence X = X1 ... X over the finite alphabet $\mathcal{A}$. (size k) is generated according to an order m ≥ 1 homogeneous, stationary and ergodic Markov model. Let π (size km+1) defined by

π(w, a) = (Xm+1= a|X1...X m = w) (w, a) $\mathcal{A}$m× $\mathcal{A}$     (1)

be the parameter of this Markov model, Π its transition matrix (note that we have Π = π only if m = 1) and μ its stationary distribution (defined by μ × Π = μ).

We then introduce the pattern statistic defined by

where N is the random number of overlapping occurrences (i. e. X = aababaaba contains three overlapping occurrences of aba but only two non-overlapping ones) of a given fixed pattern on the random sequence X and Nobs is an observation.

When π is known (and hence μ), several statistical methods are available to compute S: exact computations , Gaussian [5, 6], binomial [7, 8], compound Poisson  or large deviations approximations . But in general, the parameter π is not available and must be estimated. Let us denote by N0 (resp. N1) the (overlap) frequencies of all words of size m (resp. m + 1) in the sequence Y = Y1 ... Y n , then the Maximum-Likelihood Estimator (MLE) of π is given by

$\begin{array}{cc}\stackrel{^}{\pi }\left(w,a\right)=\frac{{N}_{1}\left(wa\right)}{{\sum }_{b\in \mathcal{A}}{N}_{1}\left(wb\right)}& \forall \left(w,a\right)\in {\mathcal{A}}^{m}×\mathcal{A}\end{array}\left(3\right)$

and the MLE of μ (as a function of π) is therefore defined by $\stackrel{^}{\mu }$ × $\stackrel{^}{\Pi }$ = $\stackrel{^}{\mu }$ where $\stackrel{^}{\Pi }$ is the transition matrix associated to $\stackrel{^}{\pi }$

We introduce now the following estimators

$\begin{array}{cccc}{\mu }_{N}\left(w\right)=\frac{{N}_{0}\left(w\right)}{n-m+1}& and& {\pi }_{N}\left(w,a\right)=\frac{{N}_{1}\left(wa\right)}{{N}_{0}\left(w\right)}& \forall \left(w,a\right)\in {\mathcal{A}}^{m}×\end{array}\mathcal{A}\left(4\right)$

which are known to be asymptotically equivalent with the MLE when n is large.

The quality of parameter estimation depends both on the number of parameters to estimate (km+1for an order m Markov model) and of the length (n) of the homogeneous sequence used for their estimation. When the same sequence (or set of sequences) is used both for observed frequencies and parameter estimation, m should not be greater than h – 2 for a pattern of length h (as else, the observed frequency of the pattern will be included in the model). As literature often suggests to use the highest possible order, it is hence common to consider m = 6 or more (for a DNA pattern of size h ≥ 8). Moreover, because of the homogeneity assumption of the model, the considered genomes have often to be segmented first. As a result, the sequences length used for parameter estimations are often dramatically reduced by such segmentation (e. g. n = 105 to n = 106 at the very best for DNA sequences). It is hence quite common to encounter high order Markov models estimated on rather short sequences which could result in high sensitivity to parameter estimation.

Considering that Y is generated through a Markov model of parameter π, the main goal of this paper is to study the distribution of S N , the statistic S computed using the estimators μ N and π N , and the consequences of its variability in projects using pattern statistics. We first present in details how the delta-method can be used to get a Gaussian approximation for the distribution of S N (using a binomial approximation to compute the pattern statistics). Then these approximations are validated through simulations and, at last, we consider a classical pattern study (finding the most over-represented patterns of a given size) and we evaluate the detrimental effect of parameter estimations both in terms of true positive rate and rank accordance.

## Materials and methods

### Distribution of N = (N0, N1)

As the estimators defined in (4) are expressed as functions of N0 and N1 we first study their distribution. Using a Gaussian approximation, we have where, for i, j {0, 1}, E i ${ℝ}^{{d}_{i}}$, and C i,j ${ℝ}^{{d}_{i}}$ × ${ℝ}^{{d}_{j}}$ with d i = km+i. One can note that C0,0 and C1,1 are symmetric, and t(C1,0) = C0,1 (where tis the matrix transpose operator).

In the stationary case, exact expression of E and C can be computed according to .

Expectation is simply given w $\mathcal{A}$mby

E0(w) = (n - m + 1) μ(w)     E1 (wa) = (n - m) μ(w)Π(w, a) (w, a) $\mathcal{A}$m× $\mathcal{A}$     (6)

In order to give more fluidity to this paper, the expression of the covariance matrix C have been moved in appendix A. Let us remark, before going forward that substituting N by E in (4) immediately gives

$\begin{array}{ccc}{\mu }_{E}=\mu & \text{and}& {\pi }_{E}=\left(1-\frac{1}{n-m+1}\right)\pi \left(7\right)\end{array}$

### Delta method

Let us start with a simple case. We consider a single pattern which is over-represented (seen more than expected) so we have

$\begin{array}{lll}{S}_{N}=-{\mathrm{log}}_{10}{F}^{+}\left(N\right)\hfill & \text{with}\hfill & {F}^{+}\left(N\right)\triangleq {ℙ}_{{\mu }_{N},{\pi }_{N}}\left(N\ge {N}_{\text{obs}}\right)\hfill \end{array}\left(8\right)$

where the function F+ also depends on the sequence length ℓ and the considered pattern.

If F+ is differentiate, the delta-method (a simple first order Taylor expansion around N = E, see ) provides the following approximation: and hence, using (7) we have for n large enough. The distribution of $\stackrel{^}{S}$ is therefore approximated by

$L$
(1)

(S N ) $\mathcal{N}$ (S, σ2)     (11)

with In consequence, computing σ requires both to compute C (done in appendix A) and F+ (E).

### Single pattern

The exact expression of F+ is computable through many different methods  but is too much complicated to derive explicitly F+. To overcome this problem, we propose to consider an approximation of F+. As said in introduction, many kind of approximations are available (Gaussian, binomial, compound Poisson or large deviations). In this paper, we have chosen to use a binomial approximation as it provides an expression which is analytically differentiable and is known to be a good heuristic to the problem .

For a single non-degenerate pattern (i.e. a simple word) W = w1 ... w h (w i $\mathcal{A}$) with hm - 1 we first denote by

P(N) = μ N (w1 ... w m ) × π N (w1 ... w m , wm+1) × ... × π N (wh-m... wh-1, w h )     (13)

the probability for W to occur at a given position in the sequence and then we get

${F}^{+}\left(N\right)\simeq ℙ\left(ℬ\left({\ell }_{h},P\left(N\right)\right)\ge {N}_{obs}\right)=\frac{\beta \left(P\left(N\right),{N}_{\text{obs}},{\ell }_{h}-{N}_{obs}+1\right)}{\beta \left({N}_{obs},{\ell }_{h}-{N}_{obs}+1\right)}\left(14\right)$

where $ℬ$ denotes the binomial distribution, with ℓ h = ℓ - h + 1 and where the β functions (complete and incomplete) and their relation to the binomial cumulative distribution function are described in appendix B.

Note that if we consider non-overlapping occurrences instead of overlapping ones, we can still use a binomial approximation for the distribution of N, but the expression of P(N) is more complicated as it involves the auto-correlation polynome of the pattern . This point is not developed in this paper.

Replacing μ N and π N by their expression easily gives

$P\left(N\right)=\frac{1}{n-m+1}\prod _{w\in {\mathcal{A}}^{m}}\frac{{\prod }_{a\in \mathcal{A}}{N}_{1}{\left(wa\right)}^{{A}_{1}\left(wa\right)}}{{N}_{0}{\left(w\right)}^{{A}_{0}\left(w\right)}}\left(15\right)$

where A1(wa) counts occurrences of the word wa in W = w1 ... w h and A0 (w) counts occurrences of the word w in w2 ... wh-1. Note that in the particular case where h = m - 1, all A0 (w) are null and we simply get (n - m + l) × P (N) = N1 (W).

Using the derivative properties of the incomplete beta function (see appendix B for more details) we hence get

$\nabla {F}^{+}\left(N\right)\simeq \frac{P{\left(N\right)}^{{N}_{\text{obs}}-1}{\left(1-P\left(N\right)\right)}^{{\ell }_{h}-{N}_{\text{obs}}}}{\beta \left({N}_{\text{obs}},{\ell }_{h}-{N}_{\text{obs}}+1\right)}×\nabla P\left(N\right)\left(16\right)$

so all we need is to compute P(N).

For all (w, a) $\mathcal{A}$m× $\mathcal{A}$ we have

$\frac{\partial P\left(N\right)}{\partial {N}_{0}\left(w\right)}=-\frac{{A}_{0}\left(w\right)}{{N}_{0}\left(w\right)}×P\left(N\right)\left(17\right)$

and

$\frac{\partial P\left(N\right)}{\partial {N}_{1}\left(w\right)}=-\frac{{A}_{1}\left(wa\right)}{{N}_{1}\left(wa\right)}×P\left(N\right)\left(18\right)$

If we denote by

P = μ (w1 ... w m ) × π (w1 ... w m , wm+1) × ... × π (wh-m... wh-1, w h )     (19)

the true probability for W to occur at a given position in the sequence X then we get, using (7) in (13), that

$P\left(E\right)=p×{\left(1-\frac{1}{n-m+1}\right)}^{h-m}\simeq p\left(20\right)$

for n large enough. We hence get

$\nabla {F}^{+}\left(E\right)\simeq \frac{{p}^{{N}_{\text{obs}}}{\left(1-p\right)}^{{\ell }_{h}-{N}_{\text{obs}}}}{\beta \left({N}_{\text{obs}},{\ell }_{h}-{N}_{\text{obs}}+1\right)}×G\left(21\right)$

where tG = [tG0 tG1] is defined by

$\begin{array}{lll}{G}_{0}\left(w\right)=-\frac{{A}_{0}\left(w\right)}{{E}_{0}\left(w\right)}\hfill & \text{and}\hfill & {G}_{1}\left(wa\right)=-\frac{{A}_{1}\left(wa\right)}{{E}_{1}\left(wa\right)}\hfill \end{array}\left(22\right)$

Using equation we finally get where and then, a computation of σ is possible by plug-in. Without considering the computation of E and C, the complexity of this approach is O(h) (where h is the size of the pattern).

When a degenerate pattern (finite set of words) is considered instead of a single word, it is easy to adapt this method by summing the contribution p of each word belonging to the pattern. This point is left to the reader.

### Under-represented pattern

In the case of an under-represented pattern we have Using a binomial approximation we get and, by the same method than in the over-represented case we finally have  ### Two distinct patterns

We consider now two patterns V and W instead of one and want to study the joint distribution of S N (V) and S N (W) their corresponding pattern statistics.

With a similar argument as in section "delta method", it is easy to show that where σ V (resp. σ W ) is the standard deviation σ for the pattern V (resp. W) and where where And after using results of sections "single pattern" and "under-represented pattern" we finally get where ${Q}_{V}^{\epsilon }$ (resp. W) and G V (resp. W) are the constant Q (Q+ and Q-) and the vector G for the pattern V (resp. W).

### Simulations

It is also possible to study the empirical distribution of a S N (for one or more patterns) through simulations.

In order to do so, we first draw M independent sequences Yj= ${Y}_{1}^{j}$ ... ${Y}_{n}^{j}$ using an order m stationary Markov model of parameters π. Complexity of this step is O(M × n).

For each j we get the frequencies Nj= (${N}_{0}^{j}$,${N}_{1}^{j}$) (with complexity O(n) for each sequence) of the words of size m and m + 1 in the sequence Yjand use it to compute Sj= ${S}_{{N}^{j}}$ (exact value or approximation). Complexity here depends on the statistical method used to compute Sj(e.g. O(h) using a binomial approximation).

We now have a M – sample S1, ..., SMof S N from which we can easily estimate σ and thus, valid or invalid the approximation through the delta-method.

When used with large value of n (e.g. several millions or more), the complexity of this approach is slowed by the drawn of the sequences Y j . It is therefore possible to improve the method by simulating directly the frequencies N through (5). As this approximation has a very small impact on the distribution of S N (data not shown) it may dramatically speed-up the computations when considering large n or M. It is nevertheless important to point out that drawing a Gaussian vector size L requires to precompute the Choleski decomposition of its covariance matrix which could be a limiting factor when considering large L.

## Results and discussion

### Validation

#### Simple case

Let us start with a simple case: a binary alphabet $\mathcal{A}$ = {a, b} (k = 2) with an order m = 1 Markov model

$\pi =\left(\begin{array}{cc}0.3& 0.7\\ 0.6& 0.4\end{array}\right)\left(33\right)$

which stationary distribution is μ = (6/13,7/13) and we work on a sequence of length n = 10 000.

The first thing to do is to compute E and C (see appendix A for details).

Now, we consider the pattern W = ababa occurring Nobs = 1221 times in a sequence of length ℓ = n = 10 000. We have

p = μ(a) Π (a,b)2 Π (b,a)2 = 8.142 × 10-2     (34)

so $\mathbb{E}$[N(ababa)] = (ℓ - 4)p = 813.8 0.66 × Nobs and hence the pattern is over-represented. Its statistic (using binomial approximation) is

$S\simeq -{\mathrm{log}}_{10}ℙ\left(ℬ\left(\ell -5+1,p\right)\ge {N}_{obs}\right)=43.74285\left(35\right)$

We have

${Q}^{+}=\frac{{p}^{{N}_{\text{obs}}-1}{\left(1-p\right)}^{\ell -4-{N}_{\text{obs}}}}{\mathrm{ln}\left(10\right)\beta \left(p,{N}_{\text{obs}},\ell -3-{N}_{\text{obs}}\right)}=193.3258\left(36\right)$

and and Finally, we get As our pattern statistics is the decimal logarithm of the p-value, σ = 6 means that the ratio of the estimated p-value over the true one could easily range from 10-12 (10-2 × σ) to 1012 (102 × σ) which is huge.

We can see on fig. 1 the empirical distribution of S N compared to the theoretical distribution. Even if the two distributions are closely related, an adjustment test (Kolmogorov-Smirnov) shows that they are different.

In the fig. 2 we compare σ to its estimator $\stackrel{^}{\sigma }$ for several values of Nobs. We can see that our theoretical values of σ fits very well to the empirical ones.

The equation gives an explicit expression of σ as a product of two terms. Once the pattern and the true parameter π are fixed, the first term (Q) depends only on ℓ and Nobs while the second one only depends on the length n of the sequence used for the parameter estimation (see appendix C for an explicit expression of σ in the particular case of an order 0 Markov model).

To study the variations of σ(n) as a function of n we therefore need to study G(n) and C(n). Using equations and we get that

$\begin{array}{ccc}E\left(n\right)=O\left(n\right)& \text{and}& G\left(n\right)=O\left(\frac{1}{n}\right)\end{array}\left(40\right)$

Using equations and in appendix A we also get that C = M + O + tEE with

M(n) = O(n2) and O(n) = O(n)     (41)

so finally

$\sigma \left(n\right)\simeq \stackrel{˜}{\sigma }\left(n\right)={Q}^{+}×\sqrt{A+\frac{B}{n}}\left(42\right)$

for large n, with and We can see on fig. 3 that $\stackrel{˜}{\sigma }$ is not a very good approximation of σ for small n, but, as the approximation is far easier to compute (and trivial to invert) than the true value, this can be useful when we need to compute a minimum length n to obtain a given σ.

We also see on the same figure that σ grows rapidly when n decreases. For example, we get σ 20 for n = 5000 (while equation gives S 264.4).

As we consider here a binary alphabet (k = 2) and a first order Markov model (m = 1) we have only km(k - 1) = 2 parameters to estimate with a sample of size n = 5000 (so we have 2500 sample per parameter). Although this situation seems quite comfortable, the sensitivity to parameter estimation appears in fact to be so large that we could have a factor 1040 between the true p-value and its estimate.

#### Practical case

We have seen with our first example that our approximation works very well in a simple case. Will this hold with more practical cases?

To answer this question, let us consider the following experimental design:

• one pattern: W = acgtacgt;

• two genomes: Escherichia coli K12 (ℓ = n = 4639675) and Mycoplasma genitalium (ℓ = n = 580076);

• five Markov orders: m = 1 to m = 5 (larger m are not considered since the computation of C becomes then intractable).

As the sequence lengths and compositions of the two considered genomes differ a lot, we have to take a different value of Nobs for each organism: Nobs = 30 for M. genitalium and Nobs = 150 for E. coli. Proceeding as indicated in section "simulations", we use the algorithm 1 for each experiment.

Algorithm 1 simulations for one experiment in the practical case

1: estimate the order m parameter π (and μ) from the original sequence. Although these parameters are estimated, they are considered as the true parameters;

2: compute S = -log10 (NNobs);

3: compute σ using approximation (23)

4: for j = 1 ... 1 000 do

5: draw a random sequence Y = Y1 ... Y n according to and order m stationary Markov model of parameter π;

6: compute N the frequency vector of all size m and size m + 1 words in Y;

7: compute Sj= S N = -log10 (NNobs);

8: end for

9: compute $\stackrel{^}{S}$ (resp. $\stackrel{^}{\sigma }$) the mean (resp. standard deviation) of the sample S1,..., Sj.

We can see on table 1 the results for E. coli. For each Markov model considered, our approximation of σ is very close to the empiric ones and, as with figure 1, the Gaussian distribution fit well to the empiric one (data not shown). Table 2 shows the same behaviour with M. genitalium except for m = 5 where $\stackrel{^}{\sigma }$ differs slightly more than in the other cases from its theoretical value. To understand this phenomenon, let us first recall the expression of P(N) for m = 5 using equation :

$P\left(N\right)=\frac{{N}_{1}\left(\text{agctac}\right)×{N}_{1}\left(\text{gctacg}\right)×{N}_{1}\left(\text{ctacgt}\right)}{\left(\ell -m+1\right)×{N}_{0}\left(\text{gctac}\right)×{N}_{0}\left(\text{ctacg}\right)}$

and as (N1 (agctac) = 0) 2.26 × 10-6, (N1 (gctacg) = 0) 1.35 × 10-1 and (N1 (ctacgt) = 0) 1.24 × 10-4 we will have P(N) = 0 roughly 14% of the time. This happened 123 times in our sample of size 1 000, each time preventing to compute S N . The sample is hence biased and $\stackrel{^}{S}$ and $\stackrel{^}{\sigma }$ are therefore not accurate.

What happen now if we use another statistical method to compute the pattern statistics. As the binomial approximation is supposed to be close to the exact solution, we expect the standard deviation obtained with other statistical methods to remain close to σ. In table 3, we compare the empirical results using binomial approximations (like above) but also compound Poisson or large deviations approximations. Both empirical means and standard deviations are close to the theoretical ones thus validating the method.

### Choice of a Markov model order

Through the computation of σ we can measure the sensitivity of pattern statistics to parameter estimations. A very natural question is then, how this variability could affect a pattern statistic study, and, as this variability grows with the Markov model order, how to choose this parameter.

We propose here to consider the case of a very simple pattern study: we want to find the 100 most over-represented octamers (DNA words of size 8) in a given genome. Assuming the true parameter π (and hence μ) is known, we can compute REF = {W1,..., W100}, the list of these words (ordered by decreasing statistics, so that the most over-represented one is the first one).

For each estimates $\stackrel{^}{\mu }$ and $\stackrel{^}{\pi }$, we can compute $\stackrel{_}{\text{REF}}$ the 100 most over-represented octamers in the genome using the statistic $\stackrel{^}{S}$ and compare it to the truth. In order to do so, we first compute the true positive rate (TP rate) defined by the rate of common words in $\stackrel{_}{\text{REF}}$ and REF, and the rank accordance rate (RA rate) defined by the Kendall's tau [, Chapter 13] between S and $\stackrel{^}{S}$ ranks of {$\stackrel{_}{\text{REF}}$ REF}. Such statistic is in the range [-1,1] and has the value 1 for the complete rank accordance and the value -1 for the complete rank discordance.

As in the section "practical case", we consider two genomes: Escherichia coli K12 (ℓ = n = 4639675) and Mycoplasma genitalium (ℓ = n = 580076). For each Markov model order m from 1 to 6, we estimate π on the sequence (by maximum of likelihood), compute the REF list and then draw a sample of $\stackrel{_}{\text{REF}}$ from which we get estimates for the expectation of TP and RA rates.

Results are given in tables 4 and 5. We can see that, surprisingly, the TP rate could be very low even for long genome such as E. coli when high order Markov model (m = 6) are used. Of course, these rates are even worse on M. genitalium whose genome is ten times smaller than the first one. It is also clear that the RA rate is more affected by the variability induced by parameter estimation than the TP rate.

Based on these results, we conclude that our pattern study requires a sample size per free parameter of at least a few thousands if we want reliable results. In our examples this has for consequence that the Markov order should not be greater than 4 (or 5 at the very most) for E. coli and 3 (or 4 at the very most) on M. genitalium without resulting in important errors.

## Conclusion

The delta-method allows us to approximate the distribution of $\stackrel{^}{S}$ by a Gaussian distribution. This first requires to compute the expectation and covariance matrix of frequencies and then to study the derivative of a function which is specific of the method used to compute the pattern statistics. In the case of the binomial approximations, we have found an explicit expression of σ the standard deviation of $\stackrel{^}{S}$.

It is clear that our approximation of σ using the delta-method relies one two major assumptions: 1) the distribution of N is Gaussian; 2) F+ is regular enough (e.g. not too steep) around E. When m grows, E closes to the boundary of the definition range of F+ hence degrading assumption 2. Moreover, it is well known that Gaussian approximations for word frequencies become weaker when the expected numbers of their occurrences become smaller, thus degrading assumption 1. It is therefore obvious that our approximation of σ will get less and less reliable as m grows.

However, the approximation of σ has been validated through simulations and appears to be very reliable (even for m = 5 or 6). As pattern statistics computed through binomial approximations are close to the exact statistics , the value of σ should not differ a lot when another statistical method is used. We have compared our approximations to the empiric distribution obtained using compound Poisson and large deviations approximations and, as expected, our approximations remains quite reliable even for these statistical methods.

The variability due to parameter estimation is of course related to the Markov model order m and to the size k of the alphabet (as we have km+1parameters for this model) and to the length n of the sequence used for this estimation. For example, considering an order m = 6 model with n = 4639675 (Escherichia coli K12 complete genome) requires to estimate 3 × 46 = 4096 free parameters which results roughly in 400 observation per free parameter. Although this situation seems quite comfortable, we have seen with our simulations that it leads an unacceptable variability for pattern statistics.

As literature often advices to use the highest possible Markov order for a given pattern problem (which means m = h - 2 for pattern of size h) it is easy to understand that such a practice could have very detrimental effects on the computed statistics unless huge data are available for estimation purpose. Even if we consider the more reasonable attitude to choose m using the classical framework of model selection (e.g. using the Akaike Information Criterion – AIC –) we get m = 5 for Mycoplasma genitalium and m = 6 for Escherichia coli K12 hence resulting in both cases in the same catastrophic results in terms of false positive and even worse ones in terms of ranking.

Moreover, we assumed here that our model was homogeneous all along the considered sequences. This is obviously completely false when complete genomes are considered. So it is more likely that the sample size n would be far smaller than a million on classical pattern studies (even of human genomes for example). As a result, the variability we pointed out in this paper will have a considerable detrimental effect on most studies unless the Markov order is carefully set.

In order to do so, we advice to compute our approximation of σ each time a pattern statistic is produced and then to evaluate, either by simulation (like in this paper) or by a theoretical work the impact of this variability on the considered study.

## Appendix A

We give here the expression of the covariance matrix C introduced in section "distribution of N = (N0, N1)". The sequence Y (of length n) is generated by an homogeneous, stationary and ergodic order m Markov model of parameter π and stationary distribution μ. We want to compute the covariance of the vector N of random frequencies of size m and m + 1 words.

For any word w (of size h w ), we introduce the following notation for h w in

${I}_{i}\left(w\right)={\mathbb{I}}_{\left\{wendinpositioni\right\}}={\mathbb{I}}_{\left\{{Y}_{i-{h}_{w}+1}^{i}=w\right\}}\left(45\right)$

where ${Y}_{i}^{j}$ = Y i ... Y j for all ij. If h w m, we denote by

$p\left(w\right)=\mu \left({w}_{1}^{m}\right)\Pi \left({w}_{1}^{m},{w}_{m+1}\right)...\Pi \left({w}_{{h}_{w}-m}^{h-1},{w}_{h}\right)\left(46\right)$

the probability to see one occurrence of w at a given position in the sequence. At last, if we consider another word v (of size h v = m) and if h w = m, we denote by

${\Pi }_{\delta }\left(v,w\right)=\sum _{x\in {\mathcal{A}}^{\delta }}p\left(vxw\right)\left(47\right)$

the probability to see occurrences of v and w separated by a gap of length δ.

For any words v an w (to simplify, we suppose that h v h w ) then, for all δ $ℤ$ and

max(h v , h w - δ) ≤ i ≤ min(n, n - δ) we have

$\mathbb{E}$

[I i (v) Ii(w)] = Dδ (v, w)     (48)

which do not depend on i.

It is therefore easy to show that

$\begin{array}{cc}\mathbb{E}\left[N\left(v\right)N\left(w\right)\right]=\sum _{i={h}_{v}}^{n}\sum _{\delta ={h}_{w}-i}^{n-i}{D}_{\delta }\left(v,w\right)& \left(49\right)\\ =\sum _{\delta ={h}_{w}-n}^{n-{h}_{v}}{N}_{\delta }{D}_{\delta }\left(v,w\right)& \left(50\right)\\ =M\left(v,w\right)+O\left(v,m\right)& \left(51\right)\end{array}$

where the main part (2n - h v - h w + 2 terms) is given by

$M\left(v,w\right)=\sum _{\delta ={h}_{v}}^{n-{h}_{w}}{N}_{-\delta }{D}_{-\delta }\left(v,w\right)+\sum _{\delta ={h}_{w}}^{n-{h}_{v}}{N}_{\delta }{D}_{\delta }\left(v,w\right)\left(52\right)$

and the overlapping part (h v + h w - 1 terms) by and with

${N}_{\delta }=\left\{\begin{array}{ll}n-{h}_{w}+1+\delta \hfill & \delta \in \left[{h}_{w}-n,{h}_{w}-{h}_{v}\left[\hfill \\ n-{h}_{v}+1\hfill & \delta \in \left[{h}_{w}-{h}_{v},0\right]\hfill \\ n-{h}_{v}+1-\delta \hfill & \delta \in \right]0,n-{h}_{v}\right]\hfill \end{array}\left(54\right)$

As we have

C(v, w) = M (v, w) + O (v, w) - E (v) E (w)     (55)

the problem is hence to compute M and O for all pairs of size m or m + 1 words. In order to simplify, we will just treat here the case of a pair of size m words (other cases can be derived from this special case).

For the main part we obtain

$\begin{array}{c}M\left(v,w\right)=\sum _{\delta =m}^{n-m}{N}_{-\delta }\mu \left(w\right){\Pi }_{\delta -m+1}\left(w,v\right)\\ +\sum _{\delta =m}^{n-m}{N}_{\delta }\mu \left(v\right){\Pi }_{\delta -m+1}\left(v,w\right)\end{array}\left(56\right)$

(2n - 2m + 2 terms). As P k (v, w) quickly converges toward μ(w) when k grows (convergence speed is given by λkwhere λ is the magnitude of the second eigenvalue of the transition matrix Π). So there exists a rank rm such as

$\begin{array}{l}M\left(v,w\right)\simeq \mu \left(v\right)\mu \left(w\right)\sum _{\delta =r}^{n-m}\left({N}_{-\delta }+{N}_{\delta }\right)\\ +\sum _{\delta =m}^{r-1}{N}_{-\delta }\mu \left(w\right){\Pi }_{\delta -m+1}\left(w,v\right)\\ +\sum _{\delta =m}^{r-1}{N}_{\delta }\mu \left(v\right){\Pi }_{\delta -m+1}\left(v,w\right)\left(57\right)\end{array}$

which has only 2r - 2m + 1 terms.

And for the overlapping part we get

$\begin{array}{l}O\left(v,w\right)={N}_{0}×\mu \left(v\right)×{\mathbb{I}}_{\left\{v=w\right\}}\\ +\sum _{\delta =1}^{m-1}{N}_{-\delta }×p\left(w{v}_{m-\delta +1}^{m}\right)×{\mathbb{I}}_{\left\{{v}_{1}^{m-\delta }={w}_{1+\delta }^{m}\right\}}\\ +\sum _{\delta =1}^{m-1}{N}_{\delta }×p\left(v{w}_{m-\delta +1}^{m}\right)×{\mathbb{I}}_{\left\{{v}_{1+\delta }^{m}={w}_{1}^{m-\delta }\right\}}\left(58\right)\end{array}$

which has 2m + 1 terms.

So the overall complexity for the computation of one term of C is hence O(r) where the value of r is directly connected to the magnitude λ of the second eigenvalue of the transition matrix.

In the particular case of an order one Markov model (m = 1), we give here the complete expressions of M and O.

For all a, b, c, d $\mathcal{A}$, we have

$\begin{array}{l}M\left(a,b\right)\simeq \left(n-r+1\right)\left(n-r\right)\mu \left(a\right)\mu \left(b\right)\\ +\sum _{\delta =1}^{r-1}\left(n-\delta \right)\left(\mu \left(b\right){\Pi }^{\delta }\left(b,a\right)+\mu \left(a\right){\Pi }^{\delta }\left(a,b\right)\right)\left(59\right)\end{array}$

O (a, b) = (a) $\mathbb{I}${a = b}    (60)

$\begin{array}{l}\frac{M\left(ab,c\right)}{\Pi \left(a,b\right)}\simeq \left(n-r\right)\left(n-r-1\right)\mu \left(a\right)\mu \left(c\right)\\ +\sum _{\delta =1}^{r-1}\left(n-\delta -1\right)\left(\mu \left(c\right){\Pi }^{\delta }\left(c,a\right)+\mu \left(a\right){\Pi }^{\delta }\left(b,c\right)\right)\left(61\right)\end{array}$

$\frac{O\left(ab,c\right)}{\Pi \left(a,b\right)}=\left(n-1\right)\mu \left(a\right)\left({\mathbb{I}}_{\left\{a=c\right\}}+{\mathbb{I}}_{\left\{b=c\right\}}\right)\left(62\right)$

$\begin{array}{l}\frac{M\left(ab,cd\right)}{\Pi \left(a,b\right)\Pi \left(c,d\right)}\simeq \left(n-r-1\right)\left(n-r-2\right)\mu \left(a\right)\mu \left(c\right)\\ +\sum _{\delta =1}^{r-1}\left(n-\delta -2\right)\left(\mu \left(c\right){\Pi }^{\delta }\left(d,a\right)+\mu \left(a\right){\Pi }^{\delta }\left(b,c\right)\right)\left(63\right)\end{array}$

$\begin{array}{l}\frac{O\left(ab,cd\right)}{\Pi \left(a,b\right)}=\left(n-1\right)\mu \left(a\right){\mathbb{I}}_{\left\{ab=cd\right\}}\\ +\left(n-2\right)\Pi \left(c,d\right)\left(\mu \left(c\right){\mathbb{I}}_{\left\{a=d\right\}}+\mu \left(a\right){\mathbb{I}}_{\left\{b=c\right\}}\right)\left(64\right)\end{array}$

With the example given in section "validation" we get for the expectation

${E}_{0}^{t}$
(3)

= [4615.4 5384.6]     (65)

and

${E}_{1}^{t}$
(4)

= [1384.5 3230.4 3230.4 2153.6]     (66)

The magnitude of the second eigenvalue of Π is λ = 0.3, then rank r = 19 give a relative error < 10 -10 and we get for the covariance  and

${C}_{1,1}=\left[\begin{array}{cccc}1536.8& -390.0& -390.0& -756.9\\ -390.0& 581.2& 581.0& -772.2\\ -390.0& 581.0& 581.2& -772.2\\ -756.9& -772.2& -772.2& 2301.4\end{array}\right]\left(69\right)$

## Appendix B

The beta function is defined by for all a, b > 0. The incomplete beta function for all x [0,1] is then defined by

$\beta \left(x,a,b\right)={\int }_{0}^{x}{t}^{a-1}{\left(1-t\right)}^{b-1}dt\left(71\right)$

and

$\begin{array}{cc}{\beta }^{-}\left(x,a,b\right)=\beta \left(a,b\right)-\beta \left(x,a,b\right)& \left(72\right)\\ ={\int }_{x}^{1}{t}^{a-1}{\left(1-t\right)}^{b-1}dt& \left(73\right)\end{array}$

Using a continued fraction representation, these functions can be quickly numerically evaluated in O($\sqrt{\mathrm{max}\left(a,b\right)}$) in the worst case [15, Chapter 6].

A great interest of this function is that it is connected to the cumulative distribution function of a binomial distribution by the following relation:

$ℙ\left(ℬ\left(n,p\right)\ge k\right)=\frac{\beta \left(p,k,n-k+1\right)}{\beta \left(k,n-k+1\right)}\left(74\right)$

with (n, k) * × , 0 ≤ kn and p [0,1].

Finally, let us remark that the incomplete beta function is differentiable in x and that

$\frac{\partial \beta \left(x,a,b\right)}{\partial x}={x}^{a-1}{\left(1-x\right)}^{b-1}\left(75\right)$

## Appendix C

We give here the complete expression of σ for a single pattern in the special case of an order m = 0 homogeneous Markov model of parameter μ.

The MLE of μ is given by

${\mu }_{N}=\frac{{N}_{1}}{n}\left(76\right)$

where N1 is the frequency of all letters.

A Gaussian approximation gives

$L$
(5)

(N1) $\mathcal{N}$ (E1, C1,1)     (77)

with E1 = and, for all a, b $\mathcal{A}$,

C1,1 (a, b) = (a) $\mathbb{I}$a = b- (a) × (b)     (78)

We have also

$P\left(N\right)=\frac{1}{{n}^{h}}\prod _{a\in \mathcal{A}}{N}_{1}{\left(a\right)}^{{A}_{1}\left(a\right)}\left(79\right)$

which implies for all a $\mathcal{A}$ that So finally we get where Q is either defined by equation if the pattern is over-represented or by equation if under-represented.

## References

1. Atteson W: Calculating the exact probability of language-like patterns in biomolecular sequences. Pro 6th Int Conf on Intelligent Systems for Molecular Biology. 1998, 17-24.

2. Régnier M, Szpankowski W: On pattern frequency occurrences in a Markovian sequence. Algorithmica. 1998, 22 (4): 631-649. 10.1007/PL00009244.

3. Robin S, Daudin JJ: Exact distribution of word occurrences in a random sequence of letters. J App Prob. 1999, 36: 179-193. 10.1239/jap/1032374240.

4. Nuel G: Effective p-value computations using Finite Markov Chain Imbedding (FMCI): application to local score and to pattern statistics. Algorithms Mol Biol. 2006, 1 (1): 5-

5. Kleffe J, Borodovski M: First and second moment of counts of words in random text generated by Markov chains. Comp Applic Biosci. 1992, 8: 443-441.

6. Prum B, Rodolphe F, de Turckheim E: Finding words with unexpected frequencies in DNA sequences. J R Statist Soc B. 1995, 11: 190-192.

7. van Helden J, André B, Collado-Vides J: Extracting Regulatory Sites from the Upstream Region of Yeast Genes by Computational Analysis of Oligonucleotide Frequencies. J Mol Biol. 1998, 281: 827-842.

8. Nuel G: S-SPatt: Simple Statististics for Patterns on Markov chains. Bioinformatics. 2005, 21 (13): 3051-3052.

9. Chrysaphinou O, Papastavridis S: A limit theorem on the number of overlapping appearances of a pattern in a sequence of independent trials. Proba Theory Relat Fields. 1988, 79 (1): 129-143. 10.1007/BF00319109.

10. Arratia R, Goldstein L, Gordon L: Poisson approximation and the Chen-Stein method. Stat Sci. 1990, 5 (4): 403-434.

11. Schbath S: Compound Poisson approximation of word counts in DNA sequences. ESAIM Probab Stat. 1995, 1: 1-16. 10.1051/ps:1997100.

12. Nuel G: LD-SPatt: Large Deviations Statistics for Patterns on Markov Chains. J Comput Biol. 2004, 11 (6): 1023-1033.

13. Oehlert GW: A note on the delta method. American Statistician. 1992, 46: 27-29. 10.2307/2684406.

14. Reinert G, Schbath S, Waterman M: Chapter 6: Statistics on words with applications to biological sequences. Applied Combinatorics on Words. 2005, Cambridge Universtity Press

15. Press WH, Teukolsky SA, Vetterling WT, Flannery BP: Numerical Recipes in C. 1988, Cambridge Universtity Press, 2

## Author information

Authors

### Corresponding author

Correspondence to Grégory Nuel.

### Competing interests

The author declares that he has no competing interests.

## Authors’ original submitted files for images

Below are the links to the authors’ original submitted files for images.

## Rights and permissions

Reprints and Permissions

Nuel, G. Pattern statistics on Markov chains and sensitivity to parameter estimation. Algorithms Mol Biol 1, 17 (2006). https://doi.org/10.1186/1748-7188-1-17

• Accepted:

• Published:

• DOI: https://doi.org/10.1186/1748-7188-1-17

### Keywords

• Markov Model
• Gaussian Approximation
• Pattern Statistic
• Pattern Versus
• Mycoplasma Genitalium 