<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Isaac Land</title>
    <description>The latest articles on DEV Community by Isaac Land (@landisaac1).</description>
    <link>https://dev.to/landisaac1</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4195271%2Fa19dce13-7ab3-47f9-aeca-1992c37c4838.png</url>
      <title>DEV Community: Isaac Land</title>
      <link>https://dev.to/landisaac1</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/landisaac1"/>
    <language>en</language>
    <item>
      <title>Taking a Research Script through MIT’s Missing Semester</title>
      <dc:creator>Isaac Land</dc:creator>
      <pubDate>Tue, 01 Dec 2026 03:00:00 +0000</pubDate>
      <link>https://dev.to/landisaac1/taking-a-research-script-through-mits-missing-semester-2e74</link>
      <guid>https://dev.to/landisaac1/taking-a-research-script-through-mits-missing-semester-2e74</guid>
      <description>&lt;h1&gt;
  
  
  Taking a Research Script through MIT’s Missing Semester
&lt;/h1&gt;

&lt;p&gt;A researcher can fit a regression and draw a figure but still produce a script that knows where the data live only on its author's computer. A changed directory breaks the run, and a slowdown has no obvious location. MIT's Missing Semester focuses on these everyday computational skills. One small research script can connect the lectures to an actual handover.[1]&lt;/p&gt;

&lt;h2&gt;
  
  
  Put nine sessions back into one workflow
&lt;/h2&gt;

&lt;p&gt;The 2026 edition ran from January 12 to 23 and was co-taught by Anish, Jon and Jose. The opening sessions cover the shell, command-line environment, and development environments and tools. Take a non-sensitive table and the script that reads it. Specify the working directory, input and output. Repeat from a different directory using only your notes. Having to ask where a file lives identifies an immediate gap in the instructions.[1]&lt;/p&gt;

&lt;p&gt;The January 15 lecture separates debugging from profiling. An incorrect result calls for locating the first stage at which a value goes wrong; a correct but slow result calls for measuring where execution time is spent. Keep outputs from the same input before and after an optimization so a faster calculation does not quietly become a different one. Searchable notes complement the lecture recording when only a particular technique is needed.[1][2]&lt;/p&gt;

&lt;p&gt;&lt;a href="/article-media/483836e43fd212bdf64c3fd86c826442cf946d03fa31de23a2e84433cf9084d0.webp" class="article-body-image-wrapper"&gt;&lt;img src="/article-media/483836e43fd212bdf64c3fd86c826442cf946d03fa31de23a2e84433cf9084d0.webp" alt="Nine January sessions span the shell to code quality"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure: The nine teaching dates in the 2026 edition.&lt;/p&gt;

&lt;p&gt;Version control and Git follow on January 16, and packaging and shipping on January 20. Record the version that first worked for a colleague, along with the example input and expected result. Then try the instructions in a clean environment. A usable history and an installable environment answer different questions about the same delivery.[1]&lt;/p&gt;

&lt;h2&gt;
  
  
  Read the AI material in context
&lt;/h2&gt;

&lt;p&gt;January 21 covers Agentic Coding, followed by Beyond the Code and Code Quality. Applicable AI tools also appear throughout the other sessions. Choose a bounded exercise such as making a figure's output path configurable. Inspect the proposed change, rerun the original case and compare the outputs. This tests the resulting work rather than the plausibility of an assistant's explanation.[1][3]&lt;/p&gt;

&lt;h2&gt;
  
  
  Leave a handover someone can use
&lt;/h2&gt;

&lt;p&gt;The syllabus links notes, videos and previous editions. Older special topics need not share the numbering of the current course. An experienced researcher can begin at a recurring bottleneck, while a beginner can take the first three sessions in sequence. The material carries a Creative Commons attribution, noncommercial and share-alike license. For a research-group exercise, share the course link and bring different real scripts. The final check is whether a colleague can find the inputs, run the specified version, compare the result and notice a subsequent regression.[1][2]&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;[1] &lt;a href="https://missing.csail.mit.edu/" rel="noopener noreferrer"&gt;The Missing Semester of Your CS Education. 2026 syllabus&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;[2] &lt;a href="https://missing.csail.mit.edu/2026/debugging-profiling/" rel="noopener noreferrer"&gt;The Missing Semester. Debugging and Profiling&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;[3] &lt;a href="https://missing.csail.mit.edu/2026/agentic-coding/" rel="noopener noreferrer"&gt;The Missing Semester. Agentic Coding&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;Originally published at &lt;a href="https://enter.scholay.com/en/news/d15b1c3a867bc033ef7dd2efde4c5f71/" rel="noopener noreferrer"&gt;EnterScholar&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.scholay.com" rel="noopener noreferrer"&gt;Scholay&lt;/a&gt; · &lt;a href="https://www.enterscholar.com" rel="noopener noreferrer"&gt;EnterScholar&lt;/a&gt;&lt;/p&gt;

</description>
      <category>cli</category>
      <category>computerscience</category>
      <category>education</category>
      <category>learning</category>
    </item>
    <item>
      <title>How the central limit theorem explains why sample means tend towards a normal distribution</title>
      <dc:creator>Isaac Land</dc:creator>
      <pubDate>Mon, 30 Nov 2026 11:00:00 +0000</pubDate>
      <link>https://dev.to/landisaac1/how-the-central-limit-theorem-explains-why-sample-means-tend-towards-a-normal-distribution-5a03</link>
      <guid>https://dev.to/landisaac1/how-the-central-limit-theorem-explains-why-sample-means-tend-towards-a-normal-distribution-5a03</guid>
      <description>&lt;h1&gt;
  
  
  How the central limit theorem explains why sample means tend towards a normal distribution
&lt;/h1&gt;

&lt;p&gt;Draw a sample of size n from a population again and again, and compute the mean each time: those means form a distribution of their own, the sampling distribution of the mean. The central limit theorem says that as long as the observations are independent, come from the same distribution and the population variance is finite, this sampling distribution is approximately normal for large n, centred on the population mean μ with variance σ²/n, whatever the shape of the population [1]. That is why confidence intervals and tests built on the normal distribution work for so much data that is not normal itself [1].&lt;/p&gt;

&lt;h2&gt;
  
  
  What the theorem says
&lt;/h2&gt;

&lt;p&gt;The classical version is the Lindeberg–Lévy central limit theorem: if X₁, X₂, … are independent and identically distributed with mean μ and finite variance σ², then as n goes to infinity, √n(X̄ₙ − μ) converges in distribution to a normal distribution with mean 0 and variance σ² [1]. Put more practically: for large n, the sample mean X̄ₙ is close to normal with mean μ and variance σ²/n.&lt;/p&gt;

&lt;p&gt;It and the law of large numbers describe two layers of the same thing. The law of large numbers says the sample mean tends to μ; the central limit theorem goes further and describes how large the fluctuations around μ are and what shape they take: their scale shrinks like 1/√n and their shape tends to the normal [1]. σ/√n is the familiar standard error of the mean.&lt;/p&gt;

&lt;h2&gt;
  
  
  An example that can be computed exactly
&lt;/h2&gt;

&lt;p&gt;Take a clearly skewed population: the exponential distribution with mean 1, whose standard deviation is also 1 and skewness 2. The sum of n independent exponential variables follows a gamma distribution, so the distribution of the sample mean can be written down exactly, with no simulation. The figure sets the exact distribution (solid) against the normal approximation N(1, 1/n) from the central limit theorem (dashed).&lt;/p&gt;

&lt;p&gt;&lt;a href="/article-media/5fa332a13ab53e6ceeec6b6ad0029d74a64c011c34307a0abf4d04f6a60baf96.png" class="article-body-image-wrapper"&gt;&lt;img src="/article-media/5fa332a13ab53e6ceeec6b6ad0029d74a64c011c34307a0abf4d04f6a60baf96.png" alt="Four panels: the mean turns normal as n grows to 30"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure: Sample mean from an exponential population, exact distribution against the normal approximation.&lt;/p&gt;

&lt;p&gt;At n = 1 it is the exponential distribution itself, far from the normal curve; at n = 5 a single peak has formed but a right tail remains; at n = 30 the two curves nearly coincide. The skewness fades, but not fast: here the skewness of the sample mean is 2/√n, about 0.37 at n = 30 and 0.20 at n = 100.&lt;/p&gt;

&lt;p&gt;The tails tell more. A normal interval such as "mean ± 1.96 standard errors" should leave 2.5% outside on each side. Computed from the exact distribution, the actual probabilities are:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Sample size n&lt;/th&gt;
&lt;th&gt;Above μ + 1.96σ/√n&lt;/th&gt;
&lt;th&gt;Below μ − 1.96σ/√n&lt;/th&gt;
&lt;th&gt;Both sides&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;4.33%&lt;/td&gt;
&lt;td&gt;0.04%&lt;/td&gt;
&lt;td&gt;4.38%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;td&gt;3.93%&lt;/td&gt;
&lt;td&gt;0.58%&lt;/td&gt;
&lt;td&gt;4.51%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;30&lt;/td&gt;
&lt;td&gt;3.40%&lt;/td&gt;
&lt;td&gt;1.40%&lt;/td&gt;
&lt;td&gt;4.81%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;td&gt;3.02%&lt;/td&gt;
&lt;td&gt;1.92%&lt;/td&gt;
&lt;td&gt;4.94%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The two sides together are already close to 5%, but they are far from even: at n = 30 the right side is still more than twice the left. The normal approximation improves quickly in the middle of the distribution, while the tails need many more observations to catch up [1]. A two-sided interval may look fine in total; one-sided tests and one-sided intervals are affected much more.&lt;/p&gt;

&lt;h2&gt;
  
  
  When the theorem holds
&lt;/h2&gt;

&lt;p&gt;First, independence. The classical version also requires identical distributions; the Lyapunov and Lindeberg versions relax this to independent but not necessarily identical variables, roughly on condition that each term is small relative to the total spread, so that no single term dominates the sum [1]. For dependent data such as time series there are versions under weak dependence (mixing), but the limiting variance has to include the covariances between periods [1].&lt;/p&gt;

&lt;p&gt;Second, finite variance, which cannot be dropped. The standard Cauchy distribution has neither a mean nor a variance, and the average of n independent standard Cauchy variables is again standard Cauchy: it never concentrates, however many draws you take [2]. Heavy-tailed cases like this belong to the generalized central limit theorem, under which a limit of standardized sums, if it exists, is a stable distribution, of which the normal is only one [1][2].&lt;/p&gt;

&lt;p&gt;Third, the speed of convergence. The theorem only gives a limit and does not say how large n must be. If the third central moment of the population is finite, the Berry–Esseen theorem guarantees that the error of the normal approximation shrinks at least as fast as 1/√n [1]; the more skewed and heavy-tailed the population, the larger the sample needed, and the example above gives a feel for the scale.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two common misreadings
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Thinking that large samples make the data themselves normal.&lt;/strong&gt; The theorem is about the distribution of means (or sums) over repeated sampling. A single larger sample only looks more like the population, as the Glivenko–Cantelli theorem says; data drawn from a skewed population stay skewed [1].&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Thinking that n above 30 is always enough.&lt;/strong&gt; The Wikipedia article notes that this widespread rule of thumb has no valid justification and can lead to seriously flawed inferences [1]. In the example above, at n = 30 the right-tail probability is still about 0.9 percentage points above its nominal value.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What to check before relying on it
&lt;/h2&gt;

&lt;p&gt;The theorem is mainly used for the standard error of the mean, normal-based confidence intervals and z-tests. Before relying on it, check three things: whether the observations are independent; whether the population may be heavy-tailed, to the point that even the variance is unstable; and how skewed the data are. The stronger the skew, the larger the sample needed and the more care one-sided conclusions need; without independence or finite variance, the theorem does not apply at all.&lt;/p&gt;

&lt;h3&gt;
  
  
  References
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Central_limit_theorem" rel="noopener noreferrer"&gt;Central limit theorem, Wikipedia, accessed 2026-11-19&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Cauchy_distribution" rel="noopener noreferrer"&gt;Cauchy distribution, Wikipedia, accessed 2026-11-19&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;Originally published at &lt;a href="https://metho.scholay.com/en/news/593c68bf52d386f709dbe5a3b6f5b9e0/" rel="noopener noreferrer"&gt;Research Methods&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.scholay.com" rel="noopener noreferrer"&gt;Scholay&lt;/a&gt; · &lt;a href="https://www.enterscholar.com" rel="noopener noreferrer"&gt;EnterScholar&lt;/a&gt;&lt;/p&gt;

</description>
      <category>data</category>
      <category>science</category>
    </item>
    <item>
      <title>Learning to Turn a Table into a Program with CS50R</title>
      <dc:creator>Isaac Land</dc:creator>
      <pubDate>Mon, 30 Nov 2026 03:00:00 +0000</pubDate>
      <link>https://dev.to/landisaac1/learning-to-turn-a-table-into-a-program-with-cs50r-27ko</link>
      <guid>https://dev.to/landisaac1/learning-to-turn-a-table-into-a-program-with-cs50r-27ko</guid>
      <description>&lt;h1&gt;
  
  
  Learning to Turn a Table into a Program with CS50R
&lt;/h1&gt;

&lt;p&gt;A beginner can reproduce a plot from someone else's R script while remaining unsure what a row means or whether a missing value entered the denominator. Harvard's CS50R takes those questions in sequence. Carter Zenke and David J. Malan's R-focused course uses RStudio. Its seven weeks of OpenCourseWare are available to non-Harvard learners for free, and CS50R may be taken before, during or after CS50x.[1]&lt;/p&gt;

&lt;h2&gt;
  
  
  Carry one table through seven weeks
&lt;/h2&gt;

&lt;p&gt;Invent three observations with values four, missing and eight, plus a sample identifier for each. This is a personal exercise, not an official assignment. In Representing Data, distinguish a vector from a data frame and a label from a numeric value. In Transforming Data, name the condition that selects rows. The denominator of an eventual average is then a visible decision.[1]&lt;/p&gt;

&lt;p&gt;Applying Functions lets you express the summary as a function. Tidying Data turns related measurements into consistent rows and columns. In Visualizing Data, use the grammar of graphics to explain which variable maps to position or colour. The course introduces the tidyverse. If a point disappears, identify its missing observation before adjusting the appearance of the plot.[1]&lt;/p&gt;

&lt;p&gt;&lt;a href="/article-media/0a29c26448cd04e04f67dbe4060352d2cc32a538912d6c442c717e5305a0367f.webp" class="article-body-image-wrapper"&gt;&lt;img src="/article-media/0a29c26448cd04e04f67dbe4060352d2cc32a538912d6c442c717e5305a0367f.webp" alt="A small observation column carried from data to a test"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure: A small table carried through the learning sequence.&lt;/p&gt;

&lt;p&gt;Testing Programs and Packaging Programs complete the sequence. Write a check that the two observed values average six. Decide what should happen when every value is missing. Give the same function to a colleague for a different table. For the final project, retaining a minimal input and an expected output lets someone independently check what the program promises to do.[1]&lt;/p&gt;

&lt;h2&gt;
  
  
  Use the assignment as the week's check
&lt;/h2&gt;

&lt;p&gt;The published workflow is lecture, recommended short videos, then the problem set, followed eventually by the final project. Use a short video to revisit a specific operation. Try rebuilding the analysis from a blank script before looking at the example. To submit problem sets and the final project for feedback, the course asks learners to create an edX account.[1]&lt;/p&gt;

&lt;h2&gt;
  
  
  Choose the recognition appropriate to the goal
&lt;/h2&gt;

&lt;p&gt;OpenCourseWare supports independent study. For an edX verified certificate, register through the separate course link. Harvard Extension School and Harvard Summer School list separate registration routes for credit and accreditation. Watching the free lectures does not award transfer credit; it does let an independent learner start the same material immediately.[1]&lt;/p&gt;

&lt;p&gt;The course materials use CC BY-NC-SA 4.0. A research group can share the course link and practise with its own table. If redistributing adapted course materials, retain attribution and follow the license conditions. Then replace the toy rows with your research data and ask who each row represents, where its value came from and what the program should do on a different input.[1][2]&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;[1] &lt;a href="https://cs50.harvard.edu/r/" rel="noopener noreferrer"&gt;Harvard CS50. Introduction to Programming with R&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;[2] &lt;a href="https://cs50.harvard.edu/r/license/" rel="noopener noreferrer"&gt;CS50R. License&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;Originally published at &lt;a href="https://enter.scholay.com/en/news/de7ead639d90bef1bf977b5c76d64100/" rel="noopener noreferrer"&gt;EnterScholar&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.scholay.com" rel="noopener noreferrer"&gt;Scholay&lt;/a&gt; · &lt;a href="https://www.enterscholar.com" rel="noopener noreferrer"&gt;EnterScholar&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>education</category>
      <category>learning</category>
      <category>programming</category>
    </item>
    <item>
      <title>How to adjust the significance threshold with the Bonferroni method in multiple comparisons</title>
      <dc:creator>Isaac Land</dc:creator>
      <pubDate>Sun, 29 Nov 2026 11:00:00 +0000</pubDate>
      <link>https://dev.to/landisaac1/how-to-adjust-the-significance-threshold-with-the-bonferroni-method-in-multiple-comparisons-bc4</link>
      <guid>https://dev.to/landisaac1/how-to-adjust-the-significance-threshold-with-the-bonferroni-method-in-multiple-comparisons-bc4</guid>
      <description>&lt;h1&gt;
  
  
  How to adjust the significance threshold with the Bonferroni method in multiple comparisons
&lt;/h1&gt;

&lt;p&gt;Setting a test's significance level at 0.05 means that when the null hypothesis is true, there is a 5% chance of wrongly calling the result significant. Run many tests at once, and a single wrong call adds a spurious "discovery". That is the multiple comparisons problem: the more tests, the greater the chance of at least one type I error [1]. The Bonferroni correction is the most direct answer: split the overall α evenly over the m tests and reject each null hypothesis only when p ≤ α/m [1].&lt;/p&gt;

&lt;h2&gt;
  
  
  What it controls is the family-wise error rate
&lt;/h2&gt;

&lt;p&gt;A set of tests interpreted together is called a "family", and the family-wise error rate (FWER) is the probability of at least one type I error within that set [2]. Where a family begins and ends depends on which results will be selected, reported or acted on together, not on every test that happens to be run on a data set [2].&lt;/p&gt;

&lt;p&gt;Bonferroni controls it through Boole's inequality: among the m₀ true null hypotheses, the probability that at least one p-value falls below α/m is no more than the sum of the individual probabilities, m₀·α/m, and so no more than α [1]. The argument requires neither independence between the tests nor knowledge of how many null hypotheses are true [1].&lt;/p&gt;

&lt;h2&gt;
  
  
  How easily false positives appear without correction
&lt;/h2&gt;

&lt;p&gt;Suppose m tests are independent and all their null hypotheses are true, each run at 0.05. The probability of at least one false positive is 1 − 0.95^m: about 22.6% for 5 tests, 40.1% for 10, 64.2% for 20 and 99.4% for 100. With the Bonferroni threshold 0.05/m, it stays around 4.9% and never exceeds 5%, however large m becomes.&lt;/p&gt;

&lt;p&gt;&lt;a href="/article-media/760b435f67eefe1f59e688a5625714e3ad3240b915ccec97f99b6a3d77a0af1c.png" class="article-body-image-wrapper"&gt;&lt;img src="/article-media/760b435f67eefe1f59e688a5625714e3ad3240b915ccec97f99b6a3d77a0af1c.png" alt="Line chart: uncorrected error nears 100%, corrected ~5%"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure: Probability of at least one false positive as the number of tests grows.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to apply it
&lt;/h2&gt;

&lt;p&gt;There are two equivalent ways. One adjusts the threshold: a study testing 20 hypotheses with an overall α of 0.05 tests each at 0.05/20 = 0.0025 [1]. The other adjusts the p-values: multiply each by the number of tests, cap the result at 1, and compare with the original 0.05; both lead to exactly the same decisions [1].&lt;/p&gt;

&lt;p&gt;α need not be split evenly either. Any levels that add up to α will do, provided they are fixed before looking at the data; for two tests, 0.04 and 0.01, for example [1]. The same idea applies to confidence intervals: to report m intervals with an overall confidence level of 1 − α, construct each at 1 − α/m [1].&lt;/p&gt;

&lt;h2&gt;
  
  
  Why it is conservative
&lt;/h2&gt;

&lt;p&gt;The price of holding the family-wise error rate is that each test becomes harder to pass, so real effects are missed more often: type II errors rise and power falls [1]. Take a real effect whose test statistic has an expected value of 3 on its own (two-sided z-test). After correcting for different numbers of tests, the chance of detecting it is:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Number of tests m&lt;/th&gt;
&lt;th&gt;Threshold α/m&lt;/th&gt;
&lt;th&gt;Two-sided critical z&lt;/th&gt;
&lt;th&gt;Chance of detection&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0.05&lt;/td&gt;
&lt;td&gt;1.96&lt;/td&gt;
&lt;td&gt;85.1%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;0.01&lt;/td&gt;
&lt;td&gt;2.58&lt;/td&gt;
&lt;td&gt;66.4%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;20&lt;/td&gt;
&lt;td&gt;0.0025&lt;/td&gt;
&lt;td&gt;3.02&lt;/td&gt;
&lt;td&gt;49.1%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;td&gt;0.0005&lt;/td&gt;
&lt;td&gt;3.48&lt;/td&gt;
&lt;td&gt;31.5%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Positive correlation between tests is the other source of conservativeness. Bonferroni is built for the worst case, so the more tests and the stronger their correlation, the more conservative it becomes [1]. In the extreme where all tests are perfectly positively correlated, there is effectively only one test and the family-wise error rate is not inflated at all, yet Bonferroni still divides the threshold by m [2]. Even with independent tests the actual family-wise error rate is only about 4.88%, slightly below the nominal 5%.&lt;/p&gt;

&lt;h2&gt;
  
  
  More powerful alternatives
&lt;/h2&gt;

&lt;p&gt;The Holm step-down method is the most common improvement. Sort the p-values from smallest to largest, compare the k-th smallest with α/(m + 1 − k), stop at the first one that fails, and reject every hypothesis before it [2]. Like Bonferroni it does not depend on the dependence between tests, yet it is uniformly at least as powerful [1][2]. As an illustration, take five p-values 0.004, 0.011, 0.020, 0.040 and 0.300 with α = 0.05. Bonferroni's threshold is 0.01 and rejects only the first; Holm compares them in turn with 0.010, 0.0125 and 0.0167, passes the first two, and stops at the third because 0.020 exceeds 0.0167, rejecting two.&lt;/p&gt;

&lt;p&gt;The Šidák correction sets each test at 1 − (1 − α)^(1/m), slightly more lenient than Bonferroni but by very little: 0.00256 against 0.0025 at m = 20. It can also fail to control the family-wise error rate when the tests are negatively dependent [2].&lt;/p&gt;

&lt;p&gt;If the goal is not to avoid every false positive but to control the share of false ones among the discoveries, the false discovery rate (FDR) is the alternative. The FDR is the expected proportion of wrongly rejected null hypotheses among all rejections; it is less strict than the family-wise error rate and so has more power, at the cost of allowing more type I errors [3]. Studies that test thousands of variables at once, such as in genomics, commonly rely on this kind of method [3].&lt;/p&gt;

&lt;h2&gt;
  
  
  When to use it
&lt;/h2&gt;

&lt;p&gt;When there are few tests and even one false positive would be costly, Bonferroni is simple, reliable and easy to explain: saying a result remains significant after Bonferroni correction means the family-wise error rate of the whole set is at most α. For more power under the same guarantee, use the Holm step-down method; with hundreds or thousands of tests and room for a few false discoveries, consider FDR methods. Whichever you choose, define the family before looking at the data.&lt;/p&gt;

&lt;h3&gt;
  
  
  References
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Bonferroni_correction" rel="noopener noreferrer"&gt;Bonferroni correction, Wikipedia, accessed 2026-11-19&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Family-wise_error_rate" rel="noopener noreferrer"&gt;Family-wise error rate, Wikipedia, accessed 2026-11-19&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/False_discovery_rate" rel="noopener noreferrer"&gt;False discovery rate, Wikipedia, accessed 2026-11-19&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;Originally published at &lt;a href="https://metho.scholay.com/en/news/64c013bed13a69f6f80d8f85382e83e1/" rel="noopener noreferrer"&gt;Research Methods&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.scholay.com" rel="noopener noreferrer"&gt;Scholay&lt;/a&gt; · &lt;a href="https://www.enterscholar.com" rel="noopener noreferrer"&gt;EnterScholar&lt;/a&gt;&lt;/p&gt;

</description>
      <category>computerscience</category>
      <category>data</category>
      <category>science</category>
    </item>
    <item>
      <title>Adding Searchable Text to a Scanned Paper with OCRmyPDF</title>
      <dc:creator>Isaac Land</dc:creator>
      <pubDate>Sun, 29 Nov 2026 03:00:00 +0000</pubDate>
      <link>https://dev.to/landisaac1/adding-searchable-text-to-a-scanned-paper-with-ocrmypdf-ci3</link>
      <guid>https://dev.to/landisaac1/adding-searchable-text-to-a-scanned-paper-with-ocrmypdf-ci3</guid>
      <description>&lt;h1&gt;
  
  
  Adding Searchable Text to a Scanned Paper with OCRmyPDF
&lt;/h1&gt;

&lt;p&gt;An old report has a clearly legible title that its PDF search box cannot find. Its pages are images; the viewer has no character sequence for the printed line. OCRmyPDF can use Tesseract to recognize printed material and align a searchable text layer with the page image. The result still opens as a paginated document, allowing readers to check words against the original appearance.[1][3]&lt;/p&gt;

&lt;h2&gt;
  
  
  Prepare the language and a separate output
&lt;/h2&gt;

&lt;p&gt;OCRmyPDF uses the Mozilla Public License 2.0. Debian and Ubuntu provide system packages, macOS users can install through Homebrew, and Windows has native and Linux-subsystem routes. The current Python installation instructions require Python 3.11 or newer. The recognition engine and external dependencies follow platform-specific instructions. Ghostscript requirements depend on the processing and output path. Installing a Python package alone does not supply every external program.[2][5]&lt;/p&gt;

&lt;p&gt;Keep the original and choose another output filename, for example &lt;code&gt;ocrmypdf scan.pdf searchable.pdf&lt;/code&gt;. For Simplified Chinese, install the corresponding Tesseract language data and check for &lt;code&gt;chi_sim&lt;/code&gt; with &lt;code&gt;tesseract --list-langs&lt;/code&gt;. For a mixture of English and Chinese, specify &lt;code&gt;-l chi_sim+eng&lt;/code&gt;. Selecting a language describes the page; it cannot supply an absent language model.[2][3][4]&lt;/p&gt;

&lt;h2&gt;
  
  
  Establish what each page already contains
&lt;/h2&gt;

&lt;p&gt;A bound report might begin with a digitally typeset contents page and continue with photographs of archival pages. Its native text already selects cleanly. In versions with the unified mode option, &lt;code&gt;--mode skip&lt;/code&gt; skips pages with text, and &lt;code&gt;--mode redo&lt;/code&gt; replaces an existing OCR layer. Use &lt;code&gt;--mode force&lt;/code&gt; deliberately because it rasterizes pages before recognizing them. First identifying the two kinds of pages protects good text already in the report.[3]&lt;/p&gt;

&lt;p&gt;&lt;a href="/article-media/ddf9205e6fae9d2cf9616b7ec33a0d8949e33b1090115375776c7646d760a0f4.webp" class="article-body-image-wrapper"&gt;&lt;img src="/article-media/ddf9205e6fae9d2cf9616b7ec33a0d8949e33b1090115375776c7646d760a0f4.webp" alt="A page image aligned with an invisible searchable text layer"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure: Image and searchable text on the same PDF page.&lt;/p&gt;

&lt;p&gt;Use &lt;code&gt;--deskew&lt;/code&gt; for a slight slant caused by the feeder. A page turned through ninety degrees calls for a rotation option instead. Check a page containing headings, footnotes and two columns. Inspect its orientation, search for a distinctive phrase and copy text near the column boundary. These actions test different properties. A correct search hit can coexist with reading order that jumps between columns.[1][3] Where that happens, locate the paragraph boundaries in the image and transcribe the target column in order. Record the page with the excerpt for comparison after any later recognition run.&lt;/p&gt;

&lt;h2&gt;
  
  
  Retain a route back to the original page
&lt;/h2&gt;

&lt;p&gt;The usual archival output path is PDF/A. Add &lt;code&gt;--sidecar recognized.txt&lt;/code&gt; if you also need the text recognized during this run. Existing text on skipped pages does not automatically enter the sidecar. Check the resulting PDF itself when searching the whole document. Return a match to its page before transcribing a quotation or recording its page number.[1][3]&lt;/p&gt;

&lt;p&gt;Check handwriting, complex columns and tables against the page image. The Tesseract workflow discussed here targets print; its output does not reconstruct the author's paragraph and heading hierarchy. Finding a person's name establishes a character match, while nearby dates, punctuation or note numbers may still be wrong. Hand over the original PDF, the searchable version and the language selection, identifying unusually complex pages so both readers can inspect the same glyphs.[1][3]&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;[1] &lt;a href="https://ocrmypdf.readthedocs.io/en/latest/introduction.html" rel="noopener noreferrer"&gt;OCRmyPDF. Introduction&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;[2] &lt;a href="https://ocrmypdf.readthedocs.io/en/latest/installation.html" rel="noopener noreferrer"&gt;OCRmyPDF. Installation&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;[3] &lt;a href="https://ocrmypdf.readthedocs.io/en/latest/cookbook.html" rel="noopener noreferrer"&gt;OCRmyPDF. Cookbook&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;[4] &lt;a href="https://ocrmypdf.readthedocs.io/en/latest/languages.html" rel="noopener noreferrer"&gt;OCRmyPDF. Installing additional language packs&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;[5] &lt;a href="https://github.com/ocrmypdf/OCRmyPDF" rel="noopener noreferrer"&gt;OCRmyPDF project repository&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;Originally published at &lt;a href="https://enter.scholay.com/en/news/4ce52e67c073b2a53fc092136d569cf3/" rel="noopener noreferrer"&gt;EnterScholar&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.scholay.com" rel="noopener noreferrer"&gt;Scholay&lt;/a&gt; · &lt;a href="https://www.enterscholar.com" rel="noopener noreferrer"&gt;EnterScholar&lt;/a&gt;&lt;/p&gt;

</description>
      <category>opensource</category>
      <category>python</category>
      <category>tools</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How the Allies Used Tank Serial Numbers to Estimate Production</title>
      <dc:creator>Isaac Land</dc:creator>
      <pubDate>Sat, 28 Nov 2026 11:00:00 +0000</pubDate>
      <link>https://dev.to/landisaac1/how-the-allies-used-tank-serial-numbers-to-estimate-production-269d</link>
      <guid>https://dev.to/landisaac1/how-the-allies-used-tank-serial-numbers-to-estimate-production-269d</guid>
      <description>&lt;h1&gt;
  
  
  How the Allies Used Tank Serial Numbers to Estimate Production
&lt;/h1&gt;

&lt;p&gt;Allied intelligence during World War II overestimated German tank production severalfold. Starting in 1943, analysts in the Economic Warfare Division of the American Embassy in London instead inferred production from serial numbers on captured equipment: according to their 1947 account, the serial-number estimate of monthly tank production for August 1942 was 327, postwar German records showed 342, and the contemporary intelligence consensus was 1550. This type of problem—inferring a total from serial numbers—later became known as the German tank problem.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7h78c58lbdb5orv7oax6.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7h78c58lbdb5orv7oax6.webp" alt="A World War II German Panther Ausf. G tank displayed outdoors in the Belgian village of Grandmenil, preserved as a memorial to the 1944 Battle of the Bulge" width="800" height="619"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Panther Ausf. G tank in Grandmenil, Manhay, Belgium, was knocked out on December 26, 1944, during the Battle of the Bulge and is now a memorial to the battle. Photograph: Jean-Pol Grandmont (2005), &lt;a href="https://commons.wikimedia.org/wiki/File:PzKpfw-Vg_%22Panther%22-Manhay1.jpg" rel="noopener noreferrer"&gt;File:PzKpfw-Vg "Panther"-Manhay1.jpg&lt;/a&gt;, &lt;a href="https://creativecommons.org/licenses/by/2.0/" rel="noopener noreferrer"&gt;CC BY 2.0&lt;/a&gt;. The original file is 2272×1704. The copy on this site is scaled to 1600×1200 and adds a 38 px bottom bar reading 研究方法; the file is 1600×1238.&lt;/p&gt;

&lt;h2&gt;
  
  
  Serial-Number Analysis in London's Economic Warfare Division
&lt;/h2&gt;

&lt;p&gt;Early in the war, the Allies mainly used two approaches to estimate total German production: extrapolating from prewar data using British and American experience, or working backward from the German order of battle and standard equipment tables. In their 1947 retrospective in the &lt;em&gt;Journal of the American Statistical Association&lt;/em&gt; (JASA), Ruggles and Brodie wrote that these two types of models allowed so much latitude that they often got even the order of magnitude wrong; clandestine sources and prisoner-of-war interrogations also supplied numerous contradictory reports, leaving analysts to fall back on figures that “looked reasonable.” In early 1943, the Economic Warfare Division of the American Embassy in London, staffed by personnel seconded from the Office of Strategic Services, the Foreign Economic Administration, and the State Department, began systematically analyzing markings on German equipment. Its first subject was tires: the British had already collected markings from about 2000 German tires. Once the method proved workable, the analysts turned their attention to tanks.&lt;/p&gt;

&lt;p&gt;Tank markings came from a wide range of sources: tank logbooks captured in North Africa, divisional equipment inventories, tank repair depot records, Wehrmacht spare-parts catalogs, and markings transcribed from captured vehicles by technical intelligence personnel in the field, totaling about 1200 chassis serial numbers. The chassis numbers did not form a single uninterrupted sequence: each tank type occupied a range of numbers, which was then divided among assembly plants, and different models always started at a new multiple of one hundred, often leaving unused numbers at the end of each hundred-number block. The analysts tabulated the distribution of the last two digits and found that the samples clustered toward the beginning of these blocks. They used this to estimate the proportion of each range actually used, then independently cross-checked the results against engine numbers. The conclusions of the first tank report differed sharply from the intelligence accepted at the time: the accepted estimate of cumulative German tank production was about 40000, while serial-number analysis put it at no more than 14000; for annual production in 1942, the accepted estimate was about 18000, while the serial-number estimate was just 3400.&lt;/p&gt;

&lt;p&gt;The analysts subsequently discovered that gearbox numbers for each tank type formed only one or two uninterrupted ascending sequences. This eliminated the need to account for gaps in number ranges, so only a small sample was needed: one or two newly captured tanks could update the production estimate. According to the original account, production of Panther (Mark V) tanks in November 1944 had already been calculated by January 1945. The most frequently cited analysis concerns Panther road wheels. Before the Normandy landings, the Allies feared that rumors of large-scale Panther production were true, yet they had only two tanks available for inspection: one supplied by the Soviets and one captured by the Western Allies. Each Panther had a total of 48 rubber-tired road wheels across its two sides, with mold numbers stamped on the tires. The largest mold number observed for one manufacturer was 77, with an average gap of about 3 numbers between observed numbers, leading the analysts to estimate that the manufacturer had about 80 sets of molds. They then consulted British road-wheel manufacturers about the output capacity of a single set of molds, deducted the allowance for spare parts, and cross-checked the calculation using the ratios of mold counts to production for Mark III, IV, and VI tanks. Both calculations pointed to an assembly rate of about 270 tanks per month in February 1944. Postwar checks showed that actual production that month was 276.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Date&lt;/th&gt;
&lt;th&gt;Serial-number estimate (tanks/month)&lt;/th&gt;
&lt;th&gt;Intelligence estimate (tanks/month)&lt;/th&gt;
&lt;th&gt;German records (tanks/month)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;June 1940&lt;/td&gt;
&lt;td&gt;169&lt;/td&gt;
&lt;td&gt;1000&lt;/td&gt;
&lt;td&gt;122&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;June 1941&lt;/td&gt;
&lt;td&gt;244&lt;/td&gt;
&lt;td&gt;1550&lt;/td&gt;
&lt;td&gt;271&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;August 1942&lt;/td&gt;
&lt;td&gt;327&lt;/td&gt;
&lt;td&gt;1550&lt;/td&gt;
&lt;td&gt;342&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The data come from page 89 of Ruggles and Brodie (1947). The intelligence estimates were taken from &lt;em&gt;Munitions Record No. 24&lt;/em&gt;, dated August 10, 1942, and represented the shared view of British and American intelligence agencies at the time; the German records came from statistics of Speer's Ministry of Armaments obtained after the war.&lt;/p&gt;

&lt;p&gt;A more widely circulated online version states that “statisticians estimated average monthly production of 246 tanks from June 1940 to September 1942, intelligence estimated about 1400, and postwar records showed 245.” These figures come from a 2006 column in &lt;em&gt;The Guardian&lt;/em&gt;, whose author used the word “reportedly”; they cannot be found in Ruggles and Brodie's original article. The formula given in the column, (M−1)(S+1)/S, also differs from the standard form in later textbooks. The original article also documented failures: assault-gun production in 1942 and 1943 was underestimated by 71% and 62%, respectively, because field personnel had neglected to collect markings from these vehicles. The two authors concluded that all estimates with large errors were too low, but that the errors in more than ninety percent of the estimates were too small to affect the analytical conclusions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Frequentist and Bayesian Estimation Formulas
&lt;/h2&gt;

&lt;p&gt;Abstracting the historical problem: a batch of items is numbered consecutively from 1 to $N$, where $N$ is unknown; $k$ items are observed at random without replacement, and the largest observed number is $m$. In their footnote on road-wheel molds, Ruggles and Brodie used the idea of “the sample maximum plus the average gap,” but did not develop the mathematics. In 1952, Leo Goodman published “Serial Number Analysis” in JASA, providing a minimum-variance unbiased estimator and confidence intervals for this type of discrete uniform population:&lt;/p&gt;

&lt;p&gt;$$\hat N = m\left(1+\frac{1}{k}\right)-1 = m + \frac{m-k}{k}$$&lt;/p&gt;

&lt;p&gt;The intuition is that $N$ cannot be smaller than $m$, so the sample maximum, which is also the maximum-likelihood estimate, is biased downward overall; the $k$ numbers divide 1 through $m$ into $k$ segments, with an average of $(m-k)/k$ unused numbers per segment. Adding another average gap after $m$ gives an unbiased estimate. Its variance is&lt;/p&gt;

&lt;p&gt;$$\operatorname{Var}(\hat N)=\frac{(N-k)(N+1)}{k(k+2)}$$&lt;/p&gt;

&lt;p&gt;When $k$ is much smaller than $N$, the standard deviation is approximately $N/k$, roughly equal to the average distance between adjacent sampled numbers.&lt;/p&gt;

&lt;p&gt;The Bayesian approach treats $N$ as a random variable, first specifying a prior distribution and then updating it with the data. Given $N=n$, the probability that a sample of $k$ items drawn without replacement has a maximum number of exactly $m$ is&lt;/p&gt;

&lt;p&gt;$$P(M=m\mid N=n)=\frac{\binom{m-1}{k-1}}{\binom{n}{k}},\quad n\ge m$$&lt;/p&gt;

&lt;p&gt;The likelihood depends only on $m$ and $k$, the same information used by the frequentist approach. With a prior that is uniform over a very large range, becoming an improper prior in the limit, the posterior for $k\ge 2$ satisfies&lt;/p&gt;

&lt;p&gt;$$P(N&amp;gt;x\mid m,k)=\frac{\binom{m-1}{k-1}}{\binom{x}{k-1}},\quad x\ge m$$&lt;/p&gt;

&lt;p&gt;The posterior mode is $m$; for $k\ge 3$, the posterior mean is $(m-1)(k-1)/(k-2)$, and the standard deviation is finite only for $k\ge 4$; the median is approximately $m + m\ln 2/(k-1)$. Simon's (2023) teaching paper emphasizes that the value of the Bayesian solution lies in more than providing another point estimate: it assigns a probability to each possible $N$, allowing a direct answer to “What is the probability that production exceeds a threshold that would change operational plans?” It also allows existing intelligence to be incorporated into the prior.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Reproducible Worked Example and Small-Sample Performance
&lt;/h2&gt;

&lt;p&gt;The following is a set of fictional data, not a historical record: 5 tanks are captured, with serial numbers 14, 37, 58, 71, and 96, so $k=5$ and $m=96$.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sample maximum: 96, which can serve only as a lower bound.&lt;/li&gt;
&lt;li&gt;Minimum-variance unbiased estimate: $96\times 6/5-1=114.2$, or about 114 tanks; the average gap is $(96-5)/5=18.2$.&lt;/li&gt;
&lt;li&gt;Frequentist one-sided 95% confidence interval: find the largest $n$ such that $P(M\le 96\mid n)=\binom{96}{5}/\binom{n}{5}\ge 0.05$. At $n=173$, this probability is about 0.0502; at $n=174$, it is about 0.0487, giving the interval $[96,173]$.&lt;/li&gt;
&lt;li&gt;Bayesian estimate with a uniform prior: the posterior mean is $95\times4/3\approx126.7$, with a standard deviation of about 44.1; $P(N&amp;gt;112)\approx0.513$ and $P(N&amp;gt;113)\approx0.494$, so the median is 113; $P(N&amp;gt;199)\approx0.0502$ and $P(N&amp;gt;200)\approx0.0492$, so the 95% credible upper bound is 200.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;math&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;comb&lt;/span&gt;

&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;14&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;37&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;58&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;71&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;96&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;mvue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;  &lt;span class="c1"&gt;# 114.2&lt;/span&gt;
&lt;span class="n"&gt;freq_upper&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nf"&gt;comb&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nf"&gt;comb&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.05&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# 173&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;posterior_tail&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="s2"&gt;"""P(N &amp;gt; x | m, k) under a flat prior, valid for x &amp;gt;= m."""&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;comb&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nf"&gt;comb&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="n"&gt;bayes_mean&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# 126.7&lt;/span&gt;
&lt;span class="n"&gt;bayes_median&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nf"&gt;posterior_tail&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# 113&lt;/span&gt;
&lt;span class="n"&gt;bayes_upper&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nf"&gt;posterior_tail&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mf"&gt;0.05&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# 200&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mvue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;freq_upper&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bayes_mean&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bayes_median&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bayes_upper&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fi29y0fp8aerbd40b334l.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fi29y0fp8aerbd40b334l.webp" alt="A graph of curves grouped by sample size k, with maximum serial number m on the horizontal axis; dashed lines show frequentist estimates, while solid lines and shading show Bayesian means and uncertainty ranges" width="800" height="1232"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Estimates of the total by sample size k and maximum serial number m: dashed lines show frequentist unbiased estimates, solid lines show Bayesian posterior means under a uniform prior, and shading extends from the smallest possible value to the mean plus one standard deviation. Example from the original figure: when 4 tanks are observed and the maximum number is 60, the frequentist estimate is 74, while the Bayesian mean is 88.5, with a standard deviation of about 50. Author: Cmglee, &lt;a href="https://commons.wikimedia.org/wiki/File:German_tank_problem_graphs.svg" rel="noopener noreferrer"&gt;File:German tank problem graphs.svg&lt;/a&gt;, &lt;a href="https://creativecommons.org/licenses/by-sa/3.0/" rel="noopener noreferrer"&gt;CC BY-SA 3.0&lt;/a&gt;. The original SVG is 512×768. The copy on this site is rendered at 960×1440 and adds a 38 px bottom bar reading 研究方法; the file is 960×1478.&lt;/p&gt;

&lt;p&gt;These figures do not contradict one another. The posterior median (113) and the unbiased estimate (114) nearly coincide; the posterior mean (126.7) is noticeably higher because the posterior distribution is cut off at 96 on the left and has a long tail on the right, with a small number of very large values of N pulling up the mean. The Bayesian upper bound (200) is wider than the frequentist upper bound (173) because of the uniform prior: it gives very large and smaller values of N equal weight, and with only 5 observations, that assumption itself carries considerable weight.&lt;/p&gt;

