Wednesday, July 23, 2008

Condom failure rates and the spread of HIV

After tackling the effect of condom failure rates on population growth, let's look at the failure rates on the spread of HIV.

I'll pose it as an ACM-type programming question. Ready?

Problem: Given a population of 100 swingers who have sexual intercourse once a week with different partners from the pool, assuming a perfectly fair round-robin distribution (i.e., no repeat partners until after they have had intercourse with everyone else in the pool), and assuming they use condoms; how many weeks until all 100 swingers have been infected with HIV, assuming that one of them is HIV-positive at the beginning?

Use a condom failure rate of 15% and average the result over 1,000 iterations.

Now, you can't use a spreadsheet to solve for this as it's a little more involved. You'd need to use a program. It's tricky, but not impossible. Below is my solution, in Python:


#!/usr/bin/python

import pairing
import array
import random
import sys

def swinger_infection_estimate(population,failure_rate):
 #initialize the swingers
 swingers=array.array('i')
 for i in range(population):
   swingers.append(0)
   swingers[0]=1

 # arrange the schedule
 schedule=pairing.roundRobin(range(population))


 #initialize counter
 week=0

 while(1):
   for i in range(len(schedule)):
     week=week+1
     for j in range(len(schedule[i])):
       if swingers[schedule[i][j][0]] ^ swingers[schedule[i][j][1]]:
         if random.random() < failure_rate:
           swingers[schedule[i][j][0]]=1
           swingers[schedule[i][j][1]]=1
         try:
           swingers.index(0)
         except ValueError:
           return week

estimate_ctr=0
for i in range(1000):
 estimate_ctr=estimate_ctr+swinger_infection_estimate(100,0.02)

print estimate_ctr/1000



The pairing algorithm I am using is adapted from the ActiveState round robin generator cookbook:


def roundRobin(units, sets=None):
   """ Generates a schedule of "fair" pairings from a list of units """
   if len(units) % 2:
       units.append(None)
   count    = len(units)
   sets     = sets or (count - 1)
   half     = count / 2
   schedule = []
   for turn in range(sets):
       pairings = []
       for i in range(half):
           pairings.append([units[i],units[count-i-1]])
       units.insert(1, units.pop())
       schedule.append(pairings)
   return schedule




Please check the logic of my code to see if it covers everything I've said. I would like to hear from you if you have a different opinion.

The result of these calculations: given the above assumptions, the entire population of 100 swingers will all be HIV-infected in anywhere from 81 to 83 weeks, or just a little over one and a half years. Individual sampling show full-infection estimates of up to 120 weeks (two years and four months) to as little as 63 weeks (one year and two months).

Consider now the results with no condom usage at all, i.e., assuming 100% failure rate. How long does it take to infect the entire population? It takes 50 weeks, or about a year. Under these assumptions, condoms delay the onset of full infection by 33 weeks.

Assuming a more generous 2% failure rate (unrealistic, in my view), it takes much longer to infect the entire population, around 510 weeks, or a little less than ten years. However: using the 2% failure rate of condoms in a monogamous relationship in which one partner is HIV-infected, the risk of infection is one in every fifty encounters. Assuming a weekly sexual encounter, infection is likely within a year.

Note: Please understand that I do not pose these questions to make fun of or condemn HIV victims. I do so because I believe that the claims around safe sex are fallacious, and that its advocates are grossly misrepresenting the dangers and condoning risky behavior.

Update: Roy, in the comments section below, points out an error in my assumptions with regard to transmission. At best, my approach shows the situations in which condom failure will occur, not necessarily transmission.

As far as I have searched, there are no established and proven probability rates for transmission in encounters.

A CDC document on the subject examines the issue in greater detail.

10 comments:

  1. Dominique,

    The round robin is not very realistic and not by a long shot will this scenario play out in the Philippines.

    Even in the field of medicine there is no guarantee that they can cure illnesses all the time or 100% batting average because if that happens people will not die anymore.

    Having 85% protection is better than having no protection at all....

    ReplyDelete
  2. Jaywalker:

    Having 85% protection is better than having no protection at all....

    I'll leave you to meditate on the rationality of that statement, and the one that preceded it. The end result is not a pregnancy that you can terminate, it's a virulent incurable life-threatening disease.

    The scenario was not meant to be a full simulation but only an indication. It's other shortcomings are: it only posits one incident of sexual penetration per week. As to whether the round robin scenario is realistic or not, consider the other possibilities in prostitution and partner exchanges. If I reduce the population -- as will likely be the case -- the time to hit full infection will be much less.

    ReplyDelete
  3. Dom,
    Although I agree with you that there is still a risk at transmitting HIV with the use of condom, from the medical point of view, the protection you get from it far exceeds that of not having one during sexual intercourse. If the perceive problem with condom use is the supposed to be inherent condoning of promiscuous sex, that should be addressed with behavioral education so that the person can have a "wise" choice. It is exactly the failure of our society and culture to do such form of education that's why we panicked to use this temporary condom solution.

    ReplyDelete
  4. I just took a very quick look at the code, but you don't seem to take into account that a person does not get infected every time the condom breaks.

    Wikipedia (that bastion of accurate information) says that 50 out of 10,000 exposures (assuming the riskiest behavior--anal sex) causes infection.

    For unprotected sex, that translates to 200 weeks (~4 years) on average for the next person to be infected. If that person wears a condom and breakage occurs 15% of the time, that translates to infection once every 1300 weeks... about 25 years on average for the second person to be infected.

    At 2% breakage, 1 out of every 10,000 exposures will cause infection, translating to 192 years on average for the next person to be infected.

    ReplyDelete
  5. Thanks for the correction, Roy. That is something I failed to consider. Looks like I'll have to revise my approach to this.

    On the other hand, the 50-in-10,000 translates to 0.5%, and that seems to be far too low to explain the spread by sexual behavior.

    ReplyDelete
  6. Remo: point taken. Thank you for pointing that out.

    ReplyDelete
  7. Good attempt at modeling this Dom. Of course the real world never follows the virtual (we wish), but the models help us put structure to the seemingly unpredictable variables that affect HIV transmission.

    A study has shown that transmission (at least in the Philippines) is very much related to circles -- ie, a monogamous relationship is rarely (if never except for blood transfusions) infected with HIV mainly because their circle does not intersect with those who are not monogamous. A similar mathematical model using the circle approach will also be interesting.

    Alas, I am not a programmer nor a mathematician to comment intelligently on your python model. Although you made some sweeping generalizations (eg., "sex once a week" -- yeah right), I can see this model slowly seeing its way to scientific literature. If you can get your hands on empirical data, then the model can be more specific.

    I would encourage pursuing this and adding a strong spin for the Filipino type of sexuality. The combination of model + empirical data deserves attention in some literary quarters.

    ReplyDelete
  8. Bone MD offers the most pragmatic informed take on the subject that just shows the power of educated awareness over the Talibani approach...... of inciting fear based on ignorance and dogmas.

    ReplyDelete
  9. The National Institutes of Health in 2001 investigated the world scientific literature relating to the ability of condom use to reduce the risk of the transmission of sexually transmitted disease.3 The NIH in 2001, found that the consistent and correct use of the condom reduced the risk of HIV transmission by 85%. A 15% risk remained. A more recent study, in 2003, concluded that consistent use of the condom results in only 80% reduction in HIV transmission.4 Other circumstances such as rupture of a condom increase the risk. Liviana Calzavera PhD., an epidemiologist at the University of Toronto, Faculty of Medicine, has stated that imperfect condom use probably offers as high a risk of transmitting HIV as does intercourse without the use of the condom.5

    ReplyDelete
  10. found this for you:
    http://www.whfhhc.com/HIV/45288.htm

    says there, that the odds of getting aids from HIV positive, during normal sex (with no protection) is 1 in 500 (0.2%), also metions there, that 10 times with a condom, is like 1 time without (risk with protection, while the partner is positive, is 1 in 5000).

    ReplyDelete