Moving-window cluster detection

Scan Statistic

Find exact probabilities for the maximum number of successes appearing in any moving window of a binary sequence.

What it computes

P(Sₙ(r) < s)

Supported models

Unconditional IID/Markov and conditional variants

Main inputs

Sequence length n, window length r, threshold s, success probabilities

Single-window web-app note

The original desktop instructions sometimes refer to buttons that open separate input windows. In this single-window web version, enter those same values directly in the text boxes or tables on the current tab. The mathematical meaning of the inputs and outputs is unchanged.

Purpose Of This App

This app computes exact scan statistic probabilities for a binary sequence. The sequence contains two possible outcomes:

    0 = failure
    1 = success

The scan statistic looks at every moving window of length r inside a sequence of length n. For each window, it counts how many successes are inside that window. The scan statistic is the largest of these window counts.

Mathematically, let

    S_n(r) = maximum number of successes in any consecutive window of
             length r among the first n trials.

The app usually reports the probability

    P(S_n(r) < s)

where s is the threshold number of successes entered in the app.

This probability means:

    No window of length r contains s or more successes.

The complementary probability is

    P(S_n(r) >= s) = 1 - P(S_n(r) < s).

This complement means:

    At least one window of length r contains s or more successes.
Main Inputs

1. No of States For the scan statistic app, this should usually be:

       No of States = 2

because the scan statistic function is for binary sequences with states 0 and 1.

Use:

       0 = failure
       1 = success

If the app asks for the number of states, enter 2.

2. n Enter the total sequence length.

   Example:
       n = 20

means the app studies a binary sequence of length 20, such as:

       0 1 0 0 1 1 0 1 0 0 1 0 0 1 1 1 0 0 1 0

3. r = Window length Enter the length of the moving scan window.

   Example:
       r = 5

means the app checks every consecutive block of 5 positions:

       positions 1-5
       positions 2-6
       positions 3-7
       ...
       positions n-r+1 through n

Usually r must satisfy:

       1 <= r <= n

4. s = number of successes Enter the success threshold inside a window.

   Example:
       s = 4

means the app checks whether any window of length r contains at least 4 successes.

The app reports:

       P(S_n(r) < 4)

which means:

       probability that every window of length r has at most 3 successes.

Usually s must satisfy:

       1 <= s <= r

5. The probability Pi For the unconditional iid Bernoulli case, click The probability Pi and enter the probability vector

       Pi = [P(X=0), P(X=1)]

The second entry is the success probability:

       p = P(X=1) = Pi(2)
   Example:
       Pi = [0.7 0.3]

means:

       P(X=0) = 0.7
       P(X=1) = 0.3

Important:

       Do not reverse the order. Pi = [0.7 0.3] means success probability
       p = 0.3, not 0.7.
What The Result Means

After clicking Calculate the Probability, the app displays a probability in the Results panel.

Typical output:

    P(S_n(r) < s) = 0.812345

This means:

    The probability that no moving window of length r contains s or more
    successes is 0.812345.

If you want the probability that at least one window has s or more successes, use the complement:

    P(S_n(r) >= s) = 1 - 0.812345
Step-By-Step Example 1: Unconditional Iid Case
Goal:
    Compute the probability that no 5-window contains 4 or more successes
    in a length-20 iid Bernoulli sequence.

Mathematically:

    P(S_20(5) < 4)
Inputs:
    No of States        = 2
    n                   = 20
    r = Window length   = 5
    s                   = 4
    Pi                  = [0.7 0.3]

Meaning of Pi:

    P(X=0) = 0.7
    P(X=1) = 0.3

Steps:

    1. Click Clear all items.
    2. Enter No of States = 2.
    3. Enter n = 20.
    4. Enter r = 5.
    5. Enter s = 4.
    6. Click The probability Pi.
    7. Enter:
           P(X=0) = 0.7
           P(X=1) = 0.3
    8. Click Save.
    9. Click Calculate the Probability.
Output interpretation:
    The displayed probability is P(S_20(5) < 4).

That is the probability that every length-5 window contains at most 3 successes.

The probability that at least one length-5 window contains 4 or more successes is:

    1 - displayed probability.
Step-By-Step Example 2: Detecting A Local Cluster
Goal:
    Compute the probability that a length-50 sequence has at least one
    10-window with 7 or more successes.

The app directly computes:

    P(S_50(10) < 7)

Then the desired cluster probability is:

    P(S_50(10) >= 7) = 1 - P(S_50(10) < 7).