&lt;p&gt;The smaller the sample, the greater the differences between methods. Suppose the true production total is $N=300$. The expected sample maximum is $k(N+1)/(k+1)$: about 200.7 for $k=2$, about 250.8 for $k=5$, and about 273.6 for $k=10$, systematically too low. The unbiased estimate hits 300 on average, but its standard deviations are about 106, 50, and 27, respectively. Using a with-replacement approximation, the upper bound of a one-sided 95% interval is approximately $m\cdot 20^{1/k}$: $20m$ for $k=1$, about $4.5m$ for $k=2$, about $1.82m$ for $k=5$, and about $1.35m$ for $k=10$. The Bayesian approach also struggles with extremely small samples: with a uniform prior and $k=1$, the posterior cannot be normalized; with $k=2$, the median is $2m-1$ but the mean is infinite. In such cases, a bounded or informative prior is required, and the conclusions consequently depend on that prior. The historical analysts did not rely on a single formula. They cross-checked multiple numbering sequences from chassis, engines, gearboxes, road wheels, and other components; this was the prerequisite for obtaining reliable estimates from just one or two tanks.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Classic Example of Sampling Serial Numbers and the Conditions for Its Use
&lt;/h2&gt;

&lt;p&gt;The German tank problem often appears in textbooks because it brings several abstract ideas together through a concrete story: population size is hidden in the sequence of numbers; under the assumptions of consecutive numbering and random sampling, the sample maximum together with the sample size captures all the information in the data about N; the maximum-likelihood estimate is clearly biased, and the minimum-variance unbiased estimator provides a clean correction; frequentist and Bayesian methods also show visible differences with small samples. Quoting Border, Simon calls it a “freak” of frequentist estimation. Similar problems arise beyond tanks: according to biographical material recounted by Simon, Turing and Gleason discussed “how to estimate the total number of taxis in a city after seeing some taxi license numbers” at a restaurant in Washington in 1942; classroom demonstrations often involve drawing numbered tokens from a bowl.&lt;/p&gt;

&lt;p&gt;The method has clear conditions for use, and Ruggles and Brodie's original article is full of checks on those conditions. First, numbers must be allocated consecutively from a known starting point; gaps in chassis-number ranges forced the analysts to make an additional estimate of the utilization of hundred-number blocks, and Goodman also specifically discussed the case of an unknown starting number. Second, the sample must be approximately random; aircraft tires accounted for nearly half the tire sample, whereas serial-number analysis suggested that they made up only 15% of production, because many samples came from German aircraft shot down over Britain. The analysts separated the two types of tires before using them for estimation. Third, it is necessary to establish which stage of production the numbering counts: estimates for V-1 flying bombs relied on component numbers, but a shortage of sheet steel kept final assembly from matching component production. The serial-number estimate for 1944 from 6 through July was 18000, while actual production might have been no more than 6000. Conversely, if numbers are not issued in production order, this inference loses its basis.&lt;/p&gt;

&lt;h3&gt;
  
  
  References
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Ruggles, R., &amp;amp; Brodie, H. (1947). An Empirical Approach to Economic Intelligence in World War II. &lt;em&gt;Journal of the American Statistical Association&lt;/em&gt;, 42(237), 72–91. &lt;a href="https://doi.org/10.1080/01621459.1947.10501915" rel="noopener noreferrer"&gt;doi:10.1080/01621459.1947.10501915&lt;/a&gt;; for a declassified reprint, see the &lt;a href="https://www.cia.gov/readingroom/docs/CIA-RDP79R01001A001300010013-3.pdf" rel="noopener noreferrer"&gt;CIA Reading Room&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Goodman, L. A. (1952). Serial Number Analysis. &lt;em&gt;Journal of the American Statistical Association&lt;/em&gt;, 47(260), 622–634. &lt;a href="https://doi.org/10.1080/01621459.1952.10483442" rel="noopener noreferrer"&gt;doi:10.1080/01621459.1952.10483442&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Simon, C. M. (2023). A Bayesian treatment of the German tank problem. &lt;a href="https://arxiv.org/abs/2301.00046" rel="noopener noreferrer"&gt;arXiv:2301.00046&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Davies, G. (2006). Gavyn Davies does the maths. &lt;em&gt;The Guardian&lt;/em&gt;. &lt;a href="https://www.theguardian.com/world/2006/jul/20/secondworldwar.tvandradio" rel="noopener noreferrer"&gt;Web page&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://metho.scholay.com" rel="noopener noreferrer"&gt;Research Methods&lt;/a&gt; · Rituals can be imitated; understanding cannot be faked&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;This information was compiled and published by the &lt;a href="https://www.scholay.com/t/M4ZZW8KRE5" rel="noopener noreferrer"&gt;Scholay One-Stop Academic Platform&lt;/a&gt;. Please report any infringement so the content can be removed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;This information was also published on &lt;a href="https://enterscholar.com" rel="noopener noreferrer"&gt;EnterScholar&lt;/a&gt;, a community for scholars in the age of intelligence.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;Originally published at &lt;a href="https://metho.scholay.com/en/news/draft-aaf15e52-4802-42bc-a37a-b07c4d3c16b3/" rel="noopener noreferrer"&gt;Research Methods&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.scholay.com" rel="noopener noreferrer"&gt;Scholay&lt;/a&gt; · &lt;a href="https://www.enterscholar.com" rel="noopener noreferrer"&gt;EnterScholar&lt;/a&gt;&lt;/p&gt;

</description>
      <category>analytics</category>
      <category>data</category>
      <category>science</category>
    </item>
    <item>
      <title>Mapping a Longitude and Latitude Table in QGIS</title>
      <dc:creator>Isaac Land</dc:creator>
      <pubDate>Sat, 28 Nov 2026 03:00:00 +0000</pubDate>
      <link>https://dev.to/landisaac1/mapping-a-longitude-and-latitude-table-in-qgis-175d</link>
      <guid>https://dev.to/landisaac1/mapping-a-longitude-and-latitude-table-in-qgis-175d</guid>
      <description>&lt;h1&gt;
  
  
  Mapping a Longitude and Latitude Table in QGIS
&lt;/h1&gt;

&lt;p&gt;Suppose a map needs three observation sites. Invent three coordinates for the exercise: A at 120° east and 30° north; B another 0.2° east and 0.1° north; C on A's longitude but 0.2° farther north. Nothing was surveyed, yet these values give a checkable expectation. C should be directly north of A and B should be to its northeast. That tells you more about an import than the mere presence of three dots.[1][3]&lt;/p&gt;

&lt;h2&gt;
  
  
  Treat the coordinates as two fields
&lt;/h2&gt;

&lt;p&gt;QGIS is a free, open-source geographic information system under GPL version 2 or later. Desktop distributions cover Windows, macOS and Linux. When checked, the download page offered the 3.44 long-term branch and the 4.2 current branch. Match the laboratory's version when sharing established projects. If you do not yet have a table, the download site also points to sample data.[1][2]&lt;/p&gt;

&lt;p&gt;Start with a CSV whose header names the identifier, longitude and latitude fields. Store decimal degrees as numbers and keep units out of individual cells. A sample identifier with leading zeroes may need to remain text. Coordinate fields locate a point. The identifier must still recover the same observation in the source records. Changing it to make every column numeric serves a different purpose entirely.[3]&lt;/p&gt;

&lt;h2&gt;
  
  
  Check the import preview twice
&lt;/h2&gt;

&lt;p&gt;Choose Delimited Text in Data Source Manager and select the file and its delimiter. If the whole row appears in one field, fix that before defining geometry. Where commas are decimal separators, check both numeric and column separator settings. Inspect detected field types, select point coordinates and assign longitude to X and latitude to Y. Use the documented degree-minute-second option when appropriate. Concatenating those digits would not produce decimal degrees.[3]&lt;/p&gt;

&lt;p&gt;Choose the geometry coordinate reference system of the input data. Our example explicitly uses WGS 84 geographic coordinates, so EPSG:4326 fits. Labelling projected metre coordinates as geographic degrees will not convert them. Add the layer, zoom to its extent and identify A, B and C in the attribute table. Compare A and C on the same meridian and check B's position to the northeast. Inspect missing coordinate values individually before assuming every row on the sheet became a point.[3] Match the three unique identifiers against the layer table as well. If three rows produce only two visible symbols, check for coincident points before changing any coordinates.&lt;/p&gt;

&lt;p&gt;&lt;a href="/article-media/603ce346f2d0444082142dbd3adb374081f592f284bc98237a89cd88b8741891.webp" class="article-body-image-wrapper"&gt;&lt;img src="/article-media/603ce346f2d0444082142dbd3adb374081f592f284bc98237a89cd88b8741891.webp" alt="Three coordinate rows plotted in their relative positions"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure: Three example coordinate pairs plotted together.&lt;/p&gt;

&lt;h2&gt;
  
  
  Set the reader's map extent in a layout
&lt;/h2&gt;

&lt;p&gt;Use the project canvas to explore. For the deliverable, create and name a new print layout, draw a map item and set its extent and scale. Label the sites at the intended page size. When the question is relative position, a little breathing room around the observations may communicate more than a crowded set of unrelated place names. If colour distinguishes groups, identify the grouping variable in the legend.[4]&lt;/p&gt;

&lt;p&gt;Export an image, PDF or SVG from the layout. Size a raster for its intended web display and inspect vector output when a publisher needs scalable labels and lines. Reopen the exported page at submission size. Check all three labels and the northernmost point. Preserve the project and CSV together, including their relative paths, coordinate units and source CRS. The next contributor should be able to add a fourth observation without tracing positions from the finished image.[3][4]&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;[1] &lt;a href="https://qgis.org/" rel="noopener noreferrer"&gt;QGIS project website&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;[2] &lt;a href="https://qgis.org/download/" rel="noopener noreferrer"&gt;QGIS downloads&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;[3] &lt;a href="https://docs.qgis.org/latest/en/docs/user_manual/managing_data_source/opening_data.html" rel="noopener noreferrer"&gt;QGIS User Guide. Opening Data&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;[4] &lt;a href="https://docs.qgis.org/latest/en/docs/user_manual/print_layout/overview_layout.html" rel="noopener noreferrer"&gt;QGIS User Guide. Overview of the Print Layout&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;Originally published at &lt;a href="https://enter.scholay.com/en/news/9e261c05fccb0a35b90a873c7cc621a7/" rel="noopener noreferrer"&gt;EnterScholar&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.scholay.com" rel="noopener noreferrer"&gt;Scholay&lt;/a&gt; · &lt;a href="https://www.enterscholar.com" rel="noopener noreferrer"&gt;EnterScholar&lt;/a&gt;&lt;/p&gt;

</description>
      <category>data</category>
      <category>tools</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Why do your friends have more friends on average than you do?</title>
      <dc:creator>Isaac Land</dc:creator>
      <pubDate>Fri, 27 Nov 2026 11:00:05 +0000</pubDate>
      <link>https://dev.to/landisaac1/why-do-your-friends-have-more-friends-on-average-than-you-do-3kcb</link>
      <guid>https://dev.to/landisaac1/why-do-your-friends-have-more-friends-on-average-than-you-do-3kcb</guid>
      <description>&lt;h1&gt;
  
  
  Why do your friends have more friends on average than you do?
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1b1nuegobcuw1k7tgeph.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1b1nuegobcuw1k7tgeph.webp" alt="LinkedIn contact network visualization: a large number of nodes are connected by thin lines, grouped by color into several clusters, with connections also existing between the clusters." width="800" height="668"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Personal contact network generated using LinkedIn InMaps: colors represent different acquaintance groups, node sizes vary, and a few nodes have significantly more connections. Author: brewbooks; Source:&lt;a href="https://www.flickr.com/photos/93452909@N00/7358153986" rel="noopener noreferrer"&gt;Flickr&lt;/a&gt;; Permission:&lt;a href="https://creativecommons.org/licenses/by-sa/2.0/" rel="noopener noreferrer"&gt;CC BY-SA 2.0&lt;/a&gt;。&lt;/p&gt;

&lt;p&gt;In May 1991, sociologist Scott L. Feld published a paper in the American Journal of Sociology, using friendship data from a high school and a simple formula to show that most individuals have fewer friends than their own friends have on average. The reason is not personality, but the counting method: individuals with more friends appear in more people's friend lists. This bias has since been applied to influenza early warning systems, immunization strategies, and the interpretation of social media data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Feld and the Marketville friendship data
&lt;/h2&gt;

&lt;p&gt;Feld was at SUNY Stony Brook at the time. The paper appeared in the American Journal of Sociology, volume 96, issue 6 (May 1991, pages 1464–1477). The starting point was very simple: people might use the number of friends of their friends to judge whether their own number of friends is sufficient; if such a comparison were made, most people would feel they have fewer friends than others. The data used came from James Coleman's classic 1961 study, The Adolescent Society. Coleman asked students at 12 high schools to list their friends, and Feld only counted reciprocal nominations as "friends."&lt;/p&gt;

&lt;p&gt;The paper first presents 10 mutual friendships among eight girls in a high school named 'Marketville' (all names are pseudonyms). Betty has only one friend, Sue, while Sue has four friends; Jane has two friends, Dale and Alice, whose friend counts average 3.5. Among the eight, Betty, Jane, Pam, Dale, and Tina have fewer friends than the average number of friends of their own friends, only Sue and Alice have more, and Carol is exactly at the average; the ratio of those with fewer friends to those with more friends is 5:2.&lt;/p&gt;

&lt;p&gt;When scaled to the entire school, the conclusion remains unchanged. Marketville has 146 girls who each have at least one mutual friend, of whom 80 have fewer mutual friends than their own mutual friends have on average, 41 have more, and 25 have the same; the former is nearly twice the latter. Feld reported that boys at the school and students at other schools in the Coleman study exhibit the same pattern; if 'average' is replaced with 'median,' that is, whether most of one's friends have more mutual friends than oneself, the result is almost identical.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fj5tkvl5oboq6odt30n2j.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fj5tkvl5oboq6odt30n2j.webp" alt="A small network consisting of four colored circular nodes A, B, C, and D: node B is connected to the other three nodes, node A is connected to node C, and node D is only connected to node B." width="800" height="824"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A minimal example of the friendship paradox: B has 3 friends, A and C each have 2, and D has only 1, so the average number of friends per person is 2; when listing each person's friends individually, B is counted 3 times, and the average number of friends among friends is 18 ÷ 8 = 2.25. A, C, and D each have fewer friends than the average number of friends of their friends, with only B being an exception (the values are calculated according to the figure in this text). Author: Jaszczuroczłek; Source:&lt;a href="https://commons.wikimedia.org/wiki/File:Graph_illustrating_the_Friendship_Paradox.svg" rel="noopener noreferrer"&gt;Wikimedia Commons&lt;/a&gt;; Permission:&lt;a href="https://creativecommons.org/licenses/by-sa/4.0/" rel="noopener noreferrer"&gt;CC BY-SA 4.0&lt;/a&gt;。&lt;/p&gt;

&lt;h2&gt;
  
  
  The variance of friend count and the degree distribution skew
&lt;/h2&gt;

&lt;p&gt;Feld's explanation is to distinguish between two distributions. The first is the 'number of friends per individual': the friend counts of the eight girls sum to 20, averaging 2.5 friends per person. The second is the 'number of friends of friends': listing each person's friends one by one results in 20 positions, and these friends collectively have 60 friends, averaging 3.0. The difference arises from repeated counting: a person appears in others' friend lists as many times as that person has friends. Using Feld's example, a person with 40 friends appears in the friend lists of 40 different people, while a person with only one friend appears in only one person's friend list.&lt;/p&gt;

