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
This app computes the distribution of the number of runs in a binary sequence of length n.
The two possible states are:
0 = failure
1 = success
The app supports:
1. Success runs only
2. Failure runs only
3. Total runs of both 0s and 1s
The app also supports two dependence assumptions:
1. Independent Bernoulli trials
2. Two-state Markov-dependent trials
The computational function is:
[pmf, cdf] = fmci_unconditional_success_runs(n, trialType, params, mode)
where:
trialType = 'iid' or 'markov'
mode = 'ones', 'zeros', or 'total'Run Types
The app should have one radio-button group for run type:
Success
Counts runs of 1s only.
The app uses mode = 'ones'.
Failure
Counts runs of 0s only.
The app uses mode = 'zeros'.
Both
Counts total runs of 0s and 1s combined.
The app uses mode = 'total'.
Example sequence:
0 1 1 0 1 0 1 1 1 0
Success runs:
11, 1, 111
Number of success runs = 3
Failure runs:
0, 0, 0, 0
Number of failure runs = 4
Total runs:
0 | 11 | 0 | 1 | 0 | 111 | 0
Total number of runs = 7Dependence Types
The app should have a separate radio-button group for:
Independent
Markov dependent
These must be separate from the Success / Failure / Both radio buttons. This is important because the user must be able to select, for example:
Success + Independent
Failure + Independent
Both + Independent
Success + Markov dependent
Failure + Markov dependent
Both + Markov dependent
If all five radio buttons are placed into one group, the app cannot distinguish the run type from the dependence type.
Inputs
Length of the Sequence
Enter n, the sequence length.
Example:
n = 20
Number of runs
Enter k, the number of runs of interest.
The app reports:
P(R_n = k)
P(R_n <= k)
P(R_n >= k)
Here R_n means the selected run statistic.
Independent Case
Choose Independent when X_1, X_2, ..., X_n are iid Bernoulli trials.
For the independent case, click:
Enter the probability Pi
Enter:
Pi = [P(X=0), P(X=1)]
Example:
Pi = [0.6 0.4]
This means:
P(X=0) = 0.6
P(X=1) = 0.4
The app passes the success probability to the function as:
trialType = 'iid'
params = Pi(2)
For Pi = [0.6 0.4], params = 0.4.
Markov-Dependent Case
Choose Markov dependent when the sequence is a two-state Markov chain on {0,1}.
For the Markov-dependent case, enter two objects:
- Initial Pi
- Transition P
Initial Pi
Click:
Enter the initial Pi
Enter:
initialPi = [P(X_1=0), P(X_1=1)]
Example:
initialPi = [0.7 0.3]
This means:
P(X_1=0) = 0.7
P(X_1=1) = 0.3
Transition P
Click:
Enter transition P
Enter a 2-by-2 transition matrix:
P = [P00 P01
P10 P11]
where:
P00 = P(X_t=0 | X_{t-1}=0)
P01 = P(X_t=1 | X_{t-1}=0)
P10 = P(X_t=0 | X_{t-1}=1)
P11 = P(X_t=1 | X_{t-1}=1)
Example:
P = [0.8 0.2
0.3 0.7]
For the Markov-dependent case, the app passes:
trialType = 'markov'
params = [initialPi(2), P(1,2), P(2,2)]
That is:
params = [p1, P01, P11]
where:
p1 = P(X_1 = 1)
P01 = P(X_t = 1 | X_{t-1} = 0)
P11 = P(X_t = 1 | X_{t-1} = 1)Button Behavior
Independent selected:
Show: Enter the probability Pi
Hide: Enter the initial Pi
Hide: Enter transition P
Markov dependent selected:
Hide: Enter the probability Pi
Show: Enter the initial Pi
Show: Enter transition PHow To Use The App
Step 1. Click Clear all items.
Step 2. Enter Length of the Sequence.
Example:
20
Step 3. Enter Number of runs.
Example:
3
Step 4. Choose the run type:
Success, Failure, or Both.
Step 5. Choose the dependence type:
Independent or Markov dependent.
Step 6A. If Independent is selected:
Click Enter the probability Pi.
Enter Pi = [P(X=0), P(X=1)].
Click Save.
Step 6B. If Markov dependent is selected:
Click Enter the initial Pi.
Enter initialPi = [P(X_1=0), P(X_1=1)].
Click Save.
Then click Enter transition P.
Enter the 2-by-2 transition matrix.
Click Save.
Step 7. Click Calculate the Probability.
Step 8. Optional: click Mean.
This computes E(R_n) from the full pmf.
Step 9. Optional: click EigValue/vector.
This displays eigenvalue/eigenvector information.Example 1: Independent Success Runs
Question:
In 20 iid Bernoulli trials with P(X=1)=0.4, what is the
probability of exactly 3 success runs?
Inputs:
Length of the Sequence = 20
Number of runs = 3
Run type = Success
Dependence type = Independent
Pi = [0.6 0.4]
Function call used by the app:
[pmf, cdf] = fmci_unconditional_success_runs(20, 'iid', 0.4, 'ones')
Output:
P(R_20 = 3)
P(R_20 <= 3)
P(R_20 >= 3)Example 2: Independent Failure Runs
Question:
In 20 iid Bernoulli trials with P(X=0)=0.6, what is the
probability of exactly 4 failure runs?
Inputs:
Length of the Sequence = 20
Number of runs = 4
Run type = Failure
Dependence type = Independent
Pi = [0.6 0.4]
Function call used by the app:
[pmf, cdf] = fmci_unconditional_success_runs(20, 'iid', 0.4, 'zeros')
Because mode = 'zeros', the function computes failure runs.
Example 3: Independent Total Runs
Question:
In 20 iid Bernoulli trials, what is the probability of
exactly 8 total runs?
Inputs:
Length of the Sequence = 20
Number of runs = 8
Run type = Both
Dependence type = Independent
Pi = [0.5 0.5]
Function call used by the app:
[pmf, cdf] = fmci_unconditional_success_runs(20, 'iid', 0.5, 'total')Example 4: Markov Success Runs
Question:
In a two-state Markov chain, what is the probability of
exactly 3 success runs in 20 trials?
Inputs:
Length of the Sequence = 20
Number of runs = 3
Run type = Success
Dependence type = Markov dependent
Initial distribution:
initialPi = [0.7 0.3]
Transition matrix:
P = [0.8 0.2
0.3 0.7]
The app forms:
params = [0.3, 0.2, 0.7]
Function call used by the app:
[pmf, cdf] = fmci_unconditional_success_runs(20, 'markov', [0.3 0.2 0.7], 'ones')Example 5: Markov Total Runs
Question:
In a two-state Markov chain, what is the probability of
exactly 10 total runs in 20 trials?
Inputs:
Length of the Sequence = 20
Number of runs = 10
Run type = Both
Dependence type = Markov dependent
Initial distribution:
initialPi = [0.5 0.5]
Transition matrix:
P = [0.9 0.1
0.2 0.8]
The app forms:
params = [0.5, 0.1, 0.8]
Function call used by the app:
[pmf, cdf] = fmci_unconditional_success_runs(20, 'markov', [0.5 0.1 0.8], 'total')Understanding The Results
The app displays three probabilities.
P(R_n = k)
Probability that the number of runs is exactly k.
P(R_n <= k)
Probability that the number of runs is at most k.
P(R_n >= k)
Probability that the number of runs is at least k.
For Success mode, R_n counts success runs. For Failure mode, R_n counts failure runs. For Both mode, R_n counts total runs.
Mean Button
The Mean button computes:
E(R_n) = sum_k k * P(R_n = k)
It uses the same current selections and probability inputs.
Eigvalue/Vector Button
The EigValue/vector button is optional.
It displays the largest eigenvalue and right eigenvector of the FMCI transition matrix for the current case when available.
The app should write this output into one scrollable text area inside the eigenvalue/vector panel, so the eigenvalue and eigenvector text do not overlap.
Common Mistakes To Avoid
1. Do not put all five radio buttons into one group. Use one group for Success / Failure / Both and another group for Independent / Markov dependent.
2. Do not reverse Pi. Pi must be [P(X=0), P(X=1)].
- Independent Pi must have exactly two entries and sum to 1.
- Markov initialPi must have exactly two entries and sum to 1.
- Each row of the Markov transition matrix must sum to 1.
6. For success/failure runs, the maximum possible number of runs is ceil(n/2).
- For total runs, the maximum possible number of runs is n.
8. If you change from Independent to Markov dependent, enter initial Pi and transition P before calculating.
Recommended Defaults
Independent default:
Pi = [0.5 0.5]
Markov initial default:
initialPi = [0.5 0.5]
Markov transition default:
P = [0.5 0.5
0.5 0.5]