Saturday, February 19, 2011

Quick Look: Uphill Struggle

When the parent's work schedules both coincide with a school day, it's often my displeasure to have to retrieve the small one from school. And because I don't drive, that's a ~30min round trip, which involves a fairly steep hill.

I don't much care for it.

I didn't track how many times that happened last year. But out of shear curiosity, and because I can, I tried modelling the set up to get an estimate.

You could probably work it out with probability alone. But that's too much like hard work.


Firstly, we assume I can randomise the parent's shifts - that is, there's no particular pattern to them. We also assume that their shifts are independent of each other and of school days and school holidays. That's not strictly true. But since there isn't a strong, underlying pattern linking them, we just ignore it.

Same goes for holidays, which in this model are also arranged at random. We can also ignore date, month, etc. because of the above assumptions and because it's just easier that way.

And finally, we ignore sick days, study days and over-time, since they aren't really predictable, and should hopefully average out over repeated trials.

I've also included a 10% chance that, for whatever reason, I won't have to pick the sister up. That number's just a random guess.

Hand-waving explanation

First you create three sets representing a year's worth of shifts for each of my parent and a year's worth of school. You then randomly delete a year's worth of holidays, bank holidays, and training days from the sets.

Finally, you count on how many days, shifts and school days coincide.

You can look at the code here.

Since this is another random use of the Monte Carlo method - you run the model 10,000 times and then draw a histogram of the resulting counts.

Hey Look!

It's a normal distribution
Which isn't that surprising.

The average is around 32 times a year, with about 78% chance that I'll have to pick up the young 'en between 27 and 37 times in any given year.

Oh, and obviously if you increase the 10% probability mentioned above, the average will get smaller (and vice versa)
And that's pretty much it. Any questions?


No comments: