Cutting Logs Part 1: Catching Ideas and Z's


Trouble Sleeping

Along with many other Americans, I often have a little trouble sleeping after a long day of staring at computer screens. My favorite solution at the moment is to take melatonin supplements. Like a lot of vitamins, it's a very iffy method with no regulation on dosage size or measure of effectiveness. Thus, while the limited scientific material I could find suggests between .5-1.5 mg for consumption, the smallest size I can find in the store comes in 3 mg. My solution for this has been to cut the pills in half, and throw the unused half back in the bottle.

This went well until the other week, when I began to be bothered by the sensation that I only seemed to ever pull full pills from the bottle, despite having them around for months. So, I did what any normal person does with a vague but quantifiable suspicion and built a model to study the concentration of whole and half pills in the bottle over time, and the subsequent likelihood of pulling one or the other.

Approach

Using Excel and VBA, I created a simple simulator that takes a pill at random from the bottle, creating a new half piece if a full piece is drawn, and consuming the half otherwise. Given my dedication to drawing pills in this way in real life, I was confident this would be an accurate model. Finally, I started with 500 pills in the bottle since that is what it said on the label. The results are below.


As we can see in this simple chart, not until I've reached 400 or so iterations (80% of the original number), do I become more likely to pull the halves out. The answer was straightforward, but after running the simulation a few more times I was intrigued but how smooth and regular the graphs kept coming out. I wanted to see if I could derive these slopes to get a more precise prediction. By using partial counts (i.e. making average draws from the bottle), I was able to come up with the following prediction for the composition over time.



And isn't that pleasing to the eye. A chi-squared test showed that this was about as perfect a prediction as one can get, and I can now say with certainty that I predict that I will start drawing more half pills than full ones at 447 iterations. 

The graph does have some tempting characteristics. With such a simple set-up, I feel strongly that I could find a distribution to predict this analytically. Anything more complicated than a poisson distribution with static probabilities is a little beyond my derivation aptitude, so for now I'll have to remain content.

Next Steps

As with any delightful findings, I am still drawn to attempt to generalize or find another application. In part 2 of this series, I'll look at seeing if I can find some applications in the construction world for drawing and replacing different intervals.

Click to download the Excel file.

Comments

Popular posts from this blog

What does it take to win at Kaggle? An Introduction to Data Strategy

Creating a Dynamic Calendar