Probability Calculator

by Ron Eaglin

HTML

<h1>Infection Probability Calculator </h1>
This will calculate your odds of contracting any illness based on the number of people with current infections in the
population. This number is given as active cases per 100,000 people and is often reported as this in news releases. The 
calculator assumes all contacts are random and with a random person from the population (huge assumption). Probability of infection per contact can be increased (close contact) up to 100% or decreased through social distancing and masks to values as low as 1%. 
<br/><h2>Number of local cases</h2>
<div>
  <input type="radio" id="Load1" name="load" value="load1" onchange="document.getElementById('infected').value='5';">
  <label for="Contact1">Low level Local cases</label>
</div>

<div>
  <input type="radio" id="Load2" name="load" value="load2" onchange="document.getElementById('infected').value='18';" checked>
  <label for="SocialDist2">Average level local cases</label>
</div>

<div>
  <input type="radio" id="Load3" name="load" value="load3" onchange="document.getElementById('infected').value='1500';">
  <label for="SocialDist3">High level local cases</label>
</div><br/>
Local Number Infected per 100,000 people (published statistic): <input type="textbox" id="infected" value="50" />
<br/>
<a href="https://www.usatoday.com/story/money/2020/04/17/states-with-the-highest-number-of-covid-19-cases/111552340/" target="_new">reference of states with actual cases per 100K</a>
<hr/>
<h2>Number of Social Contacts</h2>
<div>
  <input type="radio" id="Contact1" name="contact" value="contact1" onchange="document.getElementById('contacts').value='10';">
  <label for="Contact1">Many Contacts Daily (10)</label>
</div>

<div>
  <input type="radio" id="Contact2" name="contact" value="contact2" onchange="document.getElementById('contacts').value='5';" checked>
  <label for="SocialDist2">Average Contacts Daily (5) </label>
</div>

<div>
  <input type="radio" id="Contact3" name="contact" value="contact3"...

JavaScript

function Calculate(){
   var infected=parseFloat(document.getElementById("infected").value)/100000;
   var contacts=parseInt(document.getElementById("contacts").value);
   var c_prob=parseFloat(document.getElementById("probability").value)/100;

   ind_prob = infected*c_prob;
   cum_prob_1 = 1 - Math.pow((1-ind_prob),(contacts-1));
   cum_prob_7 = 1 - Math.pow((1-ind_prob),(7*contacts-1));
   cum_prob_30 = 1 - Math.pow((1-ind_prob),(30*contacts-1));

document.getElementById("output").innerHTML = "";
  document.getElementById("output").innerHTML += "Probability of Infection Per Contact (%) : " + ind_prob*100 + "<br/>"
	document.getElementById("output").innerHTML += "Probability of Infection in one day (% Per Day): " + (cum_prob_1 * 100).toFixed(5) + "<br/>"
	document.getElementById("output").innerHTML += "Probability of Infection in one week (% Per Week): " + (cum_prob_7 * 100).toFixed(3) + "<br/>"
	document.getElementById("output").innerHTML += "Probability of Infection in one month (% Per Month): " + (cum_prob_30 * 100).toFixed(3) + "<br/>"
  
}