&lt;p&gt;Let the i-th person have xᵢ friends. The average number of friends per person is Σxᵢ / n; in the list of friends, the i-th person appears xᵢ times, each time contributing xᵢ, so the average number of friends among friends is Σxᵢ² / Σxᵢ. Feld showed it equals "mean + variance ÷ mean." Variance cannot be negative, so the average number of friends among friends is at least equal to the average number of friends per person, and equality holds only when everyone has the same number of friends; the greater the difference in the number of friends, the larger the gap. The following Python code reconstructs the friendship network of eight girls according to the number of friends in Table 1 of the paper, with the values in the comments matching those in Table 1.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;networkx&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;nx&lt;/span&gt;

&lt;span class="c1"&gt;# Mutual friendships among the eight Marketville girls (Feld 1991, Fig. 1 / Table 1)&lt;/span&gt;
&lt;span class="n"&gt;edges&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Betty"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Sue"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Sue"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Alice"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Sue"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Dale"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Sue"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Pam"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
         &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Alice"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Jane"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Alice"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Dale"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Alice"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Pam"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
         &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Jane"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Dale"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Pam"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Carol"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Carol"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Tina"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="no"&gt;G&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;nx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Graph&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;edges&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;deg&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;G&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;degree&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;mean_friends&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;deg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;deg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;                      &lt;span class="c1"&gt;# 2.5&lt;/span&gt;
&lt;span class="n"&gt;mean_friends_of_friends&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;deg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                           &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nb"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;deg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;                  &lt;span class="c1"&gt;# 3.0&lt;/span&gt;
&lt;span class="n"&gt;friend_means&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;deg&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;u&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="no"&gt;G&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;deg&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="no"&gt;G&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;below&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="no"&gt;G&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;deg&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;friend_means&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;               &lt;span class="c1"&gt;# 5 girls&lt;/span&gt;
&lt;span class="n"&gt;mean_of_friend_means&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;friend_means&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;G&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;       &lt;span class="c1"&gt;# about 2.99&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The greater the skew in the degree distribution, the larger the gap. In Marketville, the distribution of female students' friend counts is right-skewed: the individual average is 2.7 friends, while the average from a friend's perspective is 3.4 friends. Feld estimated that if each person's friends represented the overall population of 'friends,' 74% of people would feel they have fewer friends than their friends do, while only 56% have fewer friends than the individual average. Online platforms amplify this skew to an extreme. Ugander et al. analyzed the complete friend network of approximately 721 million active Facebook users in May 2011: the average number of friends per user is about 190, the median is only 99, and a small number of users have hundreds or thousands of friends (the upper limit at that time was 5,000); the expected number of friends of a person reached via a random friendship link is 635. As a result, 92.7% of users have fewer friends than the average number of friends of their friends, and 83.6% have fewer friends than the median number of friends of their friends.&lt;/p&gt;

&lt;p&gt;Here it is important to distinguish two things. The statement 'the average friend count across all friend-list entries is greater than the average friend count per person' holds true in any network where friend counts are not all identical; however, 'most people have fewer friends than their own friends have on average' is not a mathematical necessity—it depends on who is friends with whom. Feld used the same set of friendship counts (4 people each with 3 friends, 12 people each with 1 friend) to construct four different networks: when people with similar numbers of friends are connected, the difference is smallest; when people with many friends are each connected to those with only one friend, the difference is largest; he also constructed an exception where a majority of people have more friends than their own friends have on average. Real-world social networks tend to show positive correlation, with a correlation coefficient of 0.226 between the number of friends of the two endpoints of a friendship on Facebook, but still more than 90% of users fall on the side of the paradox.&lt;/p&gt;

&lt;h2&gt;
  
  
  Influenza surveillance, health intervention, and platform sampling
&lt;/h2&gt;

&lt;p&gt;Pick a random person and ask them to identify a friend, and you can access more 'central' individuals at a very low cost without having to map out the entire network. In 2003, Reuven Cohen, Shlomo Havlin, and Daniel ben-Avraham proposed 'acquaintance immunization' in the Physical Review Letters: randomly select a subset of people and inoculate one randomly selected acquaintance of each. Theoretical analysis and simulations show that in networks with broad degree distributions, especially scale-free networks, the proportion of people required for immunity under this strategy is much lower than that required for random inoculation, and it does not require knowledge of how many connections each individual has.&lt;/p&gt;

&lt;p&gt;In 2010, Nicholas Christakis and James Fowler reported a field study in PLoS ONE. They tracked influenza at Harvard College from September 1 to December 31, 2009: a random sample of 319 students from 6,650 undergraduates, plus 425 friends nominated by these students, totaling 744 individuals. According to physician diagnoses, the cumulative incidence curve of the friends group was approximately 13.9 days (95% confidence interval 9.9–16.6 days) ahead of the random group; by day 16 of the outbreak, the friends group had significantly led, being 46 days ahead of the overall daily peak. When based on self-reported symptoms, the lead time was only 3.2 days. The authors also noted that the extent of the lead time depends on both the outbreak and the network itself; this study only involved one university during one influenza season.&lt;/p&gt;

&lt;p&gt;Applying the same approach to health interventions yields varying effects depending on the task. Kim et al. published a cluster randomized trial in The Lancet in 2015: in August 2012, in 32 villages in the Lempira department of Honduras (a total of 5,773 participants), researchers provided either a multivitamin or chlorine for water purification to 5% of villagers, selected through three methods: random selection, selection of those with the most social connections, and friends nominated by randomly selected villagers. The multivitamin redemption rate in the nominated friend group was 74.3%, in the random group 66.2%, and in the most-connected group 61.0%; the nominated friend group showed a 12.2% higher redemption rate than the random group (95% confidence interval 6.9–17.9); there were no significant differences in redemption rates for chlorine used in water purification across the three groups. The authors suggest that chlorine-based water purification requires learning a new multi-step procedure, which may partly explain the differences between the two interventions.&lt;/p&gt;

&lt;p&gt;For social media research, the friendship paradox is first and foremost a sampling weight issue. Hodas, Kooti, and Lerman found from a sample of Twitter's data stream that over 98% of users have fewer followers than the people they follow, and that the people they follow are on average more active and receive more content that is widely retweeted. That is, a person's timeline is a sample weighted by connection count. Economist Matthew Jackson theoretically argued in the Journal of Political Economy in 2019 that this over-sampling of popular individuals leads people to overestimate their peers' engagement, consistent with empirical findings that people overestimate their peers' drinking, smoking, and drug use. Any sample recruited through friend links, follow lists, or 'recommend a friend' invitations will be biased toward high-connectivity individuals; Feld provides a correction in the footnote of his paper, weighting each friend's information by '1 divided by the number of friends,' and then estimating the overall average.&lt;/p&gt;

&lt;h3&gt;
  
  
  References
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Feld, S. L. (1991). Why Your Friends Have More Friends Than You Do. &lt;em&gt;American Journal of Sociology&lt;/em&gt;, 96(6), 1464–1477. &lt;a href="https://doi.org/10.1086/229693" rel="noopener noreferrer"&gt;doi:10.1086/229693&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ugander, J., Karrer, B., Backstrom, L., &amp;amp; Marlow, C. (2011). The Anatomy of the Facebook Social Graph. arXiv:1111.4503. &lt;a href="https://arxiv.org/abs/1111.4503" rel="noopener noreferrer"&gt;arxiv.org/abs/1111.4503&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cohen, R., Havlin, S., &amp;amp; ben-Avraham, D. (2003). Efficient Immunization Strategies for Computer Networks and Populations. &lt;em&gt;Physical Review Letters&lt;/em&gt;, 91, 247901. &lt;a href="https://doi.org/10.1103/PhysRevLett.91.247901" rel="noopener noreferrer"&gt;doi:10.1103/PhysRevLett.91.247901&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Christakis, N. A., &amp;amp; Fowler, J. H. (2010). Social Network Sensors for Early Detection of Contagious Outbreaks. &lt;em&gt;PLoS ONE&lt;/em&gt;, 5(9), e12948. &lt;a href="https://doi.org/10.1371/journal.pone.0012948" rel="noopener noreferrer"&gt;doi:10.1371/journal.pone.0012948&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Kim, D. A., et al. (2015). Social network targeting to maximise population behaviour change: a cluster randomised controlled trial. &lt;em&gt;The Lancet&lt;/em&gt;, 386(9989), 145–153. &lt;a href="https://doi.org/10.1016/S0140-6736(15)60095-2" rel="noopener noreferrer"&gt;doi:10.1016/S0140-6736(15)60095-2&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Hodas, N. O., Kooti, F., &amp;amp; Lerman, K. (2013). Friendship Paradox Redux: Your Friends Are More Interesting Than You. &lt;em&gt;Proceedings of ICWSM&lt;/em&gt;, 7, 225–233. &lt;a href="https://doi.org/10.1609/icwsm.v7i1.14440" rel="noopener noreferrer"&gt;doi:10.1609/icwsm.v7i1.14440&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Jackson, M. O. (2019). The Friendship Paradox and Systematic Biases in Perceptions and Social Norms. &lt;em&gt;Journal of Political Economy&lt;/em&gt;, 127(2), 777–818. &lt;a href="https://doi.org/10.1086/701031" rel="noopener noreferrer"&gt;doi:10.1086/701031&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://metho.scholay.com" rel="noopener noreferrer"&gt;Research methodology&lt;/a&gt; Rituals can be mimicked, but understanding cannot be feigned&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Information provided by &lt;a href="https://www.scholay.com/t/M4ZZW8KRE5" rel="noopener noreferrer"&gt;Scholay Academic One-Stop Platform&lt;/a&gt; Organize and publish; if there is any infringement, please provide feedback for removal.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Information synchronization published in &lt;a href="https://enterscholar.com" rel="noopener noreferrer"&gt;EnterScholar&lt;/a&gt;, Scholar Community in the Age of Intelligence&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;Originally published at &lt;a href="https://metho.scholay.com/en/news/draft-f38ab468-d0e6-45ba-a5e8-08b1f8846a68/" rel="noopener noreferrer"&gt;Research Methods&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.scholay.com" rel="noopener noreferrer"&gt;Scholay&lt;/a&gt; · &lt;a href="https://www.enterscholar.com" rel="noopener noreferrer"&gt;EnterScholar&lt;/a&gt;&lt;/p&gt;

</description>
      <category>data</category>
      <category>science</category>
      <category>socialmedia</category>
    </item>
    <item>
      <title>Handing an R Project to a Collaborator with renv</title>
      <dc:creator>Isaac Land</dc:creator>
      <pubDate>Fri, 27 Nov 2026 03:00:28 +0000</pubDate>
      <link>https://dev.to/landisaac1/handing-an-r-project-to-a-collaborator-with-renv-255k</link>
      <guid>https://dev.to/landisaac1/handing-an-r-project-to-a-collaborator-with-renv-255k</guid>
      <description>&lt;h1&gt;
  
  
  Handing an R Project to a Collaborator with renv
&lt;/h1&gt;

&lt;p&gt;Two analyses share a laboratory computer. Updating a package for a new paper may change the functions used by last year's report. Copying every installed package to a colleague also carries across machine-specific paths and unrelated dependencies. With renv, each R project has a library of installed packages and a reviewable record of the versions it needs. Collaborators share that record and build their own installations.[1][2]&lt;/p&gt;

&lt;h2&gt;
  
  
  Give the project its own library
&lt;/h2&gt;

&lt;p&gt;Open the paper's project directory and run &lt;code&gt;renv::init()&lt;/code&gt;. In an existing project, renv discovers dependencies, creates a project library and initial lockfile, and configures the project to activate renv when R starts there. A library holds installed packages. A repository supplies packages. A lockfile describes the state a collaborator should reconstruct. Receiving the third does not immediately populate the first.[1]&lt;/p&gt;

&lt;p&gt;Suppose the new paper needs an updated data-management package. Open that project and use &lt;code&gt;renv::install()&lt;/code&gt; to install the package there. Run the affected analysis and inspect its outputs. Your installed environment has changed, but the lockfile may still describe the previous state. At the time of checking, CRAN listed version 1.3.1 of renv under MIT plus the accompanying license file. The relevant versions for a particular paper remain those in its lockfile.[1][3]&lt;/p&gt;

&lt;h2&gt;
  
  
  Read the direction of the operation
&lt;/h2&gt;

&lt;p&gt;Once satisfied with the change, run &lt;code&gt;renv::snapshot()&lt;/code&gt; and review the proposed differences. The lockfile records package names, versions and sources. Commit the updated record alongside the code that requires it. A reviewer can then see why a dependency changed. Sharing the script alone may leave collaborators with the old package. Sharing an untested lockfile does not establish that the paper's table can still be generated.[1][2]&lt;/p&gt;

&lt;p&gt;&lt;a href="/article-media/811476b9a4f4637c6a25a1c858851bc7da0b67580d54f5aebf661fb6e5214697.webp" class="article-body-image-wrapper"&gt;&lt;img src="/article-media/811476b9a4f4637c6a25a1c858851bc7da0b67580d54f5aebf661fb6e5214697.webp" alt="The lockfile sits between two independent project libraries"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure: Snapshot and restore across two project libraries.&lt;/p&gt;

&lt;p&gt;If the experiment fails and the lockfile still describes the working state, &lt;code&gt;renv::restore()&lt;/code&gt; takes the opposite direction. Review its proposed changes and restore the project library from the record. Decide which side represents the state worth keeping before responding to a mismatch. For an earlier submission, recover the lockfile committed with that version of the scripts rather than guessing which transitive dependency was in use.[1][2]&lt;/p&gt;

&lt;h2&gt;
  
  
  Make the handover in a fresh session
&lt;/h2&gt;

&lt;p&gt;Commit the scripts, &lt;code&gt;renv.lock&lt;/code&gt;, &lt;code&gt;.Rprofile&lt;/code&gt;, &lt;code&gt;renv/activate.R&lt;/code&gt; and &lt;code&gt;renv/settings.json&lt;/code&gt;. A collaborator starts a fresh R session in the project, lets the loader configure the library path, then restores missing packages. The installed library does not belong in the shared repository. A small input that exercises the script for the main table gives the collaborator a quick check of the output columns and row count before running the full analysis.[1][2]&lt;/p&gt;

