Saturday, 24 August 2024

Bayes at the Bus Stop

 I make no claims to be a statistician (though I recently read a textbook* on Bayesian probability from cover to cover) and I apologise for any errors in this post: my excuse, in the words of Dr Johnson, is "Ignorance, madam, pure ignorance".

But having made that caveat, I feel that I think like a Bayesian when I am waiting for my bus home.   If there are a lot of people waiting, I reduce my estimate of my likely wait.  If there are a lot of people waiting, but then the other bus that the stop serves arrives and they all get on it, I raise my estimate.  If I see my bus leaving just before I arrive at the stop, I expect a longer wait.  And so on.

Now, I have always known that there are pitfalls in taking averages.  If I ask random people how long was their last wait for a bus and take the average, assuming they answer accurately I will possibly get a meaningful estimate of waiting times.  But if I ask random people who play golf what was the result of the last shot they played, almost all of them will have holed that shot.  That doesn't mean that almost all golf shots are holed!  Similarly if I ask cricketers what happened to the last ball they faced, most will have got out to it, but that doesn't mean that most cricket balls take a wicket.

But here is a point I have only recently fully appreciated.  What is the average class size in a school?  If a school has 60 students and two classes it might seem that the average is 30 students per class.  Suppose they are divided so that one class contains 35 students and the other 25.  The average still seems to be 30 students per class.  But if I ask every student how many are in their class, 25 will say "25" and 35 will say "35", so that average is actually higher - 30.833 by my calculation.  And arguably this is a much more meaningful figure since it better represents the experience of the students.

OK.  So now suppose that sometimes when I am waiting for my bus a friend meets me by chance at the bus stop, and that, whenever that happens, they afterwards ask me how long my total wait for the bus was on that occasion.  Let's make a few assumptions - buses come every 20 minutes, I arrive randomly at the bus stop so my average wait is uniformly distributed between 0 and 20, and I don't see buses coming or going: they materialise and dematerialise instantly giving me no clue as to how recently the last bus came.  My friend similarly arrives entirely randomly.  And of course we assume that the bus stop and my phone don't display live information about how far away the bus is, which takes all the fun out of waiting for a bus.** 

How long does my friend think my average wait is based on the data they gather?  I should be able to calculate this directly but out of laziness I simulated it in Excel.  Excel tells me (in one typical simulation of 1000 waits) that my average wait was 10.0904 minutes, while my friend's estimate was 13.3478 minutes.  Of course my friend's estimate is larger than my experience because they are more likely to meet me during a long wait than a short one.

So - here's the question.  I am waiting at the bus stop when I see my friend coming to join me.  Should I revise upwards my estimate of my likely wait, since on the occasions I meet my friend my wait is longer?  And how about if I see my friend on the other side of the street, but they don't see me?

I think I know the answer but I will leave you to think about it if you are so inclined.

* Chris Ferris, Bayesian Probability for Babies

** Not that there is any fun in waiting for a bus


Monday, 27 May 2024

A puzzle from my childhood

I've reconstructed a puzzle which I remember being amused by when I came across it in a school textbook.

We expect that if you add a quantity to itself, and then take half of the result, you get the origal quantity.  That doesn't happen here.

Background: Imperial measurements. One rod (or perch) is 5.5 yards. 1 chain is 4 perches or 22 yards.  1 furlong is 10 chains or 220 yards  One mile is 8 furlongs or 1760 yards.   

Now. let's start with a distance of 1 mile, 7 furlongs, 9 chains, 3 rods and 7 yards,  Let's add this to itself.  

        

Handwritten calculation

            1    7    9    3    7

    +    1    7    9     3    7

    =    4    0    0    0    3   which when we divide by 2 gives

          2    0    0    0    1.5

So the sum is four miles and 3 yards, and if we divide this by two, we get 2 miles 0 furlongs 0 chains 0 rods and 1.5 yards - not what we started with!  Can you explain?

(The addition, in detail, from the right)

7 yards plus 7 yards is 14 yards which is 2 rods plus 3 yards,

