<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Publishing DTD v1.1d3 20150301//EN" "http://jats.nlm.nih.gov/publishing/1.1d3/JATS-journalpublishing1.dtd">
<article article-type="research-article" dtd-version="1.1d3" xml:lang="en" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink">
<front>
<journal-meta>
<journal-id journal-id-type="nlm-ta">PLoS ONE</journal-id>
<journal-id journal-id-type="publisher-id">plos</journal-id>
<journal-id journal-id-type="pmc">plosone</journal-id>
<journal-title-group>
<journal-title>PLOS ONE</journal-title>
</journal-title-group>
<issn pub-type="epub">1932-6203</issn>
<publisher>
<publisher-name>Public Library of Science</publisher-name>
<publisher-loc>San Francisco, CA USA</publisher-loc>
</publisher>
</journal-meta>
<article-meta>
<article-id pub-id-type="doi">10.1371/journal.pone.0223233</article-id>
<article-id pub-id-type="publisher-id">PONE-D-19-14277</article-id>
<article-categories>
<subj-group subj-group-type="heading">
<subject>Research Article</subject>
</subj-group>
<subj-group subj-group-type="Discipline-v3"><subject>Physical sciences</subject><subj-group><subject>Mathematics</subject><subj-group><subject>Probability theory</subject><subj-group><subject>Probability distribution</subject></subj-group></subj-group></subj-group></subj-group><subj-group subj-group-type="Discipline-v3"><subject>Physical sciences</subject><subj-group><subject>Mathematics</subject><subj-group><subject>Probability theory</subject><subj-group><subject>Statistical distributions</subject></subj-group></subj-group></subj-group></subj-group><subj-group subj-group-type="Discipline-v3"><subject>Engineering and technology</subject><subj-group><subject>Signal processing</subject><subj-group><subject>Statistical signal processing</subject></subj-group></subj-group></subj-group><subj-group subj-group-type="Discipline-v3"><subject>Engineering and technology</subject><subj-group><subject>Signal processing</subject><subj-group><subject>Noise reduction</subject></subj-group></subj-group></subj-group><subj-group subj-group-type="Discipline-v3"><subject>Physical sciences</subject><subj-group><subject>Mathematics</subject><subj-group><subject>Statistics</subject><subj-group><subject>Statistical data</subject></subj-group></subj-group></subj-group></subj-group><subj-group subj-group-type="Discipline-v3"><subject>Computer and information sciences</subject><subj-group><subject>Data visualization</subject><subj-group><subject>Infographics</subject><subj-group><subject>Charts</subject></subj-group></subj-group></subj-group></subj-group><subj-group subj-group-type="Discipline-v3"><subject>Physical sciences</subject><subj-group><subject>Mathematics</subject><subj-group><subject>Algebra</subject><subj-group><subject>Polynomials</subject><subj-group><subject>Binomials</subject></subj-group></subj-group></subj-group></subj-group></subj-group><subj-group subj-group-type="Discipline-v3"><subject>Biology and life sciences</subject><subj-group><subject>Organisms</subject><subj-group><subject>Eukaryota</subject><subj-group><subject>Animals</subject><subj-group><subject>Vertebrates</subject><subj-group><subject>Amniotes</subject><subj-group><subject>Mammals</subject><subj-group><subject>Wildebeest</subject></subj-group></subj-group></subj-group></subj-group></subj-group></subj-group></subj-group></subj-group></article-categories>
<title-group>
<article-title>Joint distribution for number of crossings and longest run in independent Bernoulli observations. The R package crossrun</article-title>
<alt-title alt-title-type="running-head">Joint distribution for crossings and longest run. The R package crossrun</alt-title>
</title-group>
<contrib-group>
<contrib contrib-type="author" corresp="yes" xlink:type="simple">
<contrib-id authenticated="true" contrib-id-type="orcid">http://orcid.org/0000-0002-0318-4162</contrib-id>
<name name-style="western">
<surname>Wentzel-Larsen</surname>
<given-names>Tore</given-names>
</name>
<role content-type="http://credit.casrai.org/">Conceptualization</role>
<role content-type="http://credit.casrai.org/">Formal analysis</role>
<role content-type="http://credit.casrai.org/">Methodology</role>
<role content-type="http://credit.casrai.org/">Writing – original draft</role>
<xref ref-type="aff" rid="aff001"><sup>1</sup></xref>
<xref ref-type="aff" rid="aff002"><sup>2</sup></xref>
<xref ref-type="corresp" rid="cor001">*</xref>
</contrib>
<contrib contrib-type="author" xlink:type="simple">
<contrib-id authenticated="true" contrib-id-type="orcid">http://orcid.org/0000-0002-7701-1774</contrib-id>
<name name-style="western">
<surname>Anhøj</surname>
<given-names>Jacob</given-names>
</name>
<role content-type="http://credit.casrai.org/">Conceptualization</role>
<role content-type="http://credit.casrai.org/">Formal analysis</role>
<role content-type="http://credit.casrai.org/">Methodology</role>
<role content-type="http://credit.casrai.org/">Writing – original draft</role>
<xref ref-type="aff" rid="aff003"><sup>3</sup></xref>
</contrib>
</contrib-group>
<aff id="aff001"><label>1</label> <addr-line>Centre for Child and Adolescent Mental Health, Eastern and Southern Norway, Oslo, Norway</addr-line></aff>
<aff id="aff002"><label>2</label> <addr-line>Norwegian Centre of Violence and Traumatic Stress Studies, Oslo, Norway</addr-line></aff>
<aff id="aff003"><label>3</label> <addr-line>Rigshospitalet, University of Copenhagen, Copenhagen, Denmark</addr-line></aff>
<contrib-group>
<contrib contrib-type="editor" xlink:type="simple">
<name name-style="western">
<surname>Chiacchio</surname>
<given-names>Ferdinando</given-names>
</name>
<role>Editor</role>
<xref ref-type="aff" rid="edit1"/>
</contrib>
</contrib-group>
<aff id="edit1"><addr-line>University of Catania, ITALY</addr-line></aff>
<author-notes>
<fn fn-type="conflict" id="coi001">
<p>The authors have declared that no competing interests exist.</p>
</fn>
<corresp id="cor001">* E-mail: <email xlink:type="simple">tore.wentzellarsen@gmail.com</email></corresp>
</author-notes>
<pub-date pub-type="epub">
<day>1</day>
<month>10</month>
<year>2019</year>
</pub-date>
<pub-date pub-type="collection">
<year>2019</year>
</pub-date>
<volume>14</volume>
<issue>10</issue>
<elocation-id>e0223233</elocation-id>
<history>
<date date-type="received">
<day>20</day>
<month>5</month>
<year>2019</year>
</date>
<date date-type="accepted">
<day>17</day>
<month>9</month>
<year>2019</year>
</date>
</history>
<permissions>
<copyright-year>2019</copyright-year>
<copyright-holder>Wentzel-Larsen, Anhøj</copyright-holder>
<license xlink:href="http://creativecommons.org/licenses/by/4.0/" xlink:type="simple">
<license-p>This is an open access article distributed under the terms of the <ext-link ext-link-type="uri" xlink:href="http://creativecommons.org/licenses/by/4.0/" xlink:type="simple">Creative Commons Attribution License</ext-link>, which permits unrestricted use, distribution, and reproduction in any medium, provided the original author and source are credited.</license-p>
</license>
</permissions>
<self-uri content-type="pdf" xlink:href="info:doi/10.1371/journal.pone.0223233"/>
<abstract>
<p>The R package crossrun computes the joint distribution of the number of crossings and the longest run in a sequence of independent Bernoulli observations. The main intended application is statistical process control where the joint distribution may be used for systematic investigation, and possibly refinement, of existing rules for distinguishing between signal and noise. While the crossrun vignette is written to assist in practical use, this article gives a hands-on explanation of why the procedures works. The article also includes a discussion of limitations of the present version of crossrun together with an outline of ongoing work to meet these limitations. There is more to come, and it is necessary to grasp the basic ideas behind the procedure implemented both to understand these planned extensions, and how presently implemented rules in statistical process control, based on the number of crossings and the longest run, may be refined.</p>
</abstract>
<funding-group>
<funding-statement>The authors received no specific funding for this work.</funding-statement>
</funding-group>
<counts>
<fig-count count="2"/>
<table-count count="3"/>
<page-count count="11"/>
</counts>
<custom-meta-group>
<custom-meta id="data-availability">
<meta-name>Data Availability</meta-name>
<meta-value>The article describes software, the R package crossrun. No data except what is generated by the attached script crossrunart.R is used.</meta-value>
</custom-meta>
</custom-meta-group>
</article-meta>
</front>
<body>
<sec id="sec001" sec-type="intro">
<title>Introduction</title>
<p>The setting is defined by a number of independent observations from a Bernoulli distribution with the same success probability. In statistical process control, our main intended application, this may be the useful observations in a runchart, recording values above and below the median from previous data, disregarding any observations equal to the median [<xref ref-type="bibr" rid="pone.0223233.ref001">1</xref>]. The focus of the R package crossrun [<xref ref-type="bibr" rid="pone.0223233.ref002">2</xref>,<xref ref-type="bibr" rid="pone.0223233.ref003">3</xref>] is the joint distribution of number of crossings, C, and the length of the longest run, L, in random data sequences. A run is a sequence of successes or failures, delimited by a different observation or the start or end of the entire sequence. A crossing is two adjacent different observations.</p>
<p><xref ref-type="fig" rid="pone.0223233.g001">Fig 1</xref> illustrates runs and crossings in a run chart with 20 random observations. Observations above and below the median represent successes and failures respectively.</p>
<fig id="pone.0223233.g001" position="float">
<object-id pub-id-type="doi">10.1371/journal.pone.0223233.g001</object-id>
<label>Fig 1</label>
<caption>
<title>A run chart with n = 20 data points.</title>
</caption>
<graphic mimetype="image" position="float" xlink:href="info:doi/10.1371/journal.pone.0223233.g001" xlink:type="simple"/>
</fig>
<p>The longest run consists of observations 3–7 above the median. The length of the longest run is L = 5. The number of crossings of the median is C = 10.</p>
<p>While the number of crossings follows a binomial distribution in the symmetric case (success probability 0.5), no closed form distribution is known for the longest run. The distribution of the longest run has been investigated in a number of articles, including Schilling [<xref ref-type="bibr" rid="pone.0223233.ref004">4</xref>], and Fazekas et al [<xref ref-type="bibr" rid="pone.0223233.ref005">5</xref>] that in fact gives recursion formulas, and approximations have been given. However, what is needed in applications is the joint distribution of these two variables, for which we are not aware of exact results. Our primary aim is to present an iterative procedure for computing this distribution, in principle for an arbitrary number of observations.</p>
<sec id="sec002">
<title>The iterative procedure, setting</title>
<p>In n independent Bernoulli observations with success probability p and failure probability q = 1—p, values are denoted by 1 (success with probability p) or 0. A crossing consists of two consecutive different values, and a run of length l consists of l successive observations, delimited by a crossing or the first or last observation. The possible values of the number C of crossings are c = 0, …, n-1, and the possible values for the length L of the longest run are l = 1, …, n. The joint probabilities of L and C for given n are denoted by <italic>P</italic><sub><italic>n</italic></sub>(<italic>L</italic> = <italic>l</italic>,<italic>C</italic> = <italic>c</italic>).</p>
<p>The iterative procedure involves conditioning on the first observation denoted by S, with values 1 for success (probability p) and 0 for failure (probability q). The iterative procedure computes the conditional probabilities
<disp-formula id="pone.0223233.e001">
<alternatives>
<graphic id="pone.0223233.e001g" mimetype="image" position="anchor" xlink:href="info:doi/10.1371/journal.pone.0223233.e001" xlink:type="simple"/>
<mml:math display="block" id="M1">
<mml:msub><mml:mrow><mml:mi>P</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi></mml:mrow></mml:msub><mml:mo>(</mml:mo><mml:mrow><mml:mi>L</mml:mi><mml:mo>=</mml:mo><mml:mi>l</mml:mi><mml:mo>,</mml:mo><mml:mi>C</mml:mi><mml:mo>=</mml:mo><mml:mi>c</mml:mi><mml:mo>|</mml:mo><mml:mi>S</mml:mi><mml:mo>=</mml:mo><mml:mn>1</mml:mn></mml:mrow><mml:mo>)</mml:mo><mml:mo>,</mml:mo><mml:msub><mml:mrow><mml:mi>P</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi></mml:mrow></mml:msub><mml:mo>(</mml:mo><mml:mrow><mml:mi>L</mml:mi><mml:mo>=</mml:mo><mml:mi>l</mml:mi><mml:mo>,</mml:mo><mml:mi>C</mml:mi><mml:mo>=</mml:mo><mml:mi>c</mml:mi><mml:mo>|</mml:mo><mml:mi>S</mml:mi><mml:mo>=</mml:mo><mml:mn>0</mml:mn></mml:mrow><mml:mo>)</mml:mo>
</mml:math>
</alternatives>
</disp-formula></p>
<p>This conditioning on the first observation is an essential part of the procedure. One way to see that this is reasonable is to consider the case when p is close to 1. Then most observations are successes, most runs are success runs and the conditional joint distribution of runs and crossings is quite different dependent on the first observation. It is sufficient to be able to compute these conditional distributions, because the unconditional joint distribution is
<disp-formula id="pone.0223233.e002">
<alternatives>
<graphic id="pone.0223233.e002g" mimetype="image" position="anchor" xlink:href="info:doi/10.1371/journal.pone.0223233.e002" xlink:type="simple"/>
<mml:math display="block" id="M2">
<mml:msub><mml:mrow><mml:mi>P</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi></mml:mrow></mml:msub><mml:mo>(</mml:mo><mml:mrow><mml:mi>L</mml:mi><mml:mo>=</mml:mo><mml:mi>l</mml:mi><mml:mo>,</mml:mo><mml:mi>C</mml:mi><mml:mo>=</mml:mo><mml:mi>c</mml:mi></mml:mrow><mml:mo>)</mml:mo><mml:mo>=</mml:mo><mml:msub><mml:mrow><mml:mi>P</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi></mml:mrow></mml:msub><mml:mo>(</mml:mo><mml:mrow><mml:mi>L</mml:mi><mml:mo>=</mml:mo><mml:mi>l</mml:mi><mml:mo>,</mml:mo><mml:mi>C</mml:mi><mml:mo>=</mml:mo><mml:mi>c</mml:mi><mml:mo>|</mml:mo><mml:mi>S</mml:mi><mml:mo>=</mml:mo><mml:mn>1</mml:mn></mml:mrow><mml:mo>)</mml:mo><mml:mo>·</mml:mo><mml:mi>p</mml:mi><mml:mo>+</mml:mo><mml:msub><mml:mrow><mml:mi>P</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi></mml:mrow></mml:msub><mml:mo>(</mml:mo><mml:mrow><mml:mi>L</mml:mi><mml:mo>=</mml:mo><mml:mi>l</mml:mi><mml:mo>,</mml:mo><mml:mi>C</mml:mi><mml:mo>=</mml:mo><mml:mi>c</mml:mi><mml:mo>|</mml:mo><mml:mi>S</mml:mi><mml:mo>=</mml:mo><mml:mn>0</mml:mn></mml:mrow><mml:mo>)</mml:mo><mml:mo>·</mml:mo><mml:mi>q</mml:mi>
</mml:math>
</alternatives>
</disp-formula></p>
<p>For the iterative procedure to work it is also necessary to take another variable into account, the first crossing. More precisely, we denote the end position of the first crossing by F, with values F = 2, …, n. An additional value F = 1 denotes, by convention, the case of no crossing. The joint probabilities for C and L conditional on S are partitioned by further conditioning on F as detailed below.</p>
<p>It is important to underline that the conditioning variables S and F are not parameters of the distribution but useful constructions that help break down the iterative procedure in manageable parts.</p>
<p>This article first describes the setting for the iterative computation procedure and its initial stage. Next, we introduce conditioning on the starting position and partitioning on the position of the first crossing. Finally, the joint distribution of the number of crossings and the longest run conditional on these variables is given. The computation procedure is different in two cases that are subsequently described.</p>
<p>After the exposition of the iterative procedure follows a brief comment on the simpler symmetric case, and the precision of the procedure is discussed. The resulting joint distribution is described in a simple case, and procedures for checking are briefly commented. Next follows sections on generalizations and applications and on limitations of the procedures in crossrun together with a brief description of ongoing work to address these limitations. Finally, a Conclusions section summarizes the article. Two appendices are included, one giving details on the "times" representation in which the joint distributions are actually stored, as described in the section on precision, and one on the code for the main function crossrunbin and for the analyses in this article.</p>
</sec>
<sec id="sec003">
<title>The conditional probabilities with one observation</title>
<p>First, we present the starting point of the iterative procedure, the conditional probabilities in the rather redundant case with only one observation. If n = 1, then 0 is the only possible value of C and 1 the only possible value of L, therefore <italic>P</italic><sub>1</sub>(<italic>C</italic> = 0,<italic>L</italic> = 1|<italic>S</italic> = 1) = <italic>P</italic><sub>1</sub>(<italic>C</italic> = 0,<italic>L</italic> = 1|<italic>S</italic> = 0) = 1.</p>
<p>In this case the joint distribution of (C,L) is degenerate and takes the value (0,1) with probability one. Moving to more than one observation, the next step is presenting the conditional distribution of the end position F of the first crossing, conditional on the starting position S.</p>
</sec>
<sec id="sec004">
<title>The distribution of the first crossing conditional on the starting position</title>
<p>If the first value is 1 (success), no crossing means that all the remaining n-1 values are also 1, therefore <italic>P</italic><sub><italic>n</italic></sub>(<italic>F</italic> = 1|<italic>S</italic> = 1) = <italic>p</italic><sup><italic>n</italic>−1</sup>. Similarly, <italic>P</italic><sub><italic>n</italic></sub>(<italic>F</italic> = 1|<italic>S</italic> = 0) = <italic>q</italic><sup><italic>n</italic>−1</sup>. Next, if f = 2, …, n and the first value is a success, F = f means that the sequence starts with a success, then f-2 more successes and then one failure. Therefore,
<disp-formula id="pone.0223233.e003">
<alternatives>
<graphic id="pone.0223233.e003g" mimetype="image" position="anchor" xlink:href="info:doi/10.1371/journal.pone.0223233.e003" xlink:type="simple"/>
<mml:math display="block" id="M3">
<mml:msub><mml:mrow><mml:mi>P</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi></mml:mrow></mml:msub><mml:mo>(</mml:mo><mml:mrow><mml:mi>F</mml:mi><mml:mo>=</mml:mo><mml:mi>f</mml:mi><mml:mo>|</mml:mo><mml:mi>S</mml:mi><mml:mo>=</mml:mo><mml:mn>1</mml:mn></mml:mrow><mml:mo>)</mml:mo><mml:mo>=</mml:mo><mml:msup><mml:mrow><mml:mi>p</mml:mi></mml:mrow><mml:mrow><mml:mi>f</mml:mi><mml:mo>−</mml:mo><mml:mn>2</mml:mn></mml:mrow></mml:msup><mml:mo>·</mml:mo><mml:mi>q</mml:mi><mml:mo>,</mml:mo><mml:msub><mml:mrow><mml:mi>P</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi></mml:mrow></mml:msub><mml:mo>(</mml:mo><mml:mrow><mml:mi>F</mml:mi><mml:mo>=</mml:mo><mml:mi>f</mml:mi><mml:mo>|</mml:mo><mml:mi>S</mml:mi><mml:mo>=</mml:mo><mml:mn>0</mml:mn></mml:mrow><mml:mo>)</mml:mo><mml:mo>=</mml:mo><mml:msup><mml:mrow><mml:mi>q</mml:mi></mml:mrow><mml:mrow><mml:mi>f</mml:mi><mml:mo>−</mml:mo><mml:mn>2</mml:mn></mml:mrow></mml:msup><mml:mo>·</mml:mo><mml:mi>p</mml:mi><mml:mo>,</mml:mo><mml:mi>f</mml:mi><mml:mo>=</mml:mo><mml:mn>2</mml:mn><mml:mo>,</mml:mo><mml:mo>…</mml:mo><mml:mo>,</mml:mo><mml:mi>n</mml:mi>
</mml:math>
</alternatives>
</disp-formula>
where the last formula is based on a similar argument conditional on S = 0. In the following, arguments will in many cases be given for S = 1 only, and similar results for S = 0 will be stated with no explicit arguments. By symmetry, these results will simply involve replacing p by q. In the next step the formulas in this section will be used for partitioning the joint conditional probabilities for C and L given S, by the position F of the first crossing.</p>
</sec>
<sec id="sec005">
<title>Partitioning by the position of the first crossing</title>
<p>Partitioning on F we have
<disp-formula id="pone.0223233.e004">
<alternatives>
<graphic id="pone.0223233.e004g" mimetype="image" position="anchor" xlink:href="info:doi/10.1371/journal.pone.0223233.e004" xlink:type="simple"/>
<mml:math display="block" id="M4">
<mml:msub><mml:mrow><mml:mi>P</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi></mml:mrow></mml:msub><mml:mo>(</mml:mo><mml:mrow><mml:mi>L</mml:mi><mml:mo>=</mml:mo><mml:mi>l</mml:mi><mml:mo>,</mml:mo><mml:mi>C</mml:mi><mml:mo>=</mml:mo><mml:mi>c</mml:mi><mml:mo>|</mml:mo><mml:mi>S</mml:mi><mml:mo>=</mml:mo><mml:mn>1</mml:mn></mml:mrow><mml:mo>)</mml:mo><mml:mo>=</mml:mo><mml:mrow><mml:munderover><mml:mo stretchy="false">∑</mml:mo><mml:mrow><mml:mi>f</mml:mi><mml:mo>=</mml:mo><mml:mn>1</mml:mn></mml:mrow><mml:mrow><mml:mi>n</mml:mi></mml:mrow></mml:munderover><mml:mrow><mml:msub><mml:mrow><mml:mi>P</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi></mml:mrow></mml:msub><mml:mo>(</mml:mo><mml:mrow><mml:mi>L</mml:mi><mml:mo>=</mml:mo><mml:mi>l</mml:mi><mml:mo>,</mml:mo><mml:mi>C</mml:mi><mml:mo>=</mml:mo><mml:mi>c</mml:mi><mml:mo>|</mml:mo><mml:mi>S</mml:mi><mml:mo>=</mml:mo><mml:mn>1</mml:mn><mml:mo>,</mml:mo><mml:mi>F</mml:mi><mml:mo>=</mml:mo><mml:mi>f</mml:mi></mml:mrow><mml:mo>)</mml:mo><mml:mo>·</mml:mo><mml:msub><mml:mrow><mml:mi>P</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi></mml:mrow></mml:msub><mml:mo>(</mml:mo><mml:mrow><mml:mi>F</mml:mi><mml:mo>=</mml:mo><mml:mi>f</mml:mi><mml:mo>|</mml:mo><mml:mi>S</mml:mi><mml:mo>=</mml:mo><mml:mn>1</mml:mn></mml:mrow><mml:mo>)</mml:mo></mml:mrow></mml:mrow>
</mml:math>
</alternatives>
</disp-formula>
where, as shown in the previous section,
<disp-formula id="pone.0223233.e005">
<alternatives>
<graphic id="pone.0223233.e005g" mimetype="image" position="anchor" xlink:href="info:doi/10.1371/journal.pone.0223233.e005" xlink:type="simple"/>
<mml:math display="block" id="M5">
<mml:msub><mml:mrow><mml:mi>P</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi></mml:mrow></mml:msub><mml:mo>(</mml:mo><mml:mrow><mml:mi>F</mml:mi><mml:mo>=</mml:mo><mml:mi>f</mml:mi><mml:mo>|</mml:mo><mml:mi>S</mml:mi><mml:mo>=</mml:mo><mml:mn>1</mml:mn></mml:mrow><mml:mo>)</mml:mo><mml:mo>=</mml:mo><mml:msup><mml:mrow><mml:mi>p</mml:mi></mml:mrow><mml:mrow><mml:mi>f</mml:mi><mml:mo>−</mml:mo><mml:mn>2</mml:mn></mml:mrow></mml:msup><mml:mi>q</mml:mi><mml:mspace width="0.25em"/><mml:mi mathvariant="normal">if</mml:mi><mml:mspace width="0.25em"/><mml:mi>f</mml:mi><mml:mo>≥</mml:mo><mml:mn>2</mml:mn><mml:mspace width="0.25em"/><mml:mi mathvariant="normal">and</mml:mi><mml:mspace width="0.25em"/><mml:msub><mml:mrow><mml:mi>P</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi></mml:mrow></mml:msub><mml:mo>(</mml:mo><mml:mrow><mml:mi>F</mml:mi><mml:mo>=</mml:mo><mml:mn>1</mml:mn><mml:mo>|</mml:mo><mml:mi>S</mml:mi><mml:mo>=</mml:mo><mml:mn>1</mml:mn></mml:mrow><mml:mo>)</mml:mo><mml:mo>=</mml:mo><mml:msup><mml:mrow><mml:mi>p</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi><mml:mo>−</mml:mo><mml:mn>1</mml:mn></mml:mrow></mml:msup>
</mml:math>
</alternatives>
</disp-formula></p>
<p>The formulas for <italic>P</italic><sub><italic>n</italic></sub>(<italic>L</italic> =<italic>l</italic>,<italic>C</italic> = <italic>c</italic>|<italic>S</italic> = 0) are the same, just interchanging p and q. This implies that the joint probabilities of C and L conditional on S may be computed if it is possible to compute all the joint probabilities of C and L conditional on S and F. This is the next step.</p>
</sec>
<sec id="sec006">
<title>Joint distribution conditional on starting position and first crossing</title>
<p>First, if there is no crossing (F = 1) the entire sequence constitutes one single run, therefore
<disp-formula id="pone.0223233.e006">
<alternatives>
<graphic id="pone.0223233.e006g" mimetype="image" position="anchor" xlink:href="info:doi/10.1371/journal.pone.0223233.e006" xlink:type="simple"/>
<mml:math display="block" id="M6">
<mml:msub><mml:mrow><mml:mi>P</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi></mml:mrow></mml:msub><mml:mo>(</mml:mo><mml:mrow><mml:mi>C</mml:mi><mml:mo>=</mml:mo><mml:mn>0</mml:mn><mml:mo>,</mml:mo><mml:mi>L</mml:mi><mml:mo>=</mml:mo><mml:mn>1</mml:mn><mml:mo>|</mml:mo><mml:mi>S</mml:mi><mml:mo>=</mml:mo><mml:mn>1</mml:mn><mml:mo>,</mml:mo><mml:mi>F</mml:mi><mml:mo>=</mml:mo><mml:mn>1</mml:mn></mml:mrow><mml:mo>)</mml:mo><mml:mo>=</mml:mo><mml:msub><mml:mrow><mml:mi>P</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi></mml:mrow></mml:msub><mml:mo>(</mml:mo><mml:mrow><mml:mi>C</mml:mi><mml:mo>=</mml:mo><mml:mn>0</mml:mn><mml:mo>,</mml:mo><mml:mi>L</mml:mi><mml:mo>=</mml:mo><mml:mn>1</mml:mn><mml:mo>|</mml:mo><mml:mi>S</mml:mi><mml:mo>=</mml:mo><mml:mn>0</mml:mn><mml:mo>,</mml:mo><mml:mi>F</mml:mi><mml:mo>=</mml:mo><mml:mn>1</mml:mn></mml:mrow><mml:mo>)</mml:mo><mml:mo>=</mml:mo><mml:mn>1</mml:mn>
</mml:math>
</alternatives>
</disp-formula>
and all other conditional probabilities are 0. Thus, the matrices of joint probabilities of C and L conditional on F = 1 together with each value of S, are matrices with all components equal to 0, except for a 1 in the upper right corner.</p>
<p>If crossings do occur (f = 2, …, n), the conditional probabilities
<disp-formula id="pone.0223233.e007">
<alternatives>
<graphic id="pone.0223233.e007g" mimetype="image" position="anchor" xlink:href="info:doi/10.1371/journal.pone.0223233.e007" xlink:type="simple"/>
<mml:math display="block" id="M7">
<mml:msub><mml:mrow><mml:mi>P</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi></mml:mrow></mml:msub><mml:mo>(</mml:mo><mml:mrow><mml:mi>C</mml:mi><mml:mo>=</mml:mo><mml:mi>c</mml:mi><mml:mo>,</mml:mo><mml:mi>L</mml:mi><mml:mo>=</mml:mo><mml:mi>l</mml:mi><mml:mo>|</mml:mo><mml:mi>S</mml:mi><mml:mo>=</mml:mo><mml:mn>1</mml:mn><mml:mo>,</mml:mo><mml:mi>F</mml:mi><mml:mo>=</mml:mo><mml:mi>f</mml:mi></mml:mrow><mml:mo>)</mml:mo><mml:mo>,</mml:mo><mml:msub><mml:mrow><mml:mi>P</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi></mml:mrow></mml:msub><mml:mo>(</mml:mo><mml:mrow><mml:mi>C</mml:mi><mml:mo>=</mml:mo><mml:mi>c</mml:mi><mml:mo>,</mml:mo><mml:mi>L</mml:mi><mml:mo>=</mml:mo><mml:mi>l</mml:mi><mml:mo>|</mml:mo><mml:mi>S</mml:mi><mml:mo>=</mml:mo><mml:mn>0</mml:mn><mml:mo>,</mml:mo><mml:mi>F</mml:mi><mml:mo>=</mml:mo><mml:mi>f</mml:mi></mml:mrow><mml:mo>)</mml:mo>
</mml:math>
</alternatives>
</disp-formula>
are more complicated. The key to computing these probabilities is to recognize that, except for the initial run of f-1 observations, the remaining observations constitute n-(f-1) = n+1-f identical and independent Bernoulli observations with success probability p, they represent the same setting as for all n observations, just a shorter sequence. Further, these n+1-f observations are also conditional on a fixed value of their first observation, only that this fixed value is the opposite as in the entire sequence. This is because the last n+1-f observations start with the observation after the first crossing.</p>
<p>We now have to distinguish between two cases. In case 1, the f-1 observations in the initial run, before the first crossing, are at least as many as the last n+1-f ones. In case 2, the initial run is shorter:</p>
<p>Case 1: f-1 ≥ n+1-f</p>
<p>Case 2: f-1 &lt; n+1-f</p>
<p>The two cases are illustrated in <xref ref-type="fig" rid="pone.0223233.g002">Fig 2</xref> below. In both cases the observations (red) from the end of the first crossing constitute a runchart of its own, only shorter and starting on the opposite side. In Case 1 (top), the initial run of f-1 = 14 observations is longest, l = f-1 = 14. The number of crossings in the last n+1-f = 10 observations is between 0 and 9, and the total number of crossings is one more, 1 ≤ c ≤ 10. In Case2 (bottom) the initial run of f-1 = 8 observations may or may not be longest, l ≥ 8. It is a longest run precisely if no run within the last n+1-f = 16 (red) observations is longer than 8. If all observations in the last 16 observations are below the median, l = 16, thus for the whole sequence 8 ≤ l ≤ 16. The number of crossings in the last part (red, 16 observations) is between 0 and 16–1 = 15, and the number of crossings in the whole sequence is one more, 1° ≤ c ≤ 16. What is shown here in an example is the core of the general argument that follows.</p>
<fig id="pone.0223233.g002" position="float">
<object-id pub-id-type="doi">10.1371/journal.pone.0223233.g002</object-id>
<label>Fig 2</label>
<caption>
<title>Two runcharts with n = 24 data points, both starting above the median.</title>
</caption>
<graphic mimetype="image" position="float" xlink:href="info:doi/10.1371/journal.pone.0223233.g002" xlink:type="simple"/>
</fig>
<p>Top: f = 15, the initial run is necessarily longest. Bottom: f = 9, the initial run may or may not be longest.</p>
</sec>
<sec id="sec007">
<title>Case 1, at least as many observations before the first crossing as thereafter</title>
<p>This is the simplest case. Here, the first f-1 observations constitute a run of length f-1, and no run in the last n+1-f observations may be longer than that. Therefore, the longest run is f-1, and the non-zero probabilities <italic>P</italic><sub><italic>n</italic></sub>(<italic>C</italic> = <italic>c</italic>,<italic>L</italic> = <italic>l</italic>|<italic>S</italic> = 1,<italic>F</italic> = <italic>f</italic>) are confined to the vertical strip l = f-1. And, in fact, to only a part of this strip. First, there is at least one crossing, from time f-1 to f. Also, any further crossings are within the last observations, and may be any number between 0 and (n+1-f)– 1. The total number of crossings may therefore be any number between 1 and n+1-f, which means that the non-zero probabilities <italic>P</italic><sub><italic>n</italic></sub>(<italic>C</italic> = <italic>c</italic>,<italic>L</italic> = <italic>l</italic>|<italic>S</italic> = 1,<italic>F</italic> = <italic>f</italic>) are confined to the strip l = f-1, 1 ≤ c ≤ n+1-f.</p>
<p>The non-zero probabilities <italic>P</italic><sub><italic>n</italic></sub>(<italic>C</italic> = <italic>c</italic>,<italic>L</italic> = <italic>l</italic>|<italic>S</italic> = 1,<italic>F</italic> = <italic>f</italic>), <italic>l</italic> = <italic>f</italic>−1,1≤<italic>c</italic>≤<italic>n</italic>+1−<italic>f</italic> are somehow determined by what happens within the last n+1-f observations. More specifically, the last n+1-f observations constitute a sequence of the same type as the original n observations, only shorter, and with the starting observation fixed on the opposite side of the central line. To put it into a formula,
<disp-formula id="pone.0223233.e008">
<alternatives>
<graphic id="pone.0223233.e008g" mimetype="image" position="anchor" xlink:href="info:doi/10.1371/journal.pone.0223233.e008" xlink:type="simple"/>
<mml:math display="block" id="M8">
<mml:msub><mml:mrow><mml:mi>P</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi></mml:mrow></mml:msub><mml:mo>(</mml:mo><mml:mrow><mml:mi>C</mml:mi><mml:mo>=</mml:mo><mml:mi>c</mml:mi><mml:mo>,</mml:mo><mml:mi>L</mml:mi><mml:mo>=</mml:mo><mml:mi>f</mml:mi><mml:mo>−</mml:mo><mml:mn>1</mml:mn><mml:mo>|</mml:mo><mml:mi>S</mml:mi><mml:mo>=</mml:mo><mml:mn>1</mml:mn><mml:mo>,</mml:mo><mml:mi>F</mml:mi><mml:mo>=</mml:mo><mml:mi>f</mml:mi></mml:mrow><mml:mo>)</mml:mo><mml:mo>=</mml:mo><mml:msub><mml:mrow><mml:mi>P</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi><mml:mo>+</mml:mo><mml:mn>1</mml:mn><mml:mo>−</mml:mo><mml:mi>f</mml:mi></mml:mrow></mml:msub><mml:mo>(</mml:mo><mml:mrow><mml:mi>C</mml:mi><mml:mo>=</mml:mo><mml:mi>c</mml:mi><mml:mo>−</mml:mo><mml:mn>1</mml:mn><mml:mo>|</mml:mo><mml:mi>S</mml:mi><mml:mo>=</mml:mo><mml:mn>0</mml:mn></mml:mrow><mml:mo>)</mml:mo>
</mml:math>
</alternatives>
</disp-formula>
where C = c-1 is because the crossing from f-1 to f is just before the last n+1-f observations. Similarly,
<disp-formula id="pone.0223233.e009">
<alternatives>
<graphic id="pone.0223233.e009g" mimetype="image" position="anchor" xlink:href="info:doi/10.1371/journal.pone.0223233.e009" xlink:type="simple"/>
<mml:math display="block" id="M9">
<mml:msub><mml:mrow><mml:mi>P</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi></mml:mrow></mml:msub><mml:mo>(</mml:mo><mml:mrow><mml:mi>C</mml:mi><mml:mo>=</mml:mo><mml:mi>c</mml:mi><mml:mo>,</mml:mo><mml:mi>L</mml:mi><mml:mo>=</mml:mo><mml:mi>f</mml:mi><mml:mo>−</mml:mo><mml:mn>1</mml:mn><mml:mo>|</mml:mo><mml:mi>S</mml:mi><mml:mo>=</mml:mo><mml:mn>0</mml:mn><mml:mo>,</mml:mo><mml:mi>F</mml:mi><mml:mo>=</mml:mo><mml:mi>f</mml:mi></mml:mrow><mml:mo>)</mml:mo><mml:mo>=</mml:mo><mml:msub><mml:mrow><mml:mi>P</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi><mml:mo>+</mml:mo><mml:mn>1</mml:mn><mml:mo>−</mml:mo><mml:mi>f</mml:mi></mml:mrow></mml:msub><mml:mo>(</mml:mo><mml:mrow><mml:mi>C</mml:mi><mml:mo>=</mml:mo><mml:mi>c</mml:mi><mml:mo>−</mml:mo><mml:mn>1</mml:mn><mml:mo>|</mml:mo><mml:mi>S</mml:mi><mml:mo>=</mml:mo><mml:mn>1</mml:mn></mml:mrow><mml:mo>)</mml:mo>
</mml:math>
</alternatives>
</disp-formula></p>
<p>The probabilities on the right-hand side of these formulas are for a lower number of observations and are therefore already computed in the iterative procedure.</p>
<p>Note that the n+1-f observations after the initial run start on opposite side of the centre line. Therefore, it is necessary to compute conditional probabilities conditional on starting values both above and below the centre line in the iterative procedure, they cannot be computed separately. The computations are a bit more complicated in the second case, when the initial run is the shorter part, but the main idea is the same.</p>
</sec>
<sec id="sec008">
<title>Case 2, fewer observations before the first crossing than thereafter</title>
<p>As in case 1, the total number of crossings is between 1 and n+1-f. As to the longest run L, it cannot be shorter than f-1 or longer than n+1-f, and it is necessary to distinguish between values l = f-1 and l ≥.f. A longest run f-1 in the entire sequence means that all runs in the last n+1-f observations have length l ≤ f-1. Therefore
<disp-formula id="pone.0223233.e010">
<alternatives>
<graphic id="pone.0223233.e010g" mimetype="image" position="anchor" xlink:href="info:doi/10.1371/journal.pone.0223233.e010" xlink:type="simple"/>
<mml:math display="block" id="M10">
<mml:msub><mml:mrow><mml:mi>P</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi></mml:mrow></mml:msub><mml:mo>(</mml:mo><mml:mrow><mml:mi>C</mml:mi><mml:mo>=</mml:mo><mml:mi>c</mml:mi><mml:mo>,</mml:mo><mml:mi>L</mml:mi><mml:mo>=</mml:mo><mml:mi>f</mml:mi><mml:mo>−</mml:mo><mml:mn>1</mml:mn><mml:mo>|</mml:mo><mml:mi>S</mml:mi><mml:mo>=</mml:mo><mml:mn>1</mml:mn><mml:mo>,</mml:mo><mml:mi>F</mml:mi><mml:mo>=</mml:mo><mml:mi>f</mml:mi></mml:mrow><mml:mo>)</mml:mo><mml:mo>=</mml:mo><mml:msub><mml:mrow><mml:mi>P</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi><mml:mo>+</mml:mo><mml:mn>1</mml:mn><mml:mo>−</mml:mo><mml:mi>f</mml:mi></mml:mrow></mml:msub><mml:mo>(</mml:mo><mml:mrow><mml:mi>C</mml:mi><mml:mo>=</mml:mo><mml:mi>c</mml:mi><mml:mo>−</mml:mo><mml:mn>1</mml:mn><mml:mo>,</mml:mo><mml:mi>L</mml:mi><mml:mo>≤</mml:mo><mml:mi>f</mml:mi><mml:mo>−</mml:mo><mml:mn>1</mml:mn><mml:mo>|</mml:mo><mml:mi>S</mml:mi><mml:mo>=</mml:mo><mml:mn>0</mml:mn></mml:mrow><mml:mo>)</mml:mo>
</mml:math>
</alternatives>
</disp-formula>
(and similarly conditional on S = 0). For longer runs in which f ≤ l ≤ n+1-f, the longest run has to be within the last n+1-f observations and we have
<disp-formula id="pone.0223233.e011">
<alternatives>
<graphic id="pone.0223233.e011g" mimetype="image" position="anchor" xlink:href="info:doi/10.1371/journal.pone.0223233.e011" xlink:type="simple"/>
<mml:math display="block" id="M11">
<mml:msub><mml:mrow><mml:mi>P</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi></mml:mrow></mml:msub><mml:mo>(</mml:mo><mml:mrow><mml:mi>C</mml:mi><mml:mo>=</mml:mo><mml:mi>c</mml:mi><mml:mo>,</mml:mo><mml:mi>L</mml:mi><mml:mo>=</mml:mo><mml:mi>l</mml:mi><mml:mo>|</mml:mo><mml:mi>S</mml:mi><mml:mo>=</mml:mo><mml:mn>1</mml:mn><mml:mo>,</mml:mo><mml:mi>F</mml:mi><mml:mo>=</mml:mo><mml:mi>f</mml:mi></mml:mrow><mml:mo>)</mml:mo><mml:mo>=</mml:mo><mml:msub><mml:mrow><mml:mi>P</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi><mml:mo>+</mml:mo><mml:mn>1</mml:mn><mml:mo>−</mml:mo><mml:mi>f</mml:mi></mml:mrow></mml:msub><mml:mo>(</mml:mo><mml:mrow><mml:mi>C</mml:mi><mml:mo>=</mml:mo><mml:mi>c</mml:mi><mml:mo>−</mml:mo><mml:mn>1</mml:mn><mml:mo>,</mml:mo><mml:mi>L</mml:mi><mml:mo>=</mml:mo><mml:mi>l</mml:mi><mml:mo>|</mml:mo><mml:mi>S</mml:mi><mml:mo>=</mml:mo><mml:mn>0</mml:mn></mml:mrow><mml:mo>)</mml:mo>
</mml:math>
</alternatives>
</disp-formula>
(and similarly conditional on S = 0). All these conditional probabilities, based on a shorter sequence, have already been computed in an iterative computation procedure.</p>
</sec>
<sec id="sec009">
<title>Simplifications in the symmetric case</title>
<p>For p = 0.5 there is a symmetry between crossings up or down, and between success and failure runs. Therefore, conditioning on the first observation is not necessary, although it is still necessary to partition on the first crossing F. Also, by an induction argument following the iterative procedure, all these probabilities are integer multiples of 0.5<sup><italic>n</italic>−1</sup> and, in fact, represent a partition of the binomial coefficients in the distribution of C, by the values l = 1, …, n of L.</p>
</sec>
<sec id="sec010">
<title>Precision considerations</title>
<p>To enhance precision, computations have been performed in the R package Rmpfr [<xref ref-type="bibr" rid="pone.0223233.ref006">6</xref>], an R interface to the GNU MPFR library [<xref ref-type="bibr" rid="pone.0223233.ref007">7</xref>]. Preliminary investigations pointed to precision problems above values about 50 for sequence length n without this increased precision, but no such problems up to n = 100 when using Rmpfr. To further enhance precision, probabilities are represented in the times representation, they have been multiplied by m<sup>n-1</sup> where m is a multiplier with default value 2. Thereby very small numbers are avoided, at least to some extent, and the numbers computed are integers in the symmetric case. The joint probabilities, using the times representation, in the symmetric case for n = 16 are shown in <xref ref-type="table" rid="pone.0223233.t001">Table 1</xref> below in this representation:</p>
<table-wrap id="pone.0223233.t001" position="float">
<object-id pub-id-type="doi">10.1371/journal.pone.0223233.t001</object-id>
<label>Table 1</label> <caption><title>Joint distribution in the symmetric case, n = 16.</title>
<p>Times representation.</p></caption>
<alternatives>
<graphic id="pone.0223233.t001g" mimetype="image" position="float" xlink:href="info:doi/10.1371/journal.pone.0223233.t001" xlink:type="simple"/>
<table>
<colgroup>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
</colgroup>
<thead>
<tr>
<th align="left"/>
<th align="left">l = 1</th>
<th align="left">2</th>
<th align="left">3</th>
<th align="left">4</th>
<th align="left">5</th>
<th align="left">6</th>
<th align="left">7</th>
<th align="left">8</th>
<th align="left">9</th>
<th align="left">10</th>
<th align="left">11</th>
<th align="left">12</th>
<th align="left">13</th>
<th align="left">14</th>
<th align="left">15</th>
<th align="left">16</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">c = 0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">1</td>
</tr>
<tr>
<td align="left">1</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">1</td>
<td align="left">2</td>
<td align="left">2</td>
<td align="left">2</td>
<td align="left">2</td>
<td align="left">2</td>
<td align="left">2</td>
<td align="left">2</td>
<td align="left">0</td>
</tr>
<tr>
<td align="left">2</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">6</td>
<td align="left">15</td>
<td align="left">21</td>
<td align="left">18</td>
<td align="left">15</td>
<td align="left">12</td>
<td align="left">9</td>
<td align="left">6</td>
<td align="left">3</td>
<td align="left">0</td>
<td align="left">0</td>
</tr>
<tr>
<td align="left">3</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">1</td>
<td align="left">34</td>
<td align="left">90</td>
<td align="left">106</td>
<td align="left">84</td>
<td align="left">60</td>
<td align="left">40</td>
<td align="left">24</td>
<td align="left">12</td>
<td align="left">4</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
</tr>
<tr>
<td align="left">4</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">65</td>
<td align="left">300</td>
<td align="left">370</td>
<td align="left">280</td>
<td align="left">175</td>
<td align="left">100</td>
<td align="left">50</td>
<td align="left">20</td>
<td align="left">5</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
</tr>
<tr>
<td align="left">5</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">21</td>
<td align="left">525</td>
<td align="left">960</td>
<td align="left">741</td>
<td align="left">420</td>
<td align="left">210</td>
<td align="left">90</td>
<td align="left">30</td>
<td align="left">6</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
</tr>
<tr>
<td align="left">6</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">266</td>
<td align="left">1652</td>
<td align="left">1617</td>
<td align="left">882</td>
<td align="left">392</td>
<td align="left">147</td>
<td align="left">42</td>
<td align="left">7</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
</tr>
<tr>
<td align="left">7</td>
<td align="left">0</td>
<td align="left">1</td>
<td align="left">1106</td>
<td align="left">2716</td>
<td align="left">1652</td>
<td align="left">672</td>
<td align="left">224</td>
<td align="left">56</td>
<td align="left">8</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
</tr>
<tr>
<td align="left">8</td>
<td align="left">0</td>
<td align="left">36</td>
<td align="left">2268</td>
<td align="left">2646</td>
<td align="left">1080</td>
<td align="left">324</td>
<td align="left">72</td>
<td align="left">9</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
</tr>
<tr>
<td align="left">9</td>
<td align="left">0</td>
<td align="left">210</td>
<td align="left">2640</td>
<td align="left">1605</td>
<td align="left">450</td>
<td align="left">90</td>
<td align="left">10</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
</tr>
<tr>
<td align="left">10</td>
<td align="left">0</td>
<td align="left">462</td>
<td align="left">1815</td>
<td align="left">605</td>
<td align="left">110</td>
<td align="left">11</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
</tr>
<tr>
<td align="left">11</td>
<td align="left">0</td>
<td align="left">495</td>
<td align="left">726</td>
<td align="left">132</td>
<td align="left">12</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
</tr>
<tr>
<td align="left">12</td>
<td align="left">0</td>
<td align="left">286</td>
<td align="left">156</td>
<td align="left">13</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
</tr>
<tr>
<td align="left">13</td>
<td align="left">0</td>
<td align="left">91</td>
<td align="left">14</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
</tr>
<tr>
<td align="left">14</td>
<td align="left">0</td>
<td align="left">15</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
</tr>
<tr>
<td align="left">15</td>
<td align="left">1</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
<td align="left">0</td>
</tr>
</tbody>
</table>
</alternatives>
</table-wrap>
<p>The corresponding joint probabilities are obtained by dividing these integers by 2<sup><italic>n</italic>−1</sup> = 2<sup>15</sup> = 32768, for instance <italic>P</italic><sub>16</sub>(<italic>C</italic> = 5,<italic>L</italic> = 6) = 741/32768 = 0.023. The highest joint probability is <italic>P</italic><sub>16</sub>(<italic>C</italic> = 7,<italic>L</italic> = 4) = 2716/32768 = 0.083. It is also seen that a high proportion of the joint probabilities consists of zeroes, and except for some very small numbers the joint probabilities are concentrated within a narrow sloping band, as also commented in the crossrun vignette, these are fairly general phenomena. For comparison the joint distribution for n = 16 is also shown in <xref ref-type="table" rid="pone.0223233.t002">Table 2</xref> below for p = 0.6, a case where observations tend to stay above the midline. These probabilities are still shown in the "times" representation, they are multiplied by 2<sup><italic>n</italic>−1</sup> = 32768, and are shown with one decimal digit:</p>
<table-wrap id="pone.0223233.t002" position="float">
<object-id pub-id-type="doi">10.1371/journal.pone.0223233.t002</object-id>
<label>Table 2</label> <caption><title>Joint distribution for p = 0.6, n = 16.</title>
<p>Times representation.</p>
</caption>
<alternatives>
<graphic id="pone.0223233.t002g" mimetype="image" position="float" xlink:href="info:doi/10.1371/journal.pone.0223233.t002" xlink:type="simple"/>
<table>
<colgroup>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
</colgroup>
<thead>
<tr>
<th align="left">p = 0.6</th>
<th align="left">l = 1</th>
<th align="left">2</th>
<th align="left">3</th>
<th align="left">4</th>
<th align="left">5</th>
<th align="left">6</th>
<th align="left">7</th>
<th align="left">8</th>
<th align="left">9</th>
<th align="left">10</th>
<th align="left">11</th>
<th align="left">12</th>
<th align="left">13</th>
<th align="left">14</th>
<th align="left">15</th>
<th align="left">16</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">c = 0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">9.3</td>
</tr>
<tr>
<td align="left">1</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.7</td>
<td align="left">1.6</td>
<td align="left">1.9</td>
<td align="left">2.6</td>
<td align="left">3.8</td>
<td align="left">5.6</td>
<td align="left">8.3</td>
<td align="left">12.4</td>
<td align="left">0.0</td>
</tr>
<tr>
<td align="left">2</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">7.5</td>
<td align="left">22.8</td>
<td align="left">41.2</td>
<td align="left">39.3</td>
<td align="left">37.5</td>
<td align="left">35.3</td>
<td align="left">31.9</td>
<td align="left">26.2</td>
<td align="left">16.5</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
</tr>
<tr>
<td align="left">3</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.7</td>
<td align="left">28.0</td>
<td align="left">88.6</td>
<td align="left">130.0</td>
<td align="left">121.0</td>
<td align="left">102.2</td>
<td align="left">82.8</td>
<td align="left">61.6</td>
<td align="left">38.9</td>
<td align="left">16.6</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
</tr>
<tr>
<td align="left">4</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">63.4</td>
<td align="left">337.8</td>
<td align="left">485.0</td>
<td align="left">423.3</td>
<td align="left">302.3</td>
<td align="left">202.2</td>
<td align="left">120.6</td>
<td align="left">58.5</td>
<td align="left">18.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
</tr>
<tr>
<td align="left">5</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">15.9</td>
<td align="left">451.3</td>
<td align="left">947.6</td>
<td align="left">845.0</td>
<td align="left">550.2</td>
<td align="left">323.0</td>
<td align="left">166.1</td>
<td align="left">67.6</td>
<td align="left">16.7</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
</tr>
<tr>
<td align="left">6</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">234.2</td>
<td align="left">1619.3</td>
<td align="left">1784.1</td>
<td align="left">1098.1</td>
<td align="left">557.9</td>
<td align="left">245.0</td>
<td align="left">83.5</td>
<td align="left">16.8</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
</tr>
<tr>
<td align="left">7</td>
<td align="left">0.0</td>
<td align="left">0.7</td>
<td align="left">900.4</td>
<td align="left">2439.2</td>
<td align="left">1660.7</td>
<td align="left">764.3</td>
<td align="left">295.9</td>
<td align="left">87.9</td>
<td align="left">15.2</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
</tr>
<tr>
<td align="left">8</td>
<td align="left">0.0</td>
<td align="left">28.7</td>
<td align="left">1977.6</td>
<td align="left">2518.8</td>
<td align="left">1138.4</td>
<td align="left">386.4</td>
<td align="left">99.8</td>
<td align="left">14.8</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
</tr>
<tr>
<td align="left">9</td>
<td align="left">0.0</td>
<td align="left">160.0</td>
<td align="left">2159.1</td>
<td align="left">1427.7</td>
<td align="left">444.0</td>
<td align="left">101.6</td>
<td align="left">13.2</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
</tr>
<tr>
<td align="left">10</td>
<td align="left">0.0</td>
<td align="left">369.8</td>
<td align="left">1535.6</td>
<td align="left">553.4</td>
<td align="left">111.8</td>
<td align="left">12.8</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
</tr>
<tr>
<td align="left">11</td>
<td align="left">0.0</td>
<td align="left">379.0</td>
<td align="left">582.9</td>
<td align="left">114.6</td>
<td align="left">11.7</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
</tr>
<tr>
<td align="left">12</td>
<td align="left">0.0</td>
<td align="left">223.9</td>
<td align="left">127.4</td>
<td align="left">11.5</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
</tr>
<tr>
<td align="left">13</td>
<td align="left">0.0</td>
<td align="left">68.2</td>
<td align="left">10.9</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
</tr>
<tr>
<td align="left">14</td>
<td align="left">0.0</td>
<td align="left">11.3</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
</tr>
<tr>
<td align="left">15</td>
<td align="left">0.7</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
<td align="left">0.0</td>
</tr>
</tbody>
</table>
</alternatives>
<table-wrap-foot>
<fn id="t002fn001"><p>Probabilities are multiplied by 2<sup><italic>n</italic>−1</sup> = 32768 (times representation) and shown with one decimal. Even in the times representation the probabilities are not represented with integers in non-symmetric cases.</p></fn>
</table-wrap-foot>
</table-wrap>
</sec>
</sec>
<sec id="sec011">
<title>Generalization and applications</title>
<p>The iterative procedure has been generalized to time series where the success probability may vary, as long as the observations are assumed to be independent. This is implemented in a function crossrunchange. Here, the success probability is replaced by a sequence of probabilities, one for each observation.</p>
<p>The joint distributions for the number of crossings and the longest run may be used to investigate, and possible refine, the Anhoej rules in statistical process control ([<xref ref-type="bibr" rid="pone.0223233.ref008">8</xref>], <xref ref-type="table" rid="pone.0223233.t001">Table 1</xref>). The Anhoej rules employ two tests for non-random variation in data over time:</p>
<p>Shift rule: unusually long runs of consecutive data points on the same side of the centre line. This rule is triggered if there are one or more runs longer than <italic>log</italic><sub>2</sub>(<italic>n</italic>)+3 rounded to the nearest integer, where n = the number of data points not on the median.</p>
<p>Crossings rule: the curve crosses the centre line unusually few times. This rule is triggered if there are fewer crossings than the lower 5th percentile from the cumulative binomial distribution function with a success probability of 0.5 and n-1 trials.</p>
<p>While these rules have shown to be useful, as seen when preparing our recent article [<xref ref-type="bibr" rid="pone.0223233.ref009">9</xref>] they do not have quite monotone sensitivities and specificities. For such work access to the exact joint distributions has decisive advantages compared to simulations. We are at present working on calculation of exact values of sensitivities and specificities of the Anhoej rules, and also on a modification of the rules with less variation in sensitivities and specificities. Preliminary investigations indicate that this modification may improve the practical usefulness of the Anhoej rules.</p>
<p>To illustrate the use of the joint distributions of C and L we present in <xref ref-type="table" rid="pone.0223233.t003">Table 3</xref> below the specificities of the Anhoej rules for sequence lengths between 10 and 100 in the following table.</p>
<table-wrap id="pone.0223233.t003" position="float">
<object-id pub-id-type="doi">10.1371/journal.pone.0223233.t003</object-id>
<label>Table 3</label> <caption><title>Specificities of the Anhoej rules.</title></caption>
<alternatives>
<graphic id="pone.0223233.t003g" mimetype="image" position="float" xlink:href="info:doi/10.1371/journal.pone.0223233.t003" xlink:type="simple"/>
<table>
<colgroup>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
<col align="left" valign="middle"/>
</colgroup>
<thead>
<tr>
<th align="center" colspan="11">Specificities of the Anhoej rules</th>
</tr>
<tr>
<th align="left"/>
<th align="left" colspan="10">Sequence lengths represented as tens (columns) + ones (rows)</th>
</tr>
<tr>
<th align="left"/>
<th align="left">10</th>
<th align="left">20</th>
<th align="left">30</th>
<th align="left">40</th>
<th align="left">50</th>
<th align="left">60</th>
<th align="left">70</th>
<th align="left">80</th>
<th align="left">90</th>
<th align="left">100</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">0</td>
<td align="left">0.955</td>
<td align="left">0.929</td>
<td align="left">0.936</td>
<td align="left">0.921</td>
<td align="left">0.927</td>
<td align="left">0.926</td>
<td align="left">0.908</td>
<td align="left">0.907</td>
<td align="left">0.891</td>
<td align="left">0.929</td>
</tr>
<tr>
<td align="left">1</td>
<td align="left">0.951</td>
<td align="left">0.933</td>
<td align="left">0.920</td>
<td align="left">0.910</td>
<td align="left">0.935</td>
<td align="left">0.915</td>
<td align="left">0.914</td>
<td align="left">0.898</td>
<td align="left">0.931</td>
<td align="left"/>
</tr>
<tr>
<td align="left">2</td>
<td align="left">0.957</td>
<td align="left">0.917</td>
<td align="left">0.929</td>
<td align="left">0.915</td>
<td align="left">0.923</td>
<td align="left">0.922</td>
<td align="left">0.904</td>
<td align="left">0.904</td>
<td align="left">0.922</td>
<td align="left"/>
</tr>
<tr>
<td align="left">3</td>
<td align="left">0.963</td>
<td align="left">0.952</td>
<td align="left">0.935</td>
<td align="left">0.903</td>
<td align="left">0.931</td>
<td align="left">0.911</td>
<td align="left">0.911</td>
<td align="left">0.894</td>
<td align="left">0.929</td>
<td align="left"/>
</tr>
<tr>
<td align="left">4</td>
<td align="left">0.939</td>
<td align="left">0.934</td>
<td align="left">0.922</td>
<td align="left">0.910</td>
<td align="left">0.918</td>
<td align="left">0.919</td>
<td align="left">0.916</td>
<td align="left">0.901</td>
<td align="left">0.920</td>
<td align="left"/>
</tr>
<tr>
<td align="left">5</td>
<td align="left">0.949</td>
<td align="left">0.944</td>
<td align="left">0.929</td>
<td align="left">0.897</td>
<td align="left">0.927</td>
<td align="left">0.924</td>
<td align="left">0.908</td>
<td align="left">0.906</td>
<td align="left">0.927</td>
<td align="left"/>
</tr>
<tr>
<td align="left">6</td>
<td align="left">0.953</td>
<td align="left">0.950</td>
<td align="left">0.915</td>
<td align="left">0.936</td>
<td align="left">0.933</td>
<td align="left">0.915</td>
<td align="left">0.913</td>
<td align="left">0.898</td>
<td align="left">0.933</td>
<td align="left"/>
</tr>
<tr>
<td align="left">7</td>
<td align="left">0.935</td>
<td align="left">0.936</td>
<td align="left">0.922</td>
<td align="left">0.943</td>
<td align="left">0.923</td>
<td align="left">0.921</td>
<td align="left">0.904</td>
<td align="left">0.903</td>
<td align="left">0.925</td>
<td align="left"/>
</tr>
<tr>
<td align="left">8</td>
<td align="left">0.941</td>
<td align="left">0.943</td>
<td align="left">0.908</td>
<td align="left">0.932</td>
<td align="left">0.929</td>
<td align="left">0.911</td>
<td align="left">0.910</td>
<td align="left">0.894</td>
<td align="left">0.931</td>
<td align="left"/>
</tr>
<tr>
<td align="left">9</td>
<td align="left">0.921</td>
<td align="left">0.928</td>
<td align="left">0.916</td>
<td align="left">0.939</td>
<td align="left">0.919</td>
<td align="left">0.918</td>
<td align="left">0.901</td>
<td align="left">0.900</td>
<td align="left">0.922</td>
<td align="left"/>
</tr>
</tbody>
</table>
</alternatives>
</table-wrap>
<p>The sequence lengths are represented as tens in columns and ones in rows. For instance, the specificity is 0.897 for sequence length 45 = 40+5 and 0.936 for sequence length 46. The specificities may also be estimated by extensive and complicated simulations as used in [<xref ref-type="bibr" rid="pone.0223233.ref009">9</xref>], but with lower precision.</p>
</sec>
<sec id="sec012">
<title>Limitations and planned extensions</title>
<p>There are at present two main limitations. First, in applications in statistical process control when observations are categorized as above or below a midline, the iterative procedure presupposes that the midline is determined from previous data, usually the median. If the midline is the median in the same data set the procedure does not apply since subsequent observations are no longer fully independent. Work is, however, underway to tackle this case. Briefly, the median divides the useful observations (observations not on the median, see [<xref ref-type="bibr" rid="pone.0223233.ref008">8</xref>] for details) into two parts of equal size. The useful observations are then necessarily an even number, say n = 2m, the useful observations above the median is a subset of size m, and all such subsets are equally probable. To find the number of such subsets for each combination of the number of crossing and the longest run is in fact tractable if it is generalized to all subsets, not necessarily of size m = n/2, and an iterative procedure resembling the procedure implemented in the function crossrunbin has been developed. The procedure, due to the large number of such subsets, is more demanding in terms of computation time and storage requirements, and it has so far only been possible to use it up to n = 64. Specifically, using a PC with an Intel Core i5 processor and 8 GB RAM computation times for n = 10, 20 and 40 were 3 seconds, 27 seconds and 9 minutes and storage requirements were 9 kB, 107 kB and 2MB, respectively. Preliminary investigations seem to indicate that the difference from the case of a predetermined midline is smaller for longer sequences. A function crossrunem has been written for this case and is planned for inclusion in an update of the package crossrun.</p>
<p>Another important limitation is that the iterative procedure does not apply for autocorrelated time series. Here also, work is in progress in a simple autocorrelation model in which the probabilities of "success" and "failure" in each observation may depend on the previous observation only, and a function crossrunauto is planned for inclusion in a future update. The practical value of this procedure is likely to be limited since decision rules based on the number of crossings and the longest run are probably not particularly useful for autocorrelated series, but at least the procedure may be used to investigate the extent of the problem.</p>
<p>A third limitation is that the code has so far only been checked for small n. For applications in statistical process control this should not be a problem, therefore details above, and in the crossrun vignette, stop at n = 100. We have now extended the computations up to n = 200 both in the symmetric case and for probability 0.8, and the procedure seems to work well, except that it was necessary to increase the mpfr precision parameter from the default value of 120 to 240 bits. Then the marginal distributions of <italic>C</italic> in the symmetric case agreed completely with the binomial coefficients for all n up to 200. The sum of the joint distribution for probability 0.8, in the times representation, agreed with 2<sup><italic>n</italic>−1</sup>, with discrepancies in the 11. decimal or smaller. It was also checked, both in the symmetric case and for probability 0.8, that the mean of C·L, an example of a demanding calculation, agreed well with simulation results for n = 200. Details are included at the end of the article script. Still, as expected this points to increasing precision demands for obtaining accurate joint distributions for longer sequences. The procedures implemented in crossrun are therefore not likely to be practically feasible for applications that require very long sequences.</p>
</sec>
<sec id="sec013" sec-type="conclusions">
<title>Conclusions</title>
<p>The crossrun package includes functions for computing the probabilities of the joint distribution of longest run and number of crossings in random data series. To our knowledge, this distribution has not been studied before.</p>
<p>The ability to calculate exact probabilities for the joint distribution allows for the development of better prediction limits for longest run and crossings in random data series. In turn, this allows for better separation of signal and noise, i.e. random and non-random variation in statistical process control and possibly also in other areas of application.</p>
</sec>
<sec id="sec014">
<title>Appendix 1: Details on the times representation</title>
<p>The times representation of the joint distribution is defined as
<disp-formula id="pone.0223233.e012">
<alternatives>
<graphic id="pone.0223233.e012g" mimetype="image" position="anchor" xlink:href="info:doi/10.1371/journal.pone.0223233.e012" xlink:type="simple"/>
<mml:math display="block" id="M12">
<mml:msub><mml:mrow><mml:mi mathvariant="normal">Pt</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi></mml:mrow></mml:msub><mml:mo>(</mml:mo><mml:mrow><mml:mi>C</mml:mi><mml:mo>=</mml:mo><mml:mi>c</mml:mi><mml:mo>,</mml:mo><mml:mi>L</mml:mi><mml:mo>=</mml:mo><mml:mi>l</mml:mi><mml:mo>|</mml:mo><mml:mi>S</mml:mi><mml:mo>=</mml:mo><mml:mn>1</mml:mn></mml:mrow><mml:mo>)</mml:mo><mml:mo>=</mml:mo><mml:msup><mml:mrow><mml:mi>m</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi><mml:mo>−</mml:mo><mml:mn>1</mml:mn></mml:mrow></mml:msup><mml:mo>·</mml:mo><mml:msub><mml:mrow><mml:mi>P</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi></mml:mrow></mml:msub><mml:mo>(</mml:mo><mml:mrow><mml:mi>C</mml:mi><mml:mo>=</mml:mo><mml:mi>c</mml:mi><mml:mo>,</mml:mo><mml:mi>L</mml:mi><mml:mo>=</mml:mo><mml:mi>l</mml:mi><mml:mo>|</mml:mo><mml:mi>S</mml:mi><mml:mo>=</mml:mo><mml:mn>1</mml:mn></mml:mrow><mml:mo>)</mml:mo>
</mml:math>
</alternatives>
</disp-formula>
where m is a multiplier normally set as m = 2. The case of conditioning on S = 0, starting below the midline, is similar. Denoting the success probability as p and the failure probability as q = 1-p the main decomposition for probabilities is
<disp-formula id="pone.0223233.e013">
<alternatives>
<graphic id="pone.0223233.e013g" mimetype="image" position="anchor" xlink:href="info:doi/10.1371/journal.pone.0223233.e013" xlink:type="simple"/>
<mml:math display="block" id="M13">
<mml:mtable><mml:mtr><mml:mtd><mml:msub><mml:mrow><mml:mi>P</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi></mml:mrow></mml:msub><mml:mo>(</mml:mo><mml:mrow><mml:mi>C</mml:mi><mml:mo>=</mml:mo><mml:mi>c</mml:mi><mml:mo>,</mml:mo><mml:mi>L</mml:mi><mml:mo>=</mml:mo><mml:mi>l</mml:mi><mml:mo>|</mml:mo><mml:mi>S</mml:mi><mml:mo>=</mml:mo><mml:mn>1</mml:mn></mml:mrow><mml:mo>)</mml:mo><mml:mo>=</mml:mo><mml:msup><mml:mrow><mml:mi>p</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi><mml:mo>−</mml:mo><mml:mn>1</mml:mn></mml:mrow></mml:msup><mml:mo>·</mml:mo><mml:msub><mml:mrow><mml:mi>P</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi></mml:mrow></mml:msub><mml:mo>(</mml:mo><mml:mrow><mml:mi>C</mml:mi><mml:mo>=</mml:mo><mml:mi>c</mml:mi><mml:mo>,</mml:mo><mml:mi>L</mml:mi><mml:mo>=</mml:mo><mml:mi>l</mml:mi><mml:mo>|</mml:mo><mml:mi>S</mml:mi><mml:mo>=</mml:mo><mml:mn>1</mml:mn><mml:mo>,</mml:mo><mml:mi>F</mml:mi><mml:mo>=</mml:mo><mml:mn>1</mml:mn></mml:mrow><mml:mo>)</mml:mo><mml:mo>+</mml:mo></mml:mtd></mml:mtr><mml:mtr><mml:mtd><mml:mrow><mml:mstyle displaystyle="true"><mml:munderover><mml:mo>∑</mml:mo><mml:mrow><mml:mi>f</mml:mi><mml:mo>=</mml:mo><mml:mn>2</mml:mn></mml:mrow><mml:mrow><mml:mi>n</mml:mi></mml:mrow></mml:munderover></mml:mstyle><mml:mrow><mml:msup><mml:mrow><mml:mi>p</mml:mi></mml:mrow><mml:mrow><mml:mi>f</mml:mi><mml:mo>−</mml:mo><mml:mn>2</mml:mn></mml:mrow></mml:msup><mml:mo>·</mml:mo><mml:mi>q</mml:mi><mml:mo>·</mml:mo><mml:msub><mml:mrow><mml:mi>P</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi></mml:mrow></mml:msub><mml:mo>(</mml:mo><mml:mrow><mml:mi>C</mml:mi><mml:mo>=</mml:mo><mml:mi>c</mml:mi><mml:mo>,</mml:mo><mml:mi>L</mml:mi><mml:mo>=</mml:mo><mml:mi>l</mml:mi><mml:mo>|</mml:mo><mml:mi>S</mml:mi><mml:mo>=</mml:mo><mml:mn>1</mml:mn><mml:mo>,</mml:mo><mml:mi>F</mml:mi><mml:mo>=</mml:mo><mml:mi>f</mml:mi></mml:mrow><mml:mo>)</mml:mo></mml:mrow></mml:mrow></mml:mtd></mml:mtr></mml:mtable>
</mml:math>
</alternatives>
</disp-formula>
where the first term conditions on F = 1, by convention corresponding to no crossing, and each of the remaining terms conditions on F = f, f = 2, …, n corresponding to the first crossing from f-1 to f. The corresponding decomposition in the times representation may be written as
<disp-formula id="pone.0223233.e014">
<alternatives>
<graphic id="pone.0223233.e014g" mimetype="image" position="anchor" xlink:href="info:doi/10.1371/journal.pone.0223233.e014" xlink:type="simple"/>
<mml:math display="block" id="M14">
<mml:mtable><mml:mtr><mml:mtd><mml:msub><mml:mrow><mml:mi mathvariant="normal">Pt</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi></mml:mrow></mml:msub><mml:mo>(</mml:mo><mml:mrow><mml:mi>C</mml:mi><mml:mo>=</mml:mo><mml:mi>c</mml:mi><mml:mo>,</mml:mo><mml:mi>L</mml:mi><mml:mo>=</mml:mo><mml:mi>l</mml:mi><mml:mo>|</mml:mo><mml:mi>S</mml:mi><mml:mo>=</mml:mo><mml:mn>1</mml:mn></mml:mrow><mml:mo>)</mml:mo><mml:mo>=</mml:mo></mml:mtd></mml:mtr><mml:mtr><mml:mtd><mml:mrow><mml:mstyle displaystyle="true"><mml:munderover><mml:mo>∑</mml:mo><mml:mrow><mml:mi>f</mml:mi><mml:mo>=</mml:mo><mml:mn>2</mml:mn></mml:mrow><mml:mrow><mml:mi>n</mml:mi></mml:mrow></mml:munderover></mml:mstyle><mml:mrow><mml:mo>(</mml:mo><mml:mi>p</mml:mi><mml:mi>m</mml:mi><mml:msup><mml:mrow><mml:mo>)</mml:mo></mml:mrow><mml:mrow><mml:mi>f</mml:mi><mml:mo>−</mml:mo><mml:mn>2</mml:mn></mml:mrow></mml:msup><mml:mo>·</mml:mo><mml:mi>q</mml:mi><mml:mi>m</mml:mi><mml:mo>·</mml:mo><mml:msup><mml:mrow><mml:mi>m</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi><mml:mo>−</mml:mo><mml:mi>f</mml:mi></mml:mrow></mml:msup><mml:mo>·</mml:mo><mml:msub><mml:mrow><mml:mi>P</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi></mml:mrow></mml:msub><mml:mo>(</mml:mo><mml:mi>C</mml:mi><mml:mo>=</mml:mo><mml:mi>c</mml:mi><mml:mo>,</mml:mo><mml:mi>L</mml:mi><mml:mo>=</mml:mo><mml:mi>l</mml:mi><mml:mo>∣</mml:mo><mml:mi>S</mml:mi><mml:mo>=</mml:mo><mml:mn>1</mml:mn><mml:mo>,</mml:mo><mml:mi>F</mml:mi><mml:mo>=</mml:mo><mml:mi>f</mml:mi><mml:mo>)</mml:mo></mml:mrow></mml:mrow></mml:mtd></mml:mtr></mml:mtable>
</mml:math>
</alternatives>
</disp-formula></p>
<p>In the first term for no crossing the probability is simply 1 if C = 0, L = n, and 0 otherwise. This term is the same in the times representation except for the initial factor in which <italic>p</italic><sup><italic>n</italic>−1</sup> is replaced by (<italic>pm</italic>)<sup><italic>n</italic>−1</sup>. In the symmetric case both pm and qm are equal to 1, thus the initial factor is 1 and the term as a whole is actually simpler in the times representation in the symmetric case.</p>
<p>In the remaining terms, for the first crossing from f-1 to f, there is first a factor that is similar to the corresponding factor in the original representation, except that p is replaced by pm and q by qm. Again, this first factor is actually equal to 1 in the symmetric case. The rest of the term is <italic>m</italic><sup><italic>n</italic>−<italic>f</italic></sup>·<italic>P</italic><sub><italic>n</italic></sub>(<italic>C</italic> = <italic>c</italic>,<italic>L</italic> = <italic>l</italic>|<italic>S</italic> = 1,<italic>F</italic> = <italic>f</italic>). As shown previously, the probabilities <italic>P</italic><sub><italic>n</italic></sub>(<italic>C</italic> = <italic>c</italic>,<italic>L</italic> = <italic>l</italic>|<italic>S</italic> = 1,<italic>F</italic> = <italic>f</italic>) are determined by the joint distribution <italic>P</italic><sub><italic>n</italic>+1−<italic>f</italic></sub>(<italic>C</italic> = <italic>c</italic>′,<italic>L</italic> = <italic>l</italic>′|<italic>S</italic> = 0) for the observations starting at the end of the first crossing. Here we condition on the opposite starting value S = 0 since this last part of the sequence starts just where the first crossing has occurred. As to the main part of the term <italic>P</italic><sub><italic>n</italic></sub>(<italic>C</italic> = <italic>c</italic>,<italic>L</italic> = <italic>l</italic>|<italic>S</italic> = 1,<italic>F</italic> = <italic>f</italic>) we more specifically have seen that it is determined by the joint distribution <italic>P</italic><sub><italic>n</italic>+1−<italic>f</italic></sub>(<italic>C</italic> = <italic>c</italic>′,<italic>L</italic> = <italic>l</italic>′|<italic>S</italic> = 0) by simple operations in terms of additions and reshuffling only. The corresponding joint distribution in the times representation is
<disp-formula id="pone.0223233.e015">
<alternatives>
<graphic id="pone.0223233.e015g" mimetype="image" position="anchor" xlink:href="info:doi/10.1371/journal.pone.0223233.e015" xlink:type="simple"/>
<mml:math display="block" id="M15">
<mml:msub><mml:mrow><mml:mi mathvariant="normal">Pt</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi><mml:mo>+</mml:mo><mml:mn>1</mml:mn><mml:mo>−</mml:mo><mml:mi>f</mml:mi></mml:mrow></mml:msub><mml:mo>(</mml:mo><mml:mrow><mml:mi>C</mml:mi><mml:mo>=</mml:mo><mml:mi>c</mml:mi><mml:mo>′</mml:mo><mml:mo>,</mml:mo><mml:mi>L</mml:mi><mml:mo>=</mml:mo><mml:mi>l</mml:mi><mml:mo>′</mml:mo><mml:mo>|</mml:mo><mml:mi>S</mml:mi><mml:mo>=</mml:mo><mml:mn>0</mml:mn></mml:mrow><mml:mo>)</mml:mo><mml:mo>=</mml:mo><mml:msup><mml:mrow><mml:mi>m</mml:mi></mml:mrow><mml:mrow><mml:mo>(</mml:mo><mml:mrow><mml:mi>n</mml:mi><mml:mo>+</mml:mo><mml:mn>1</mml:mn><mml:mo>−</mml:mo><mml:mi>f</mml:mi></mml:mrow><mml:mo>)</mml:mo><mml:mo>−</mml:mo><mml:mn>1</mml:mn></mml:mrow></mml:msup><mml:mo>·</mml:mo><mml:msub><mml:mrow><mml:mi>P</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi><mml:mo>+</mml:mo><mml:mn>1</mml:mn><mml:mo>−</mml:mo><mml:mi>f</mml:mi></mml:mrow></mml:msub><mml:mo>(</mml:mo><mml:mrow><mml:mi>C</mml:mi><mml:mo>=</mml:mo><mml:mi>c</mml:mi><mml:mo>′</mml:mo><mml:mo>,</mml:mo><mml:mi>L</mml:mi><mml:mo>=</mml:mo><mml:mi>l</mml:mi><mml:mo>′</mml:mo><mml:mo>|</mml:mo><mml:mi>S</mml:mi><mml:mo>=</mml:mo><mml:mn>0</mml:mn></mml:mrow><mml:mo>)</mml:mo>
</mml:math>
</alternatives>
</disp-formula>
where the leading factor <italic>m</italic><sup>(<italic>n</italic>+1−<italic>f</italic>)−1</sup> = <italic>m</italic><sup><italic>n</italic>−<italic>f</italic></sup> is exactly the same as the leading factor in <italic>m</italic><sup><italic>n</italic>−<italic>f</italic></sup>·<italic>P</italic><sub><italic>n</italic></sub>(<italic>C</italic> = <italic>c</italic>,<italic>L</italic> = <italic>l</italic>|<italic>S</italic> = 1,<italic>F</italic> = <italic>f</italic>). Therefore, the term
<disp-formula id="pone.0223233.e016">
<alternatives>
<graphic id="pone.0223233.e016g" mimetype="image" position="anchor" xlink:href="info:doi/10.1371/journal.pone.0223233.e016" xlink:type="simple"/>
<mml:math display="block" id="M16">
<mml:msup><mml:mrow><mml:mi>m</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi><mml:mo>−</mml:mo><mml:mi>f</mml:mi></mml:mrow></mml:msup><mml:mo>·</mml:mo><mml:msub><mml:mrow><mml:mi>P</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi></mml:mrow></mml:msub><mml:mo>(</mml:mo><mml:mrow><mml:mi>C</mml:mi><mml:mo>=</mml:mo><mml:mi>c</mml:mi><mml:mo>,</mml:mo><mml:mi>L</mml:mi><mml:mo>=</mml:mo><mml:mi>l</mml:mi><mml:mo>|</mml:mo><mml:mi>S</mml:mi><mml:mo>=</mml:mo><mml:mn>1</mml:mn><mml:mo>,</mml:mo><mml:mi>F</mml:mi><mml:mo>=</mml:mo><mml:mi>f</mml:mi></mml:mrow><mml:mo>)</mml:mo>
</mml:math>
</alternatives>
</disp-formula>
is determined by the joint distribution
<disp-formula id="pone.0223233.e017">
<alternatives>
<graphic id="pone.0223233.e017g" mimetype="image" position="anchor" xlink:href="info:doi/10.1371/journal.pone.0223233.e017" xlink:type="simple"/>
<mml:math display="block" id="M17">
<mml:msub><mml:mrow><mml:mi mathvariant="normal">Pt</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi><mml:mo>+</mml:mo><mml:mn>1</mml:mn><mml:mo>−</mml:mo><mml:mi>f</mml:mi></mml:mrow></mml:msub><mml:mo>(</mml:mo><mml:mrow><mml:mi>C</mml:mi><mml:mo>=</mml:mo><mml:mi>c</mml:mi><mml:mo>′</mml:mo><mml:mo>,</mml:mo><mml:mi>L</mml:mi><mml:mo>=</mml:mo><mml:mi>l</mml:mi><mml:mo>′</mml:mo><mml:mo>|</mml:mo><mml:mi>S</mml:mi><mml:mo>=</mml:mo><mml:mn>0</mml:mn></mml:mrow><mml:mo>)</mml:mo>
</mml:math>
</alternatives>
</disp-formula>
on the times scale by exactly the same additions and reshufflings as apply on the original probability scale.</p>
</sec>
<sec id="sec015">
<title>Appendix 2: R code for the iteration procedure</title>
<p>The iterative procedure is coded in the function crossrunbin, and is available by typing</p>
<p>library(crossrun)</p>
<p>?crossrunbin</p>
<p>within R, after having installed the package crossrun. R code for all analyses in this article is available in the <xref ref-type="supplementary-material" rid="pone.0223233.s001">S1 File</xref> crossrunart.R. The R packages Rmpfr and crossrun should have been installed before running these analyses.</p>
</sec>
<sec id="sec016">
<title>Supporting information</title>
<supplementary-material id="pone.0223233.s001" position="float" xlink:href="info:doi/10.1371/journal.pone.0223233.s001" xlink:type="simple">
<label>S1 File</label>
<caption>
<title>R script for all analyses in the article.</title>
<p>(R)</p>
</caption>
</supplementary-material>
</sec>
</body>
<back>
<ref-list>
<title>References</title>
<ref id="pone.0223233.ref001"><label>1</label><mixed-citation publication-type="journal" xlink:type="simple"><name name-style="western"><surname>Anhøj</surname> <given-names>J</given-names></name>. <article-title>Diagnostic Value of Run Chart Analysis: Using Likelihood Ratios to Compare Run Chart Rules on Simulated Data Series</article-title>. <source>PLos ONE</source> <year>2015</year>. <month>Mar</month> <day>23</day>; <volume>10</volume>(<issue>3</issue>): <fpage>e0121349</fpage>. <ext-link ext-link-type="uri" xlink:href="https://doi.org/10.1371/journal.pone.0121349" xlink:type="simple">https://doi.org/10.1371/journal.pone.0121349</ext-link> <object-id pub-id-type="pmid">25799549</object-id></mixed-citation></ref>
<ref id="pone.0223233.ref002"><label>2</label><mixed-citation publication-type="other" xlink:type="simple">R Core Team (2014) R: A language and Environment for Statistical Computing. Version 3.6.0 or higher [software]. 2019 Apr 26. Available from <ext-link ext-link-type="uri" xlink:href="http://www.R-project.org/" xlink:type="simple">http://www.R-project.org/</ext-link></mixed-citation></ref>
<ref id="pone.0223233.ref003"><label>3</label><mixed-citation publication-type="other" xlink:type="simple">Wentzel-Larsen T, Anhøj J. crossrun: Joint Distribution of Number of Crossings and Longest Run. Version 0.1.0. [software]. 2018 Oct 10. Available from <ext-link ext-link-type="uri" xlink:href="https://CRAN.R-project.org/package=crossrun" xlink:type="simple">https://CRAN.R-project.org/package=crossrun</ext-link></mixed-citation></ref>
<ref id="pone.0223233.ref004"><label>4</label><mixed-citation publication-type="journal" xlink:type="simple"><name name-style="western"><surname>Schilling</surname> <given-names>MF</given-names></name>. <article-title>The Surprising Predictability of Long Runs</article-title>. <source>Mathematics Magazine</source>. <year>2012</year>. <month>Dec</month> <day>22</day>; <volume>85</volume> (<issue>2</issue>): <ext-link ext-link-type="uri" xlink:href="https://www.jstor.org/stable/10.4169/math.mag.85.2.141" xlink:type="simple">https://www.jstor.org/stable/10.4169/math.mag.85.2.141</ext-link></mixed-citation></ref>
<ref id="pone.0223233.ref005"><label>5</label><mixed-citation publication-type="journal" xlink:type="simple"><name name-style="western"><surname>Fazekas</surname> <given-names>I</given-names></name>, <name name-style="western"><surname>Karácsony</surname> <given-names>Z</given-names></name>, <name name-style="western"><surname>Libor</surname> <given-names>Z</given-names></name>. <article-title>Longest runs in coin tossing. Comparison of recursive formulae, asymptotic theorems, computer simulations</article-title>. <source>Acta Universitatis Sapientiae. Mathematica</source>. <year>2010</year> <month>Jan</month>; <volume>2</volume> (<issue>2</issue>): <fpage>215</fpage>–<lpage>228</lpage>. <ext-link ext-link-type="uri" xlink:href="https://www.researchgate.net/publication/266954746_Longest_runs_in_coin_tossing_Comparison_of_recursive_formulae_asymptotic_theorems_computer_simulations" xlink:type="simple">https://www.researchgate.net/publication/266954746_Longest_runs_in_coin_tossing_Comparison_of_recursive_formulae_asymptotic_theorems_computer_simulations</ext-link></mixed-citation></ref>
<ref id="pone.0223233.ref006"><label>6</label><mixed-citation publication-type="other" xlink:type="simple">Maechler M. Rmpfr: R MPFR—Multiple Precision Floating-Point Reliable. Version 0.7–1 or higher [software]. 2018 Jul. <ext-link ext-link-type="uri" xlink:href="https://CRAN.R-project.org/package=Rmpfr" xlink:type="simple">https://CRAN.R-project.org/package=Rmpfr</ext-link></mixed-citation></ref>
<ref id="pone.0223233.ref007"><label>7</label><mixed-citation publication-type="other" xlink:type="simple">Hanrot G, Lefèvre V, Pélissier P, Théveny P, Zimmermann P. The MPFR Library Version 4.0.2 or higher. [software]. 2019 Jan 31.</mixed-citation></ref>
<ref id="pone.0223233.ref008"><label>8</label><mixed-citation publication-type="journal" xlink:type="simple"><name name-style="western"><surname>Anhøj</surname> <given-names>J</given-names></name>, <name name-style="western"><surname>Olesen</surname> <given-names>AV</given-names></name>. <article-title>Run charts revisited: A simulation study of run chart rules for detection of non-random variation in health care processes</article-title>. <source>PLoS ONE</source>. <year>2014</year> <month>Nov</month> <day>25</day>; <volume>9</volume>(<issue>11</issue>): <fpage>e113825</fpage>. <ext-link ext-link-type="uri" xlink:href="https://doi.org/10.1371/journal.pone.0113825" xlink:type="simple">https://doi.org/10.1371/journal.pone.0113825</ext-link> <object-id pub-id-type="pmid">25423037</object-id></mixed-citation></ref>
<ref id="pone.0223233.ref009"><label>9</label><mixed-citation publication-type="journal" xlink:type="simple"><name name-style="western"><surname>Anhøj</surname> <given-names>J</given-names></name>, <name name-style="western"><surname>Wentzel-Larsen</surname> <given-names>T</given-names></name>. <article-title>Sense and sensibility: on the diagnostic value of control chart rules for detection of shifts in time series data</article-title>. <source>BMC Medical Research Methodology</source>. <month>Oct</month> <day>3</day>; <volume>18</volume>(<issue>1</issue>): <fpage>100</fpage>. <ext-link ext-link-type="uri" xlink:href="https://doi.org/10.1186/s12874-018-0564-0" xlink:type="simple">https://doi.org/10.1186/s12874-018-0564-0</ext-link> <object-id pub-id-type="pmid">30285737</object-id></mixed-citation></ref>
</ref-list>
</back>
</article>