&lt;p&gt;The lockfile records the R version but does not install the interpreter. Pandoc and system development libraries have their own installation paths. Record the interpreter, operating system and rendering tool versions when you need to compare a new machine with the original one. An analysis that runs and then fails when rendering the report may be missing a different component entirely. To stop using renv in this project, ordinary &lt;code&gt;renv::deactivate()&lt;/code&gt; removes the automatic loader while retaining other project files for later use. The practical handover test is whether the collaborator can regenerate the table.[1]&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;[1] &lt;a href="https://rstudio.github.io/renv/articles/renv.html" rel="noopener noreferrer"&gt;renv documentation. Introduction to renv&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;[2] &lt;a href="https://rstudio.github.io/renv/articles/collaborating.html" rel="noopener noreferrer"&gt;renv documentation. Collaborating with renv&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;[3] &lt;a href="https://cran.r-project.org/package=renv" rel="noopener noreferrer"&gt;CRAN. renv: Project Environments&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;Originally published at &lt;a href="https://enter.scholay.com/en/news/4aa12eb975a775209ea84866c27c584d/" rel="noopener noreferrer"&gt;EnterScholar&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.scholay.com" rel="noopener noreferrer"&gt;Scholay&lt;/a&gt; · &lt;a href="https://www.enterscholar.com" rel="noopener noreferrer"&gt;EnterScholar&lt;/a&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>softwaredevelopment</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Why do hospital samples make unrelated diseases appear related</title>
      <dc:creator>Isaac Land</dc:creator>
      <pubDate>Thu, 26 Nov 2026 11:00:47 +0000</pubDate>
      <link>https://dev.to/landisaac1/why-do-hospital-samples-make-unrelated-diseases-appear-related-3ni2</link>
      <guid>https://dev.to/landisaac1/why-do-hospital-samples-make-unrelated-diseases-appear-related-3ni2</guid>
      <description>&lt;h1&gt;
  
  
  Why do hospital samples make unrelated diseases appear related
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2vxlb6gfk5wkgkg09hyg.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2vxlb6gfk5wkgkg09hyg.webp" alt="A six-bed ward at the Triboro Hospital for Tuberculosis in New York, in 1940, with several iron bed frames neatly arranged, extending toward a balcony at the end." width="799" height="597"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In December 1940, a six-bed room with a balcony access at the Triboro Hospital for Tuberculosis, Parsons Avenue, Jamaica, New York. Photo uploaded by Flickr user polkbritton; original photographer not specified; source:&lt;a href="https://www.flickr.com/photos/157979053@N04/44337013100" rel="noopener noreferrer"&gt;Flickr&lt;/a&gt;; Permission:&lt;a href="https://creativecommons.org/publicdomain/mark/1.0/" rel="noopener noreferrer"&gt;Public Domain Mark 1.0&lt;/a&gt;。&lt;/p&gt;

&lt;p&gt;In 1946, statistician Joseph Berkson from the Mayo Clinic published a paper pointing out that even if two diseases are completely unassociated in the general population, a significant association—either positive or negative—might be calculated from a 2x2 table based solely on hospital patients. The reason lies not in biology, but in who gets sent to the hospital. This phenomenon later became known as Berkson's paradox or Berkson's bias, and is classified in modern epidemiology as a selection bias.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hospital data on cholecystitis and diabetes
&lt;/h2&gt;

&lt;p&gt;Berkson's paper is titled "Limitations of the Application of Fourfold Table Analysis to Hospital Data," published in June 1946 in the Biometrics Bulletin, Volume 2, Issue 3, pages 47–53. A footnote in the article states that this paper was previously presented in slightly different form at a meeting of the American Statistical Association in 1938, and was formally published in response to recent inquiries. In 2014, the International Journal of Epidemiology reprinted the full article and included a commentary.&lt;/p&gt;

&lt;p&gt;He began with a medical practice of the time: some believed that gallbladder diseases could trigger or exacerbate diabetes, and certain medical circles even regarded cholecystectomy as a treatment for diabetes. A hospital wanted to know whether its accumulated medical records could support this practice. By convention, patients were divided into two groups—those with diabetes and those without—and the proportion of gallbladder inflammation was compared between the groups, showing a significant positive correlation. Some might object that the 'without diabetes' group had various other conditions, some of which might themselves be related to gallbladder inflammation. Thus, Berkson changed the control group to one seemingly unrelated to gallbladder inflammation—patients visiting the clinic for eyeglasses due to refractive errors—and found the same significant positive correlation. He then asked: even after controlling for age, gender, and diagnostic reliability, could such a result indicate a biological association between gallbladder inflammation and diabetes?&lt;/p&gt;

&lt;p&gt;According to Snoep et al.'s 2014 review, Berkson recalled in 1955 that the inspiration for this problem came from Raymond Pearl, a biologist and statistician at Johns Hopkins University, who conducted a postmortem study in 1929: among 816 individuals who died of cancer, 6.6% were found to have active tuberculosis foci; among 816 individuals matched by race, gender, and age who died of other causes, the proportion was 16.3%. Tuberculosis seemed to 'prevent cancer,' and at the time, there were even attempts to treat cancer with tuberculin. Pearl himself acknowledged that same year that this negative correlation might simply be due to cancer patients dying before tuberculosis could fully develop.&lt;/p&gt;

&lt;h2&gt;
  
  
  How admission probabilities create associations
&lt;/h2&gt;

&lt;p&gt;To answer this question, Berkson constructed a hypothetical population in which several diseases were mutually independent: the prevalence of cholecystitis was 3%, refractive error was 10%, and the proportion of cholecystitis among diabetics and among individuals with refractive error was exactly the same. He further assumed that each disease had a probability of sending a patient to the hospital, and that when a person had multiple diseases, these probabilities acted independently of one another. In other words, the more diseases a person had, the greater the chance that at least one of them would send him to the hospital.&lt;/p&gt;

&lt;p&gt;First assume that the admission probabilities for the three diseases are all 0.05. Under this assumption, the prevalence of cholecystitis in the diabetes group in the hospital is approximately 5.4%, and in the group with refractive error as control is approximately 5.7%, showing a slight negative correlation. Berkson particularly pointed out that this occurs when the admission probabilities for all diseases are completely equal. In reality, factors such as disease severity, ability to seek care locally, and the hospital's specialty will make admission probabilities differ. He instead set the admission probability for cholecystitis at 0.15, for diabetes at 0.05, and for refractive error at 0.20. Under this new setting, the prevalence of cholecystitis in the diabetes group in the hospital becomes 8.55%, and in the refractive error control group it is 4.72%, approximately twice that of the latter, while in the general population they are equal. It is thus evident that the direction and magnitude of the spurious association depend on the admission probabilities of the diseases and the selection of the control group.&lt;/p&gt;

&lt;p&gt;Berkson emphasized that these spurious associations do not rely on any assumptions about biological effects, but are simply the result of combining independent probabilities in the usual way; replacing patients with randomly distributed cards would yield the same result. He also pointed out that pairing each case with a matched control for age and gender within the hospital sample does not resolve this issue.&lt;/p&gt;

&lt;p&gt;Pushing the mechanism to its extremes makes it easier to see clearly. Below is a hypothetical example created for illustrative purposes: a small town has 10,000 people, with 10% suffering from disease A and 10% from disease B, independently; the hospital only admits people who have at least one of these two diseases. Thus, approximately 100 people in the town have both diseases, 900 have only disease A, and 900 have only disease B. Among the 1,900 people admitted to the hospital, among the 1,000 with disease B, 10% also have disease A, while all 900 without disease B have disease A. Looking only at hospital data, disease B seems to 'prevent' disease A. The reason is simple: once a person is hospitalized, if they do not have a certain disease, it is likely because they have the other disease.&lt;/p&gt;

&lt;p&gt;Modern epidemiology describes this structure using causal graphs: both diseases point to 'hospitalization,' hospitalization being their common outcome, referred to as a collider. In a 2012 paper, Westreich explained that analyzing only hospitalized individuals amounts to restricting the data to one value of the collider, which creates a non-causal association between two originally unrelated variables; he also draws an analogy between this selection and missing data, viewing non-hospitalized individuals as 'missing,' and analyzing only hospitalized individuals being equivalent to analyzing only complete cases. Hernán and Robins' textbook Causal Inference: What If discusses such issues in the chapter on 'selection bias.'&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fta54cz3yjc42to5mo2hi.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fta54cz3yjc42to5mo2hi.webp" alt="Disease A and Disease B each have an arrow down to Hospitalization. A dashed line between the diseases is labeled as a spurious association among hospitalized patients." width="800" height="626"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The causal structure of Berkson's bias: both diseases increase the likelihood of hospitalization, "hospitalization" is a common outcome for both; analyzing only hospitalized individuals will create a false association between the two originally unrelated diseases. Structural reference to Snoep et al. (2014) and Westreich (2012). AI-generated schematic.&lt;/p&gt;

&lt;h2&gt;
  
  
  Measures for prevention in research design
&lt;/h2&gt;

&lt;p&gt;Berkson himself believed that the hospital 2x2 table comparison would not be erroneous only under two rather theoretical conditions: one is that one of the diseases fundamentally does not lead to hospitalization; the other is that the hospitalization probabilities of the control disease and the case disease are identical. Snoep et al. added that the second condition also requires excluding individuals who have both diseases simultaneously, otherwise the bias would not completely disappear. Simply replacing the control with community populations is not sufficient: according to their review, Feinstein et al. and Flanders et al. had previously pointed out that as long as the cases still come from hospitals, the bias persists.&lt;/p&gt;

&lt;p&gt;A common idea in modern study design is not to let conditions such as 'whether hospitalized'—which are simultaneously influenced by two factors being compared—determine who enters the comparison:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Cases and controls come from the same source population.&lt;/strong&gt;: Where possible, sample from the community or disease registries, rather than relying solely on medical records from a single hospital.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Replace prevalent cases with incident cases&lt;/strong&gt;: Snoep et al. point out that new cases reduce the probability that two diseases simultaneously send a person to the hospital, significantly mitigating bias but not eliminating it entirely.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Only included individuals hospitalized due to the disease under study itself.&lt;/strong&gt;: Excluding patients hospitalized for other diseases can eliminate what they refer to as 'indirect' Berkson's bias, provided there is no interaction among different admission mechanisms—for example, having both diseases must not itself make admission more likely because their management is more complex.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Draw a causal diagram before analysis&lt;/strong&gt;: Check whether variables such as 'hospitalization', 'medical visit', 'enrollment in the study' are common outcomes of the factors being compared, and avoid imposing restrictions or stratification on them.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Berkson's argument has long been criticized as "merely theoretical opposition, never tested." According to Snoep et al.'s review, in 1978 Roberts, Spitzer, Delmore, and Sackett conducted a test using data from three household surveys: among 28 disease-disease associations, most showed some degree of spurious association among people who had been hospitalized in the past six months. They also acknowledged that it was difficult to distinguish this from "clinical selection bias," that is, physicians tend to admit patients who have multiple conditions simultaneously. In 1979, Sackett renamed this bias as "admission rate bias."&lt;/p&gt;

&lt;p&gt;Snoep et al. in their 2014 review argued that the classical form of Berkson's bias pertains to associations between prevalent diseases, and that diseases are rarely studied as causes of other diseases, so its actual impact on epidemiological conclusions may be limited. More concerning is the 'indirect' form: when an exposure factor is associated with another disease that leads to hospitalization, the exposure appears correlated with the disease under study. They cited the example of studies using hospital cases to examine smoking and hip disease, where some cases were actually hospitalized due to smoking-related cardiovascular diseases. For today's readers, Berkson's warning remains relevant: when encountering a study that only includes a certain group of people, one should first ask whether the criteria for entry into the sample are simultaneously influenced by the two factors being compared.&lt;/p&gt;

&lt;h3&gt;
  
  
  References
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Berkson J. Limitations of the application of fourfold table analysis to hospital data. &lt;em&gt;Biometrics Bulletin&lt;/em&gt;. 1946;2(3):47–53. &lt;a href="https://doi.org/10.2307/3002000" rel="noopener noreferrer"&gt;doi:10.2307/3002000&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Berkson J. Limitations of the application of fourfold table analysis to hospital data (reprinted). &lt;em&gt;International Journal of Epidemiology&lt;/em&gt;. 2014;43(2):511–515. &lt;a href="https://doi.org/10.1093/ije/dyu022" rel="noopener noreferrer"&gt;doi:10.1093/ije/dyu022&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Snoep JD, Morabia A, Hernández-Díaz S, Hernán MA, Vandenbroucke JP. Commentary: A structural approach to Berkson's fallacy and a guide to a history of opinions about it. &lt;em&gt;International Journal of Epidemiology&lt;/em&gt;. 2014;43(2):515–521. &lt;a href="https://doi.org/10.1093/ije/dyu026" rel="noopener noreferrer"&gt;doi:10.1093/ije/dyu026&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Westreich D. Berkson's bias, selection bias, and missing data. &lt;em&gt;Epidemiology&lt;/em&gt;. 2012;23(1):159–164. &lt;a href="https://doi.org/10.1097/EDE.0b013e31823b6296" rel="noopener noreferrer"&gt;doi:10.1097/EDE.0b013e31823b6296&lt;/a&gt;（&lt;a href="https://pmc.ncbi.nlm.nih.gov/articles/PMC3237868/" rel="noopener noreferrer"&gt;PMC Full Text&lt;/a&gt;）&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Hernán MA, Robins JM. &lt;em&gt;Causal Inference: What If&lt;/em&gt; Boca Raton: Chapman &amp;amp; Hall/CRC; 2020 (online version April 26, 2024), Chapter 8 Selection bias. &lt;a href="https://miguelhernan.org/whatifbook" rel="noopener noreferrer"&gt;Online version&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://metho.scholay.com" rel="noopener noreferrer"&gt;Research methodology&lt;/a&gt; Rituals can be mimicked, but understanding cannot be feigned&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Information provided by &lt;a href="https://www.scholay.com/t/M4ZZW8KRE5" rel="noopener noreferrer"&gt;Scholay Academic One-Stop Platform&lt;/a&gt; Organize and publish; if there is any infringement, please provide feedback for removal.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Information synchronization published in &lt;a href="https://enterscholar.com" rel="noopener noreferrer"&gt;EnterScholar&lt;/a&gt;, Scholar Community in the Age of Intelligence&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;Originally published at &lt;a href="https://metho.scholay.com/en/news/draft-7c4a04ff-2440-4244-a895-0b10ec650993/" rel="noopener noreferrer"&gt;Research Methods&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.scholay.com" rel="noopener noreferrer"&gt;Scholay&lt;/a&gt; · &lt;a href="https://www.enterscholar.com" rel="noopener noreferrer"&gt;EnterScholar&lt;/a&gt;&lt;/p&gt;

</description>
      <category>analysis</category>
      <category>data</category>
      <category>science</category>
    </item>
    <item>
      <title>Keeping Jupyter Notebook Edits Readable in Git</title>
      <dc:creator>Isaac Land</dc:creator>
      <pubDate>Thu, 26 Nov 2026 03:01:44 +0000</pubDate>
      <link>https://dev.to/landisaac1/keeping-jupyter-notebook-edits-readable-in-git-43f7</link>
      <guid>https://dev.to/landisaac1/keeping-jupyter-notebook-edits-readable-in-git-43f7</guid>
      <description>&lt;h1&gt;
  
  
  Keeping Jupyter Notebook Edits Readable in Git
&lt;/h1&gt;

&lt;p&gt;A colleague changes the last observation in a notebook from six to nine. The question for a reviewer is simple: why did that value change? A diff of an ipynb file can bury the one-line change under execution counts, image data and cell metadata. Jupytext lets the team keep a second representation of the notebook. The author can execute cells in Jupyter, while the reviewer sees cell inputs as ordinary text in Git.[1][3]&lt;/p&gt;

&lt;h2&gt;
  
  
  Pair a notebook with a text file
&lt;/h2&gt;

&lt;p&gt;Install Jupytext in the environment that starts the Jupyter server, for example with &lt;code&gt;pip install jupytext&lt;/code&gt; or &lt;code&gt;conda install -c conda-forge jupytext&lt;/code&gt;. A kernel can live in a different environment. Installing only there may leave a working conversion command but no pairing command in the interface. Restart the server, open the command palette in JupyterLab, search for Jupytext, choose a pairing for an existing notebook and save. Look for the companion file beside the original. The project uses the MIT license.[1][2]&lt;/p&gt;

&lt;p&gt;For a code-heavy analysis choose &lt;code&gt;py:percent&lt;/code&gt;. Python code remains readable in an ordinary editor, cell boundaries appear as &lt;code&gt;# %%&lt;/code&gt;, and Markdown cells carry a distinct marker. A Markdown pairing can be easier to review for a notebook that is mostly prose. Both formats preserve inputs. Large printed tables and images belong to the ipynb file. Picking one text format for the project gives each change one obvious place for review.[1][3]&lt;/p&gt;

&lt;h2&gt;
  
  
  Follow one changed observation
&lt;/h2&gt;

&lt;p&gt;Run &lt;code&gt;jupytext --set-formats ipynb,py:percent mean.ipynb&lt;/code&gt; in the project directory. It records the pairing and creates the companion text file. Our example notebook takes the mean of two, four and six. Its stored output is four. In the text file, replace six with nine, save, then run &lt;code&gt;jupytext --sync mean.ipynb&lt;/code&gt;. Reading the resulting notebook shows the new input and the old output of four. Calculating the mean of the revised observations gives five. Copying the number next to the updated input into a report would copy the wrong result.[3][4]&lt;/p&gt;

&lt;p&gt;&lt;a href="/article-media/d2ddd8eee8115a9a9a2723dc02c30d2aa38ae1e94d780e9ada615340bed35e30.webp" class="article-body-image-wrapper"&gt;&lt;img src="/article-media/d2ddd8eee8115a9a9a2723dc02c30d2aa38ae1e94d780e9ada615340bed35e30.webp" alt="The edited input, old output and recomputed mean"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure: Mean after synchronization and execution.&lt;/p&gt;

&lt;p&gt;Opening a pair loads inputs from its more recent member and any saved outputs from the ipynb file. Saving updates both members and can recreate a missing one. If Git tracks only the text file, a collaborator can open and save it in Jupyter with Jupytext installed to create a local notebook. The text has no historical plots to recover. Reproducing the last plot needs the input data, the execution environment and a fresh run.[3]&lt;/p&gt;

&lt;h2&gt;
  
  
  Hand the analysis to a collaborator
&lt;/h2&gt;

&lt;p&gt;For a project with several notebooks, set &lt;code&gt;formats = "ipynb,py:percent"&lt;/code&gt; in a project-level &lt;code&gt;jupytext.toml&lt;/code&gt; and share the configuration with the text files. Start review at the changed cell, then identify results that depend on it. A particular figure cited in a paper can be saved as a separate output so that the team knows which artifact to regenerate.[4][5]&lt;/p&gt;

&lt;p&gt;In a merge request, separate the reason for the edit from the check on its effect. The last observation might be a corrected entry. Record both the old and new mean and the cell responsible. Someone with only the text file can check three numbers by hand before rerunning the whole analysis. This helps distinguish an input error, a calculation error and a stale display.&lt;/p&gt;

&lt;p&gt;Save work in Jupyter before switching to an external editor. If both stay open, the documentation recommends disabling autosave and reloading when returning to Jupyter. Where both copies have unsaved contributions, preserve a text copy and reconcile the meaningful lines. Finish by checking the value the report actually cites: after the change from six to nine, the fresh run must produce five.[3]&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;[1] &lt;a href="https://github.com/jupytext/jupytext" rel="noopener noreferrer"&gt;Jupytext project repository&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;[2] &lt;a href="https://jupytext.org/getting-started/install/" rel="noopener noreferrer"&gt;Jupytext installation&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;[3] &lt;a href="https://jupytext.org/using/paired-notebooks/" rel="noopener noreferrer"&gt;Paired notebooks&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;[4] &lt;a href="https://jupytext.org/using/cli/" rel="noopener noreferrer"&gt;Jupytext CLI&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;[5] &lt;a href="https://jupytext.org/using/config/" rel="noopener noreferrer"&gt;Jupytext configuration&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;Originally published at &lt;a href="https://enter.scholay.com/en/news/1d61f25622ee98d6f3a44c5da124f462/" rel="noopener noreferrer"&gt;EnterScholar&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.scholay.com" rel="noopener noreferrer"&gt;Scholay&lt;/a&gt; · &lt;a href="https://www.enterscholar.com" rel="noopener noreferrer"&gt;EnterScholar&lt;/a&gt;&lt;/p&gt;

</description>
      <category>git</category>
      <category>python</category>
      <category>tools</category>
    </item>
    <item>
      <title>Kaplan–Meier Curves: Calculation, Testing, and Misinterpretation</title>
      <dc:creator>Isaac Land</dc:creator>
      <pubDate>Sun, 22 Nov 2026 13:00:09 +0000</pubDate>
      <link>https://dev.to/landisaac1/kaplan-meier-curves-calculation-testing-and-misinterpretation-57ig</link>
      <guid>https://dev.to/landisaac1/kaplan-meier-curves-calculation-testing-and-misinterpretation-57ig</guid>
      <description>&lt;h1&gt;
  
  
  Kaplan–Meier Curves: Calculation, Testing, and Misinterpretation
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0f08a1etunmnyzt9y8tq.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0f08a1etunmnyzt9y8tq.webp" alt="Two step-shaped Kaplan–Meier survival curves by treatment group, plotted from the aml dataset in the R survival package." width="800" height="753"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Two Kaplan–Meier survival curves grouped by treatment; the data are the acute myeloid leukemia (aml) dataset bundled with the R survival package. Figure: Michaelg2015; source: Wikimedia Commons; license: CC BY-SA 4.0.&lt;/p&gt;

&lt;p&gt;The Kaplan–Meier curve (product-limit estimate) answers the question: when follow-up has not ended for some subjects and their outcomes are unknown, what proportion survives beyond a given time point? Proposed by Kaplan and Meier in 1958, it makes no assumption about the shape of the survival-time distribution. This entry uses a public dataset to demonstrate, step by step, the calculation, censoring marks, and the log-rank test, and explains common misuses such as ignoring competing risks, confusion over proportional hazards, and over-interpretation of the curve's tail.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Estimand and the Product-Limit Formula
&lt;/h2&gt;

&lt;p&gt;In survival analysis, "survival" broadly means that the event of interest has not yet occurred; the event may be death or relapse, or it may be equipment failure or conception. The quantity to be estimated is the survival function S(t), the probability that T exceeds t, the proportion of the population whose event time T exceeds t. The difficulty is censoring: some people have still not experienced the event when the study ends, others are lost to follow-up partway through, and all we know is that their event time is later than the last observation. In their 1958 paper, Kaplan and Meier referred to the event of interest generically as "death" and to events that prevent observation as "loss", noting that a loss may be accidental or may result from the investigator deliberately ending observation; they generally assumed that the lifetime and the potential loss time are independent of each other, while cautioning that this assumption needs careful scrutiny in practice.&lt;/p&gt;

&lt;p&gt;Computing a proportion directly goes wrong: excluding censored subjects throws away the information that "they survived at least until a certain time," so survival is underestimated; treating censored subjects as having survived throughout leads to overestimation. The product-limit estimate cuts the time axis at each event time, estimates the conditional probability of "surviving this segment" for each segment using only those still under observation at that time, and then multiplies the segment probabilities together. Censored subjects remain in the denominator until they are censored and drop out afterward. The original paper proves that, when no distributional form is imposed, this estimate is the distribution that maximizes the sample likelihood; if there is no censoring before time t, it reduces to the ordinary proportion surviving.&lt;/p&gt;

&lt;p&gt;$$\hat S(t)=\prod_{t_j\le t}\left(1-\frac{d_j}{n_j}\right),\qquad \widehat{\operatorname{Var}}\big[\hat S(t)\big]=\hat S(t)^2\sum_{t_j\le t}\frac{d_j}{n_j\,(n_j-d_j)}$$&lt;/p&gt;

&lt;p&gt;Here $t_j$ are the distinct event times, $n_j$ is the number of people still at risk just before $t_j$ (including those who have the event or are censored exactly at $t_j$), and $d_j$ is the number of events at $t_j$. The right-hand expression is Greenwood's formula; Kaplan and Meier used this name in Section 6 of their original paper.&lt;/p&gt;

&lt;p&gt;Data are usually recorded in two columns: time, and status (1 for an event, 0 for censoring). When an event and a censoring are recorded at the same time, by convention the event is taken to come first and the censoring afterward, so the censored subject is still counted in the risk set at that time; both Kaplan and Meier's original paper and Collett's textbook adopt this convention. When plotted, the curve is a step function that drops only at event times; it does not drop at censoring times, which are marked only by a short vertical tick or a "+" on the curve. If the last observation is censored, the curve is undefined beyond that time and cannot be extrapolated; if the last observation is an event, the curve drops to 0.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Step-by-Step Example with Glioma Data
&lt;/h2&gt;

&lt;p&gt;The example below uses a dataset published by Bland and Altman in their statistics notes in the British Medical Journal (BMJ): the number of weeks from entry to death or censoring for 51 adult patients with recurrent malignant glioma; the original study was a phase II trial by Rostomily et al. in 1994. By tumor type, the patients were divided into anaplastic astrocytoma (group A, 20 patients, 14 deaths, 6 censored) and glioblastoma (group G, 31 patients, 28 deaths, 3 censored). The observation times in group A were 6, 13, 21, 30, 31+, 37, 38, 47+, 49, 50, 63, 79, 80+, 82+, 82+, 86, 98, 149+, 202, 219 weeks ("+" denotes censoring). The table below computes the product-limit estimate for group A row by row; the values were calculated by hand, step by step, from the formula and are given to three decimal places.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Week&lt;/th&gt;
&lt;th&gt;At risk n&lt;/th&gt;
&lt;th&gt;Deaths d&lt;/th&gt;
&lt;th&gt;Censored&lt;/th&gt;
&lt;th&gt;Conditional survival (n−d)/n&lt;/th&gt;
&lt;th&gt;Ŝ(t)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;20&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;19/20&lt;/td&gt;
&lt;td&gt;0.950&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;13&lt;/td&gt;
&lt;td&gt;19&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;18/19&lt;/td&gt;
&lt;td&gt;0.900&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;21&lt;/td&gt;
&lt;td&gt;18&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;17/18&lt;/td&gt;
&lt;td&gt;0.850&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;30&lt;/td&gt;
&lt;td&gt;17&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;16/17&lt;/td&gt;
&lt;td&gt;0.800&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;31&lt;/td&gt;
&lt;td&gt;16&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;0.800&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;37&lt;/td&gt;
&lt;td&gt;15&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;14/15&lt;/td&gt;
&lt;td&gt;0.747&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;38&lt;/td&gt;
&lt;td&gt;14&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;13/14&lt;/td&gt;
&lt;td&gt;0.693&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;47&lt;/td&gt;
&lt;td&gt;13&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;0.693&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;49&lt;/td&gt;
&lt;td&gt;12&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;11/12&lt;/td&gt;
&lt;td&gt;0.636&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;50&lt;/td&gt;
&lt;td&gt;11&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;10/11&lt;/td&gt;
&lt;td&gt;0.578&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;63&lt;/td&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;9/10&lt;/td&gt;
&lt;td&gt;0.520&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;79&lt;/td&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;8/9&lt;/td&gt;
&lt;td&gt;0.462&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;80&lt;/td&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;0.462&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;82&lt;/td&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;0.462&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;86&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;4/5&lt;/td&gt;
&lt;td&gt;0.370&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;98&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;3/4&lt;/td&gt;
&lt;td&gt;0.277&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;149&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;0.277&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;202&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1/2&lt;/td&gt;
&lt;td&gt;0.139&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;219&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0/1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A few details are worth checking. At week 31, 1 person is censored and the curve does not drop, but the denominator at week 37 changes from 16 to 15, so the conditional survival is 14/15 rather than 15/16. At week 63, Ŝ(63) = 0.520, and Greenwood's formula gives a standard error of about 0.117; with a sample of 20, the estimate is quite rough. For comparison: if the two censored subjects at weeks 31 and 47 are excluded, the proportion surviving past week 63 is 9/18 = 0.50; if they are treated as having survived throughout, it is 11/20 = 0.55; the product-limit estimate falls between the two. The median survival time is taken as the time at which Ŝ(t) first falls to 0.5 or below; for group A it is 79 weeks. For group G, the estimate is 0.516 at week 30 and falls to 0.484 at week 33, so the median survival time is 33 weeks.&lt;/p&gt;

&lt;p&gt;The Python code below depends only on NumPy, SciPy, and Matplotlib. It implements the product-limit estimate, Greenwood standard errors, and the log-rank test according to the formulas in the previous section, and plots the two groups' curves with censoring ticks. The figures in the text were checked by hand using the same formulas, and the code can be run to verify them one by one.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;numpy&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;matplotlib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pyplot&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;plt&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;scipy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;stats&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;chi2&lt;/span&gt;