3 rods plus 3 rods plus 2 rods (carried) is 8 rods which is 2 chains plus 0 rods,

9 chains + 9 chains plus 2 chains(carried) is 20 chains = 2 furlongs 0 chains,

7 furlongs + 7 furlongs plus 2 furlongs (carried) is 16 furlongs = 2 miles 0 furlongs

1 mile + 1 mile plus 2 miles (carried) is 4 miles.


Friday, 1 March 2024

My Wordle failure

 Earlier this week, on 24 February,  my Wordle streak of over 200 successes came to a sad end. (For those who don't know the game, each day one has to deduce a five-letter word in at most six guesses, learning after each attempt whether each letter is correct and in the correct place, or correct but out of position.)  I play the hard version, which requires that each guess be consistent with the results of all previous attempts.

After two guesses I knew the word had the form _I_ER.  At this point I was in trouble - the hard version meant that every subsequent guess had to have this form, so I could try only two new letters each time and there were too many possibilities to guarantee success in the six permitted rounds.  And I failed to find the right one.

So I was interested to see this puzzle tackled by Mark Goodliffe of Cracking the Cryptic.   He faced the same problem I did.  Spoiler warning - next sentence is in white text so you don't have to read it.  Mark succeeded - with a little good fortune, which I feel he thoroughly deserved because he was aware of the possibility of repeated letters, which I had overlooked.  But (without indulging in schadenfreude) I was relieved to see from the comments that I was not the only person whose streak had ended with that puzzle - perhaps I shouldn't blame myself too much!

So how could I have done better? It seems to me that as soon as I knew that the solution contained E and R I was in difficulty.  My strategy is to choose an opening guess that is made up of common letters.  But perhaps if I want to be sure of success in six guesses I can't afford to have both E and R in my initial guess?  

Of course, success in six attempts isn't the only possible objective.  I am tyring to get my average number of attempts as far below 4 as I can, and so I may have to accept the occasional failure in order to achieve that goal - a strategy that guarantees success in six goes every time might have a higher average number of guesses.  

I know there are people who have done much more analysis than I have who know exactly how to optimise their choices but my comments are based on intuition rather than hard evidence!

Monday, 1 January 2024

Laptop irritations

 This isn't really maths (except in so far as all computing is maths) but I am going to vent a couple of frustrations regarding laptops.  

First, I am sure there is a good reason for this design feature and I would be delighted if someone could enlighten me.  Here is part of the keyboard of this laptop:

Laptop keyboard

Now, note the position of the on/off switch (lit up in the photo). It's in the middle of the top row of keys. Why?  In other laptops I have used, the on/off switch is easy to find because it is placed apart from the other keys.  With this keyboard, it's hard to find (with my eyesight the marking isn't very clear to me, especially in low light, and of course it isn't lit up when I want to switch the laptop on).  Worse, it is next to the delete key, and on more than one occasion I have hit the off key instead of delete.  (You have to hold it down for a time to switch the machine off, and so far I have only accidentally switched it off once when in the middle of a piece of work, but the possibility is now always in the back of my mind.)

It seems to me utterly illogical to place the on/off switch where it is.  But it is so illogical that there must have been a deliberate design decision to do so and there must be a good reason for it.  Can anyone tell me?

My second point is just venting at an irritation.  I don't like my laptops making noises when I am working, so the first thing I do is switch off all notifications.  But still some persist.  (Why, when I save a Word document as a PDF and the file already exists, does it have to beep as well as displaying an "are you sure" box?  I find myself swearing aloud at the machine when it does this, and I have spent more time than it is worth trying to find out how to switch it off.)

What is worse than that is that the machine makes random beeps at odd times.  (These do not correlate to emails arriving or anything like that, as far as I can tell.)  It even does it when I have locked the computer.  Presumably these are important warnings, but I can't find out what they are.  Nothing has popped up in another window and there is no indication that I can see as to the reason for the beep.  What event is so important that the laptop has to interrupt me to tell me it has occurred, but isn't sufficiently important for me to be told what has happened?