Inputs:
    No of States        = 2
    n                   = 50
    r                   = 10
    s                   = 7
    Pi                  = [0.8 0.2]

Steps:

    1. Enter No of States = 2.
    2. Enter n = 50.
    3. Enter r = 10.
    4. Enter s = 7.
    5. Click The probability Pi.
    6. Enter Pi = [0.8 0.2].
    7. Click Calculate the Probability.
    8. Compute the complement 1 - Probability if you want the chance of
       at least one local cluster.
Interpretation:
    P(S_50(10) < 7) means no length-10 segment has 7 or more successes.
    1 - P(S_50(10) < 7) means at least one length-10 segment has 7 or
    more successes.
Step-By-Step Example 3: Small Window Example
Goal:
    Compute the probability that no 3-window contains 2 or more successes
    in a length-12 sequence.
Inputs:
    No of States        = 2
    n                   = 12
    r                   = 3
    s                   = 2
    Pi                  = [0.6 0.4]

The app computes:

    P(S_12(3) < 2)

This means every window of length 3 contains at most 1 success.

Example sequence that satisfies S_12(3) < 2:

    1 0 0 1 0 0 1 0 0 1 0 0

Every block of 3 positions has at most one success.

Example sequence that does not satisfy S_12(3) < 2:

    1 1 0 0 0 1 0 0 1 0 0 0

The first window, positions 1-3, contains two successes. Therefore S_12(3) >= 2.

Conditional Scan Statistic, If Your Version Has It

Some versions of this app also include a conditional scan statistic option. In the conditional case, the total number of successes in the whole sequence is fixed.

The conditional probability is:

    P(S_n(r) < s | N_n = m)

where:

    n = sequence length
    r = window length
    s = success threshold in a window
    m = total number of successes in the whole sequence

In the conditional case, do not use Pi. The probability vector is not needed because the calculation conditions on the total number of successes m.

Example conditional inputs:

    n = 20
    m = 8
    r = 5
    s = 4

The app computes:

    P(S_20(5) < 4 | N_20 = 8)

This means that among all binary sequences of length 20 with exactly 8 successes, the app computes the probability that no window of length 5 contains 4 or more successes.

Conditional input restrictions:

    0 <= m <= n
    1 <= r <= n
    1 <= s <= r
Eigvalue/Vector Button

The L_eigValue/vector button is for eigenvalue and eigenvector information associated with the FMCI matrix used in the scan statistic calculation.

This is mainly useful for large-n approximations and diagnostic checking. For ordinary probability calculations, you usually only need Calculate the Probability.

If your app version includes both unconditional and conditional scan statistic calculations, the eigenvalue/vector calculation is usually meaningful for the unconditional homogeneous case. The conditional case is time-inhomogeneous and may not have the same single transition matrix interpretation.

Clear All Items

Use Clear all items before starting a new example.

A safe workflow is:

  1. Clear all items.
  2. Enter No of States = 2.
  3. Enter n.
  4. Enter r.
  5. Enter s.
  6. Enter Pi for the unconditional case.
  7. Calculate.

If you change n, r, s, or Pi, calculate again.

Common Mistakes

1. Reversing Pi Use Pi = [P(X=0), P(X=1)].

   Example:
       Pi = [0.7 0.3] means p = P(X=1) = 0.3.

2. Thinking the output is P(S_n(r) = s) The app reports P(S_n(r) < s), not P(S_n(r) = s).

3. Forgetting the complement If you want the probability that at least one window has s or more successes, compute:

       1 - Probability

4. Entering s larger than r Since a window of length r cannot contain more than r successes, use s <= r.

5. Entering r larger than n The window length cannot be larger than the sequence length.

6. Using No of States other than 2 The scan statistic app is for binary success/failure sequences. Use No of States = 2 unless your function has been modified for another alphabet.

7. Confusing r with the number of successes r is the window length. s is the success threshold.

8. Using Pi in the conditional case If your version has a conditional option, Pi is not used there. The total number of successes m is fixed instead.

Quick Reference

Unconditional iid case:

    No of States = 2
    Enter n
    Enter r
    Enter s
    Enter Pi = [P(X=0), P(X=1)]
    Calculate
Output:
    Probability = P(S_n(r) < s)
Complement:
    1 - Probability = P(S_n(r) >= s)

Meaning:

    P(S_n(r) >= s) is the probability that at least one window of length r
    contains s or more successes.