&lt;span class="c1"&gt;# Bland &amp;amp; Altman, BMJ 2004: weeks to death (event=1) or censoring (event=0)&lt;/span&gt;
&lt;span class="n"&gt;astro_time&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;13&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;21&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;31&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;37&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;38&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;47&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;49&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;63&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;79&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;82&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;82&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                       &lt;span class="mi"&gt;86&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;98&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;149&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;202&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;219&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;astro_event&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                        &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;glio_time&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;13&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;14&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;17&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;18&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;28&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;33&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                      &lt;span class="mi"&gt;34&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;35&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;37&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;46&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;48&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;70&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;76&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;81&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;82&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;91&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;112&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;181&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;glio_event&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;kaplan_meier&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="s2"&gt;"""Product-limit estimate with Greenwood standard errors."""&lt;/span&gt;
    &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;gw&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rows&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;1.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;unique&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;greater_equal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# subjects censored at t stay in the risk set&lt;/span&gt;
        &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;*=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;
        &lt;span class="n"&gt;gw&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;gw&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;greater&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;nan&lt;/span&gt;
        &lt;span class="n"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sqrt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;gw&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;rows&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;logrank&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;e1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;e2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;times&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;unique&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;concatenate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;t1&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;e1&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t2&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;e2&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;observed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;expected&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;variance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.0&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;times&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;n1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;greater_equal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;greater_equal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;d1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t1&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e1&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;d1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t2&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e2&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;n1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;n2&lt;/span&gt;
        &lt;span class="n"&gt;observed&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;d1&lt;/span&gt;
        &lt;span class="n"&gt;expected&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;n1&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;greater&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;variance&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;n1&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;n2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;stat&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;observed&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;expected&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;variance&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;observed&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;expected&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variance&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stat&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;chi2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stat&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;plot_km&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ax&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;rows&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;kaplan_meier&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;r_&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;r_&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mf"&gt;1.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;line&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ax&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;step&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;where&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"post"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;cens&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;idx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;searchsorted&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cens&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;side&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"right"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="n"&gt;ax&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;plot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cens&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;idx&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"|"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;markersize&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;markeredgewidth&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;1.5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;line&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_color&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"A"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;astro_time&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;astro_event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"G"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;glio_time&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;glio_event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"Group {name}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;tj&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;se&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;kaplan_meier&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"  week {tj:3}  n={n:2}  d={d}  S={s:.3f}  SE={se:.3f}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;obs&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;exp_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stat&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;logrank&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;astro_time&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;astro_event&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;glio_time&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;glio_event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"Log-rank: O_A={obs:.0f}  E_A={exp_:.2f}  V={var:.2f}  chi2={stat:.2f}  p={p:.4f}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;fig&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ax&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subplots&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;figsize&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;4.5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;plot_km&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ax&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;astro_time&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;astro_event&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Anaplastic astrocytoma (n=20)"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;plot_km&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ax&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;glio_time&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;glio_event&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Glioblastoma (n=31)"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;ax&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;xlabel&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Weeks since entry"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ylabel&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Estimated survival S(t)"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ylim&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;1.05&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;ax&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;legend&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"| marks censored times"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;fig&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;tight_layout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;fig&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;savefig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"km_glioma.png"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dpi&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;R users can perform the same calculations with the survival package:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight r"&gt;&lt;code&gt;&lt;span class="nb"&gt;library&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;survival&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;frame&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="n"&gt;group&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;rep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;c&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"A"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"G"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;c&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;31&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;time&lt;/span&gt;   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;c&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;13&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;21&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;31&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;37&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;38&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;47&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;49&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;63&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;79&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;82&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;82&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;86&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;98&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;149&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;202&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;219&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;13&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;14&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;17&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;18&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;28&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;33&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;34&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;35&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;37&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;46&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;48&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;70&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;76&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;81&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;82&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;91&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;112&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;181&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;c&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="nb"&gt;rep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;rep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;rep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;fit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;survfit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Surv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;~&lt;/span&gt; &lt;span class="n"&gt;group&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nb"&gt;summary&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;                                     &lt;span class="c1"&gt;# n.risk, n.event, survival, std.err&lt;/span&gt;
&lt;span class="nf"&gt;survdiff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Surv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;~&lt;/span&gt; &lt;span class="n"&gt;group&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;# log-rank test&lt;/span&gt;
&lt;span class="nb"&gt;plot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fit&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;mark&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;TRUE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;lty&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;xlab&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Weeks"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ylab&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Estimated survival"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F76p50j8cf5bh2r55e3fh.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F76p50j8cf5bh2r55e3fh.webp" alt="AI illustration of step-shaped survival curves for two groups of glioma patients, one falling noticeably faster, with short vertical ticks of the same color marking censoring times." width="800" height="626"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Illustration of step-shaped Kaplan–Meier survival curves for two groups of glioma patients: one curve falls noticeably faster, and short vertical ticks of the same color on the curves indicate censoring. The shapes of the curves and the positions of the steps are for illustration only and do not correspond to the actual values in this example; running the code above with the data published by Bland and Altman (BMJ 2004) plots the real curves for group A (anaplastic astrocytoma, n=20) and group G (glioblastoma, n=31). AI-generated illustration.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Log-Rank Test and Between-Group Comparison
&lt;/h2&gt;

&lt;p&gt;When comparing two groups' curves, picking a single time point (for example, 1-year survival) yields conclusions that change depending on the time point chosen. In 1966, Mantel proposed a chi-square procedure for comparing two life tables "as a whole," noting that when the intervals are made arbitrarily short it is essentially a rank test that can handle individual right censoring and ties; this is what is now commonly called the log-rank test. The procedure is to construct a 2×2 table at each event time t_j: if the two groups have the same risk, the expected number of events in group A is E_j = n_Aj × d_j / n_j. The observed counts O and expected counts E are summed separately across time points and then standardized by the hypergeometric variance V.&lt;/p&gt;

&lt;p&gt;$$\chi^2=\frac{(O_A-E_A)^2}{V},\qquad V=\sum_j\frac{n_{Aj}\,n_{Gj}\,d_j\,(n_j-d_j)}{n_j^2\,(n_j-1)}$$&lt;/p&gt;

&lt;p&gt;Under the null hypothesis, this statistic approximately follows a chi-square distribution with 1 degree of freedom (k − 1 degrees of freedom when comparing k groups). In the BMJ, Bland and Altman use the simpler approximation $\sum (O-E)^2/E$, which extends easily to multiple groups.&lt;/p&gt;

&lt;p&gt;Take the glioma data as an example. At the first death, in week 6, 51 people are at risk, 20 of them in group A, so the expected number of deaths in group A is 20 × 1/51 ≈ 0.39; at week 10, 2 people in group G die, when group A has 19 people and the total is 50, so the expected number of deaths in group A is 19 × 2/50 = 0.76. Summing over all event times, hand calculation gives about 22.50 expected deaths in group A and about 19.50 in group G; the BMJ paper reports 22.48 and 19.52, a difference of 0.02. The expected values given step by step in the original paper are rounded to two decimal places, so the discrepancy may come from rounding. Group A had 14 observed deaths, clearly fewer than expected; group G had 28 observed deaths, more than expected. The simplified BMJ formula gives χ² ≈ 6.92 (6.88 in the original); using the hypergeometric variance V ≈ 9.59 gives χ² ≈ 7.53, with 1 degree of freedom, P ≈ 0.006. Both methods give P less than 0.01: the difference in survival experience between the two groups is statistically significant, in the direction of more deaths than expected in the glioblastoma group.&lt;/p&gt;

&lt;p&gt;The log-rank test answers only "whether the two groups' survival experiences differ"; it does not tell how large the difference is and provides no confidence interval. To estimate the effect size, a Cox proportional hazards model is commonly used to give a hazard ratio. Because the test sums O − E with equal weight across event times, it is most likely to detect a difference when one group's risk is consistently higher than the other's; if the curves cross (for example, a surgery group with higher early risk but later benefit), early and late differences in opposite directions cancel each other out, and the test may not be significant. Bland and Altman therefore recommend always plotting the curves first when analyzing survival data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Assumptions, Common Misuses, and the Life-Table Method
&lt;/h2&gt;

&lt;p&gt;The Kaplan–Meier estimate and the log-rank test share several assumptions: censoring is unrelated to prognosis, meaning that at any moment those censored have the same survival prospects as those who remain under follow-up; people enrolled early and late have the same survival probabilities; and events occur at the recorded times. The first assumption is hard to test with data. Bland and Altman give the example of a conception study: if some people drop out of follow-up because they have not conceived after a long time, censoring is related to the outcome, and the estimated probability of "not conceiving" will be biased downward. If the groups violate the assumptions to different degrees—for example, if one group has markedly more loss to follow-up—the between-group comparison is affected most. In addition, every subject needs a clearly defined time origin; Kaplan and Meier's original paper lists "observation of the initial event that marks the beginning of the lifetime" as an assumption.&lt;/p&gt;

&lt;p&gt;The first kind of misuse is ignoring competing risks. If the outcome of interest is cardiovascular death and patients may die of other causes first, the latter is not a case of "the outcome has not been seen yet"; rather, it makes the event of interest impossible from then on. When competing events are treated as censoring, 1 − KM estimates the cumulative incidence in a hypothetical population in which "competing events do not exist," which is usually higher than in the real population. In a tutorial published in Circulation in 2016, Austin, Lee, and Fine reported that the 5-year incidence of cardiovascular death among patients hospitalized for heart failure was 43.0% when calculated with 1 − KM and 36.8% when calculated with the cumulative incidence function (CIF). When competing risks are present, the cumulative incidence function should be reported; for regression, either a cause-specific hazards model or the Fine–Gray model can be chosen depending on the research question (Putter et al. 2007; Austin et al. 2016).&lt;/p&gt;

&lt;p&gt;The second kind of misuse is conflating the proportional hazards assumption with KM. The KM curve is a nonparametric estimate and does not require the proportional hazards assumption; the log-rank test likewise does not require prior knowledge of the shape of the curves or of the survival-time distribution. Proportional hazards is an assumption of the Cox model and of the practice of "summarizing the entire follow-up with a single hazard ratio." Two confusions are common. The first is declaring that "KM is not applicable" upon seeing crossing curves, when in fact crossing curves are still a valid description; it is just that a single hazard ratio and the log-rank test are no longer suitable for summarizing the difference. The second is using the log-rank P value to imply that a constant hazard ratio exists. When the curves cross or the gap between them changes markedly over time, one can report survival rates with confidence intervals at several prespecified time points, or choose a model after checking the proportional hazards assumption.&lt;/p&gt;

&lt;p&gt;The third kind of misuse is over-interpreting small samples and the step shape of the curve's tail. A single event makes the curve drop by Ŝ(t)/n; the smaller the risk set n, the larger the step. In this example, group A has only 2 people left by week 202, and 1 death drops the estimate from 0.277 to 0.139; conversely, a long plateau in the tail often just means that the few people still under follow-up have not yet had an event, and does not represent "cure" or zero risk. Pocock, Clayton, and Altman (2002) recommend showing the extent of follow-up in the figure (such as the number at risk at each time point), giving standard errors or confidence intervals, truncating the curve when too few people remain under follow-up, and interpreting the curve shape and late differences with caution. The truncation approach proposed by Gebski et al. (2018) is for the investigators to prespecify the maximum acceptable drop that "1 more event" would cause; once this would be exceeded, the curve is not extended any further.&lt;/p&gt;

&lt;p&gt;Finally, there is the distinction from the life-table method. The life-table method is also called the actuarial method, and Kaplan and Meier's original paper calls it the actuarial estimate: it likewise multiplies conditional survival probabilities together, but the intervals are usually grouped, so the result depends to some extent on the choice of intervals. Collett's textbook calls the assumption that "censoring occurs uniformly within an interval, with the number at risk taken as n − c/2" the actuarial assumption, and points out that KM is precisely the limit of the life-table estimate as the number of intervals tends to infinity and the interval width tends to zero, which is why it is also called the product-limit estimate. When each person's exact time is known, grouping loses information, and KM should be preferred; when only the numbers of events and censorings in each interval are available, the life-table method is more appropriate.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Kaplan–Meier (product-limit method)&lt;/th&gt;
&lt;th&gt;Life-table method (actuarial method)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Time partitioning&lt;/td&gt;
&lt;td&gt;Split at each distinct event time&lt;/td&gt;
&lt;td&gt;Intervals defined in advance, commonly 5–15&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Handling of censoring&lt;/td&gt;
&lt;td&gt;Censored subjects remain in the risk set until the time of censoring&lt;/td&gt;
&lt;td&gt;Censoring assumed to occur uniformly within the interval; number at risk taken as n − c/2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Dependence on grouping&lt;/td&gt;
&lt;td&gt;None&lt;/td&gt;
&lt;td&gt;Varies with the choice of intervals, similar to a histogram&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Suitable data&lt;/td&gt;
&lt;td&gt;Exact time known for each person&lt;/td&gt;
&lt;td&gt;Only the numbers of events and censorings in each interval&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Kaplan EL, Meier P. Nonparametric estimation from incomplete observations. &lt;em&gt;Journal of the American Statistical Association&lt;/em&gt;, 1958, 53(282): 457–481. &lt;a href="https://doi.org/10.1080/01621459.1958.10501452" rel="noopener noreferrer"&gt;doi:10.1080/01621459.1958.10501452&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Mantel N. Evaluation of survival data and two new rank order statistics arising in its consideration. &lt;em&gt;Cancer Chemotherapy Reports&lt;/em&gt;, 1966, 50(3): 163–170. &lt;a href="https://pubmed.ncbi.nlm.nih.gov/5910392/" rel="noopener noreferrer"&gt;PubMed 5910392&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Bland JM, Altman DG. Survival probabilities (the Kaplan-Meier method). &lt;em&gt;BMJ&lt;/em&gt;, 1998, 317: 1572. &lt;a href="https://doi.org/10.1136/bmj.317.7172.1572" rel="noopener noreferrer"&gt;doi:10.1136/bmj.317.7172.1572&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Bland JM, Altman DG. The logrank test. &lt;em&gt;BMJ&lt;/em&gt;, 2004, 328: 1073. &lt;a href="https://doi.org/10.1136/bmj.328.7447.1073" rel="noopener noreferrer"&gt;doi:10.1136/bmj.328.7447.1073&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Pocock SJ, Clayton TC, Altman DG. Survival plots of time-to-event outcomes in clinical trials: good practice and pitfalls. &lt;em&gt;The Lancet&lt;/em&gt;, 2002, 359(9318): 1686–1689. &lt;a href="https://doi.org/10.1016/S0140-6736(02)08594-X" rel="noopener noreferrer"&gt;doi:10.1016/S0140-6736(02)08594-X&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Gebski V, Garès V, Gibbs E, Byth K. Data maturity and follow-up in time-to-event analyses. &lt;em&gt;International Journal of Epidemiology&lt;/em&gt;, 2018, 47(3): 850–859. &lt;a href="https://doi.org/10.1093/ije/dyy013" rel="noopener noreferrer"&gt;doi:10.1093/ije/dyy013&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Putter H, Fiocco M, Geskus RB. Tutorial in biostatistics: competing risks and multi-state models. &lt;em&gt;Statistics in Medicine&lt;/em&gt;, 2007, 26(11): 2389–2430. &lt;a href="https://doi.org/10.1002/sim.2712" rel="noopener noreferrer"&gt;doi:10.1002/sim.2712&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Austin PC, Lee DS, Fine JP. Introduction to the analysis of survival data in the presence of competing risks. &lt;em&gt;Circulation&lt;/em&gt;, 2016, 133: 601–609. &lt;a href="https://doi.org/10.1161/CIRCULATIONAHA.115.017719" rel="noopener noreferrer"&gt;doi:10.1161/CIRCULATIONAHA.115.017719&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Collett D. &lt;em&gt;Modelling Survival Data in Medical Research&lt;/em&gt;. 4th ed. Boca Raton: CRC Press, 2023. &lt;a href="https://doi.org/10.1201/9781003282525" rel="noopener noreferrer"&gt;doi:10.1201/9781003282525&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://metho.scholay.com" rel="noopener noreferrer"&gt;Research Methods&lt;/a&gt; · Rituals can be imitated; understanding cannot be faked&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;This information was compiled and published by &lt;a href="https://www.scholay.com/t/M4ZZW8KRE5" rel="noopener noreferrer"&gt;Scholay One-Stop Academic Platform&lt;/a&gt;; in case of any infringement, please let us know and it will be taken down.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;This information is also published on &lt;a href="https://enterscholar.com" rel="noopener noreferrer"&gt;EnterScholar&lt;/a&gt;, a community for scholars in the age of intelligence&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;Originally published at &lt;a href="https://metho.scholay.com/en/news/draft-65708a63-236a-470e-bd02-1e6014310dbb/" rel="noopener noreferrer"&gt;Metho&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>analytics</category>
      <category>data</category>
      <category>science</category>
    </item>
  </channel>
</rss>
