Header tag

Monday, 16 May 2011

Web Analytics: Experimenting to Test a Hypothesis

Experimenting to Test a Hypothesis

After my previous post on reporting, analysing, forecasting and testing, I thought I'd look in more detail at testing.  Not the how-to-do-it, although I'll probably cover that in a later post, but how to take a test and a set of test results and use them to drive recommendations for action.  The action might be 'do this to improve results' or it might be 'test this next'.
As I've mentioned before, I have a scientific background, so I have a strong desire to do tests scientifically, logically and in an ordered way.  This is how science develops - with repeatable tests that drive theories, hypotheses and understanding.  However, in science (by which I mean physics, chemistry and biology), most of  the experiments are with quantitative measurements, while in an online environment (on a website, for example), most of the variables are qualitative.  This may make it harder to develop theories and conclusions, but it's not impossible - it just requires more thought before the testing begins!

Quantitative Data

Quantitative data is data that comes in quantities - 100 grams, 30 centimetres, 25 degrees Celsius, 23 seconds, 100 visitors, 23 page views, and so on.  Qualitative data is data that describes the quality of a variable - what colour is it, what shape is it, is it a picture of a man or a woman, is the text in capitals, is the text bold?  Qualitative data is usually described with words, instead of numbers.  This doesn't make the tests any less scientific (by which I mean testable and repeatable) it just means that interpreting the data and developing theories and conclusions is a little trickier.

For example, experiments with a simple pendulum will produce a series of results.  Varying the length of the pendulum string leads to a change in the time it takes to complete a full swing.  One conclusion from this test would be:  "As the string gets longer, the pendulum takes longer to run."  And a hypothesis would add, "Because the pendulum has to travel further per swing."

Online, however, test results are more likely to be quantitative.  In my previous post, I explained how my test results were as follows:

Red Triangle  = 500 points per day
Green Circle  = 300 points per day
Blue Square = 200 points per day

There's no trending possible here - circles don't have a quantity connected to them, nor a measurable quantity that can be compared to squares or triangles.  This doesn't mean that they can't be compared - they certainly can.  As I said, though, they do need to be compared with care!  In my test, I've combined two quantitative variables - colour and shape - and this has clouded the results completely and made it very difficult to draw any useful conclusions.  I need to be more methodical in my tests, and start to isolate one of the variables (either shape or colour) to determine which combination is better.  Then I can develop a hypothesis - why is this better than that, and move from testing to optimising and improving performance.
Producing a table of the results from the online experiments shows the gaps that need to be filled by testing - it's possible that not all the gaps will need to be filled in, but certainly more of them do!

Numerical results are points per day


COLOUR Red GreenBlueYellow
SHAPE   


Triangle 500   

Circle
300

Square

200

Now there's currently no trend, but by carrying out tests to fill in some of the gaps, it becomes possible to identify trends, and then theories.

Numerical results are points per day


COLOUR Red GreenBlueYellow
SHAPE   


Triangle 500
399
Circle 409 300
553
Square
204200


Having carried out four further tests, it now becomes possible to draw the following conclusions:

1.  Triangle is the best shape for Red and Blue, and based on the results it appears that Triangle is better than Circle is better than Square.
2.  For the colours, it looks as if Red and Yellow are the best.
3.  The results show that for Circle, Yellow did better than Red and Green, and further testing with Yellow triangles is recommended.

I know this is extremely over-simplified, but it demonstrates how results and theories can be obtained from qualitative testing.  Put another way, it is possible to compare apples and oranges, providing you test them in a logical and ordered way.  The trickier bit comes from developing theories as to why the results are the way they are.  For example, do Triangles do better because visitors like the pointed shape?  Does it match with the website's general branding?  Why does the square perform lower than the other shapes?  Does its shape fit in to the page too comfortably and not stand out?  You'll have to translate this into the language of your website, and again, this translation into real life will be trickier too.  You'll really need to take care to make sure that your tests are aiming to fill gaps in results tables, or instead of just being random guesses.  Better still, look at the results and look at the likely areas which will give improvements. 

It's hard, for sure:  with quantitative data, if the results show that making the pendulum longer increases the time it takes for one swing, then yes, making the pendulum even longer will make the time for one swing even longer too.  However, changing from Green to Red might increase the results by 100 points per day, but that doesn't lead to any immediate recommendation, unless you include, "Make it more red."  

If you started with a hypothesis, "Colours that contrast with our general background colours will do better" and your results support this, then yes, an even more clashing colour might do even better, and that's an avenue for further testing.  This is where testing becomes optimising - not just 'what were the results?', but 'what do the results tell us about what was best, and how can we improve even further?'.

In my next posts in this series, I go on to write about how long to run a test for and explain statistical significance, confidence and when to call a test winner.

Sunday, 15 May 2011

Physics: The Sound Barrier and Sonic Booms

After sobering up from his drunken walk home, Isaac Newton went to see his friend, Mr Science.  However, as Isaac went along, he noticed that the roadway to Mr Science's house was very busy; Mr Science lived in the middle of town, and it was market day, and Isaac found that there were large crowds of people milling around in front of him.  Still, walking was definitely the quickest way to see his friend, as although gravity had been invented, cars were still some way off in the future.

Isaac Newton was quite keen to get to Mr Science's house to discuss his adventures with apples, including his failed attempt to launch it into space, and started jogging and jostling through the crowd, shouting at people to move out of the way, instead of just meandering through it.  He bumped into people more frequently as he did so, but kept on jogging undeterred, and found that the faster he jogged, the more people he bumped into; in the end, he put his arms out in front of him like a wedge and started pushing his way through with more effort.  This continued until he found that crowds of people were gathering together in front of him, despite him shouting at them, they were barely unable to get out of his way before he started ploughing into them.  Finally, he realised he was going that fast, that the people, all bunched up in front him and desperate to get out of his way, were unable to stand aside and he sent the crowds tumbling left and right in front of him.

When he arrived at Mr Science's house, he recounted the strange behaviour of the crowd and the various stages he'd encountered. "That's interesting," commented Mr Science, "That reminds me of an experiment I've just been running."

Isaac's journey through the crowd is very similar to an aircraft (or a car) as it travels at speeds close to the speed of sound.  The atmosphere is made up of gas particles which travel around, silently bouncing off each other and generally behaving randomly (in the real sense of the word), at speeds which are close to - but less than - the speed of sound.  Particles in a gas are extremely small (as all particles are), and by comparison, the spaces between them are relatively large.  This means that there are large gaps between them, and if you move a large, solid object between them (or, for example, start walking through them) then you're able to push them aside and move through the gas.  

Walking at low speeds, you're not likely to notice this effect, but at larger speeds, for example running, you'll feel the air as it rushes past your face.  Cycling through the air, you'll feel this more strongly, and as you increase your speed, you'll begin to feel the effort of pushing through the air - it'll feel as if there's a wind blowing into you, pushing you back.  This is known as 'air resistance' and it increases as your speed increases.  You're pushing more and more air particles aside, as you cut through the air, and this takes more effort.  At these speeds, it becomes more and more important to get into an aerodynamic position - as low down as possible, elbows tucked in, and so on, to cut through the air as economically and as easily as possible.  In Isaac Newton's case, he put his arms out in front of him like a wedge, so that he could push through the crowds of people as easily as possible.

Now, the gas particles in the atmosphere are bouncing around, flying around at close to (but less than) the speed of sound, which is 330 metres per second (or thereabouts).  In an aircraft, it's possible to approach and exceed the speed of sound, but in order to do so, the aircraft has to push through the air particles as if they were a crowd.  At walking and cycling speeds, the air particles can easily move aside as you push through them, but at speeds close to the speed of sound, they particles are unable to get out of the way of an aircraft.  The aircraft has to shove the particles aside - this becomes very difficult at speeds close to the speed of sound - and break through the sound barrier.  


The air particles start to bunch up in front of the nose of the aircraft until eventually (if it continues to accelerate) they are pushed aside in a huge compression wave.  All these particles pushed together in one go produce a loud noise - a sonic boom - as the aircraft exceeds the speed of sound and goes supersonic.  

 This sonic boom continues to travel along the ground and will be heard along the line of the aircraft's flight path - it isn't produced just once and then stops.  Mr Science tried to explain all this to Isaac, but Isaac was extremely pleased with having discovered gravity, and wasn't in the mood to discuss ways of beating it in huge flying machines, let alone ones that could travel faster than sound.  "Maybe some other time," he explained to his friend, "When I've finished with the apples."

Friday, 6 May 2011

Web Analytics: Reporting, Analysing, Testing and Forecasting


Reporting, Forecasting, Testing and Analysing


As a website analyst, my working role means that I will take a large amount of online data, sift it, understand it, sift it again and search for the underlying patterns, changes, trends and reasons for those changes.  It's a bit like panning for gold.  In the same way as there's a small amount of gold in plenty of river, there's plenty of data to look at, it's just a case of finding what's relevant, useful and important, and then telling people about it.  Waving it under people's noses; e-mailing it round; printing it out and so on – that’s reporting.

However, if all I do with the data I have is report it, then all I'm probably doing is something similar to reporting the weather for yesterday.  I can make many, many different measurements about the weather for yesterday, using various instruments, and then report the results of my measurements.  I can report the maximum temperature; the minimum temperature; the amount of cloud coverage in the sky; the rainfall; the wind speed and direction and the sunrise and sunset times.  But, will any of this help me to answer the question, "What will the weather be like tomorrow?" or is it just data?  Perhaps I'll look at the weather the day before, and the day before that.  Are there trends in any of the data?  Is the temperature rising?  Is the cloud cover decreasing?  In this way, I might be able to spot trends or patterns in the data that would lead me to conclude that yes, tomorrow is likely to be warmer and clearer than yesterday.  Already my reporting is moving towards something more useful, namely forecasting.

The key difference between the weather and online data, hopefully, is that when we come to analyse business data (marketing data or web data), I'm in a position to change the inputs of today’s data.  I can't do much today with my measurements to influence tomorrow's weather, but online I can change my website’s content, text, layout or whatever, and hopefully make some changes to my online performance.  No amount of measuring or reporting is going to change anything – not the weather, not sales performance.  Only changes to the site will lead to changes to the results.  Then, I can not only forecast tomorrow's online performance, but also make changes to try to improve it.

No change means that there's no way to determine what works and what doesn't.  I've been asked to try and determine, "What does good look like?" but unless I make some guesses at what good might be, and test them out on the website, I'll never know.  What I should be able to do, though, is forecast what future performance will look like - this is the advantage of having a website that doesn't change much.  Providing most of the external factors (for example traffic sources, marketing spend, product pricing) stay the same, I should be able to forecast what performance will be like next week.  Unfortunately, the external factors rarely stay the same, which will make forecasting tricky - but it'll be easier than forecasting performance for a changing website!

Consider the following situation:  here's my online promotion, and I've simplified it (I've removed the text, and really simplified it) and I've reduced it to a colour and a shape.  So I launch my campaign with Red Triangle, and measurements show that it is worth 500 points per day (I'm not discussing whether that's clicks, sales, quotes, telephone calls or what - it's a success metric and I've scored it 500 points per day).



       500 points per day



If I make no changes to the promotion, then I'll keep using Red Triangle, and theoretically it'll keep scoring 500 points each day.  However, I might change it to something else, for example, I might test Green Circle





300 points per day





Now, Green Circle scores 300 points per day, over a week.  Is that good?  Well, Red Triangle scored 500 points per day, so you might think it'd be worth changing it back.  There's a barrier here, in that if I do change it back to Red Triangle, I have to admit that I made a mistake, and that my ideas weren't as good as I thought they were.  Perhaps I'll decide that I can't face going back to Red Triangle, and I'll try Blue Square instead.
 
 


 200 points per day


But what if Blue Square scores only 200 points each day?  Do I keep running it until I'm sure it's not as good, or do I carry out a test of statistical significance?  Perhaps it'll recover?  One thing is for sure; I know what good looks like (it's a Red Triangle at the moment) but I'll have to admit that my two subsequent versions weren't as good; this is a real mental shift - after all, doesn't optimising something mean making it better?  No, it's not scientific and I should probably start testing Red Circles and Green Triangles, but based on the results I've actually obtained, Red Triangle is the best. 

Maybe I shouldn't have done any testing at all.  After all, Green Circle would cost me 200 points per day, and Blue Square costs me 300 points per day.  And I've had to spend time developing the creative and the text - twice.

Now, I firmly believe that testing is valuable in and of itself.  I’m a scientist, with a strong scientific background, and I know how important testing has been, and will continue to be, to the development of science.  However, one of the major benefits of online marketing and sales is that it's comparatively easy to swap and change - to carry out tests and to learn quickly.  It’s not like changing hundreds of advertising posters at bus stops up and down the country – it’s simply a case of publishing new content on the site.  Even sequential tests (instead of A/B tests) like my example above with the coloured shapes, will provide learning.  What's imperative, though, is that the learning is carried forwards.  Having discovered that Red Triangle is the best of the three shapes tried so far, I would not start the next campaign with a variation of Blue SquareLearning must be remembered, not forgotten.

Having carried out tests like this, it becomes possible to analyse the results.  I’ve done the measuring and reporting, and it looks like this:  Red Triangle = 500 pts/day, Green Circle = 300 pts/day, Blue Square = 200 pts/day.

Analysing the data is the next step.  In this case, there genuinely isn’t much data to analyse, so I would recommend more testing.  I would certainly recommend against Green Circle and Blue Square, and would propose testing Yellow Triangle instead, to see if it’s possible to improve on Red Triangle’s performance.  It all sounds so easy, and I know it isn’t, especially when there’s a development cycle to build Yellow Triangle, when Green Circle is already on the shelf, and Blue Square is already up and running.  However, that’s my role – to review and analyse the data and recommend action.  There are occasions when there are other practical reasons for not following the data, and flexibility is key here.

In fact, for me, I’m always looking at what to do on the website next – the nugget of gold which is often a single sentence that says, “This worked better than that, therefore I recommend this…” or “I recommend doing this, because it provided an uplift of 100 points per day".  That’s always the aim, and the challenge, when I’m analysing data.  Otherwise, why analyse?  My role isn’t to report yesterday’s weather.  At the very least, I’m looking to provide a forecast for tomorrow’s weather, and ideally, I’d be able to recommend if an umbrella will be needed tomorrow afternoon, or sun tan lotion.  Beyond that, I’d also like to be able to suggest where to seed the clouds to make it rain, too!





Tuesday, 3 May 2011

Web Analytics: Pages with Zero Traffic

HOW TO TRACK PAGES THAT GET NO TRAFFIC

In this post, I'm wandering from my usual leisure-time subjects to one that's come up at work, and on some web analytics forums:  how can you tell which pages on a website aren't getting any traffic?

It's an interesting question - how can you tell if a page has zero page views - i.e. no traffic.  We're always interested in the pages that generate the most traffic on our sites; the ones that are our superstars, getting the most visitors and attracting the most attention.  However, the flip side of this is that there may be some pages on our sites that have no traffic at all, and are just taking up space, maintenance time and so on, for no benefit at all.

The issue is that all our analytics tools work when our pages are viewed - when visitors load up our pages, point to our links and visit our site, so identifying the zero-traffic pages is not an easy task, and can't be done directly.  Instead, it must be done by a logical process, and my suggestions would be this.  Firstly, identify any suspect pages, which you can tell by process of elimination - run a report that shows all the pages that have had visits, and then deduce which ones haven't.  Or, alternatively, hit all (and that really means ALL - the better your spidering now, the better your results later) the pages on the site during a visit - go through your site and make sure that you visit every page at least once.  This depends on the size of your site - and although I haven't checked, it might be possible to obtain a manual site spidering tool that will go through your site, firing off the javascript tags on each page.  

Once on each page is sufficient, to fire the tag.  If you're doing this manually, make sure you're not using a PC that has its IP address screened out by any filters you may have set up.

Having done this, go on to run a page report for all pages, for the date that covers your spidering session.  Then use the calendar to compare it against any other time frame - in particular, the time frame that you are actually interested in looking for zero-traffic pages.  Sort the pages by the number of page views they got during the time frame of interest, in ascending order.  By doing this, you should see that all the pages that received visits on the test date, but haven't had any during the time frame of interest, come to the top of
the list.  Note from the quick mock-up below how the pages which had the most traffic in the first time frame come to the top of the list.  By reversing the two time frames, it'd be possible to bring the one-day traffic to the top, and compare with the one-month time frame.






It's not pretty, but it should work, and has the advantage that you only have to visit all the pages once (and make a note of the date that you did your visit, for reference, so that you can run further tests in future, as necessary.

Please let me know if this works for you; I haven't tried it (!) but based on my experience it should work successfully.

Other articles I've written on Website Analytics that you may find relevant:

Web Analytics - Gathering Requirements from Stakeholders

Friday, 29 April 2011

Review of Transformers 2: Revenge of the Fallen


As the trailer for the new Transformers film has been launched today, it seems like a good time to look again at the previous film, Revenge of the Fallen.  After its release, a number of people asked me what I thought of it, and I wasn't really able to answer such people at length and explain exactly what my opinion is, or to say whether or not I really enjoyed watching it.

So, here goes - my first written film review. And it will be detailed, and will contain spoilers. I should explain that I am a very big fan of Transformers, have been since I was about 8 years old, and thoroughly enjoyed the first Transformers movie, in 2007 (and the one in 1985). I can recall when Sideswipe and Ironhide were red, while Jazz and Ratchet were white.

When I settled down to watch the film, I noticed all the credits at the start: Dreamworks this, and Steven Spielberg that, and Michael Bay etc etc, and Hasbro. "Oh yeah," I thought to myself, "The toys - it all started with the toys." And thought nothing more of it at the time. It has crossed my mind several times since.

The film starts with the Autobots tracking down Decepticon activity all over the globe, having formed an alliance with the humans. I had to learn in the first movie that human weapons are effective against Transformers - they certainly never used to be, but okay, we'll accept that they are now. Ironhide leads a team to track down some nameless Decepticon. Now, excuse me for asking, but why don't the Autobots speak when they're in vehicle mode? Or do anything sensible? We do get the full length, ten-second-long Ironhide transformation - we know we'll never see a transformation take that long again - and Ironhide finally starts speaking. (Compare this with the scene in the first movie, just after Starscream's airstrike on the city has taken out Bumblebee's legs... Sam has to tell Jazz, who's still in vehicle mode, to back off and reverse. I'll repeat my earlier question - why don't the Autobots do anything sensible in vehicle mode?).

And yes, it is some nameless Decepticon.  Sadly, this is something that I had to get used to, as it cropped up repeatedly.  I guess here is as good a place as any to cover the new characters in the film. There are loads. In fact, to be quite honest, it's the single greatest issue I have with this film. I loved the explosions, I loved the hardware and the storyline, but the number of new characters was overwhelming. On both sides, but especially the Decepticons. The Autobots - we see them in their hangar, an array of shiny sports cars and motorbikes, a couple of Japanese minicars and an ice cream van. No, I know very few of the names of these characters, and very few of them got personalities - just accents. The purple ice cream van rates as moderately annoying. The two Japanese minicars - one of them was called Skids, which was really disappointing considering the intelligence of the original character - were stupid. I think a professional film reviewer likened them to Jar Jar Binks, which is quite accurate - right down to the racial stereotyping. One Autobot I did pick out was Sideswipe, who was silver, instead of red. Now, he has no feet, just wheels. Nor does he have hands or forearms - just large spikes on his elbows. I was thoroughly unimpressed by this - it strikes me as lazy CGI and I was not happy. But anyways, it was only a fluke that I found out that this particular character was Sideswipe - he could have been anonymous if I'd not been listening closely.

Having mentioned the large number of Autobots, this is nothing compared to the Decepticons. At one point towards the end of the film, it almost literally starts raining Decepticons. A huge army of Decepticons arrives in the desert and start attacking our heroes, and as I watched this, I started to wonder why the existing Decepticons - those already introduced in the story, or even some already on Earth - didn't show up. I'm still not sure, but I think the answer is that Hasbro are named in the credits, and more figures (I can't call them characters - I don't think they have a line of dialogue between them) means more toys. Now, these fresh warriors all look pretty much the same, since they haven't adopted an earth-based vehicle mode. In other words - they don't transform. This is, above and beyond the number of new characters; the stupid accents; the nameless characters, the single most irritating part of this film. Transformers that don't transform? No. Big mistake. Wrong. And wrong from the perspective of the toy makers too. Surely Hasbro should keep in mind that the original series of toys were successful because they were robots and vehicles. I should mention at this point "The Fallen" who also doesn't transform... he could have been any sort of intergalactic weapon - tank, spacecraft - but no.

And if you want further evidence that this is a toy-maker's film, consider Starscream, who is one of the few Decepticons to make it from the first film. Ordinarily, Starscream version 1.0 would be sufficient for most kids, but no. To quote one of the soldiers (I can't recall which), describing Starscream in aircraft mode - "It's got some crazy alien graffiti all over it." That's right, kids, Starscream from the first film is out-of-date, time to go splash out on Starscream version 2.0. And if you thought the original Optimus would suffice... sadly not, as, towards the end, we get Japanese-armoured-style ultra super-powered Optimus with the armour of that poor unfortunate defecting Decepticon, Jetfire. I bet the armour in the toy version either (a) sticks on and doesn't come off, leading to a non-transforming Transformer, or (b) doesn't stay on when it's put on. I'm not sure which is worse.

That's covered most of my ranting about the robots, now let's turn to the humans.

Now - Megan Fox. Oh good grief... I'd heard that she was in the film almost exclusively as eye candy, but the first few scenes with her in, posing on the motorbike, were just too much. Perhaps I'm the wrong side of, say, 14 years old, but it was just a bit too obvious that she was just in the film for the teenage boys.

Sam's parents, who thoroughly annoyed me during the first film, were back on form. Why, why, why do the film makers insist on giving Sam's parents lines, or even screen time? They are the most unnecessary characters in a film that I've ever come across. The "Sam's special time" scene from the first film could have been cut in its entirety and the film would have been greatly improved. In this film, it was the scene where Sam's mum buys a 'herbal rememdy' from a student that could have been left on the cutting room floor. Many people have commented that this film was over-long... I think I've just solved the problem.  I'm with Ironhide, who in the first film commented, "Can't we terminate the humans?  The parents are very irritating."

Speaking of Sam's parents - shortly after (before?) the first Megan Fox scene, we come to the scene with the kitchen critters and Bumblebee blasting the house down. Yes, I enjoyed this one - and in particular the extremely cool kitchen critters (no lines of dialogue, no names) but why, oh why has Bumblebee been reduced to an overgrown guard dog in the garden, with his own kennel? And, okay, perhaps it's a plot contrivance that he's lost his voice, but when did he become an over-exuberant teenager? He used to be a no-messing warrior who protected Sam from Barricade (the police car) and an all-round fighter. A highlight of the film is the scene where Sam has to tell Bumblebee to grow up and remember who he really is.

Now? He can't wait to go to college with Sam? Okay, I'll let it go, but I did think it was particularly stupid that he lived in the garage like a dog. And yes, I thought some of the kitchen critters were cool, but it didn't dawn on me until a little later that they were obvious merchandise, and would probably be in my local Toys R Us store by the end of the movie.

One of the film's biggest redeeming features for me has to be the Sector Seven agent, Simmons. He is brilliant. I loved his archive of antiquated Transformers, Frenzy's head in his office, I liked his panicky but genuine character, and the way he ordered the naval barrage was inspired. I like this character, and hope to see him in the third film.

Finally - Alice, the human who turned out to be a Decepticon. She doesn't Transform... and Decepticons never, ever, took human form. Mind control, yes. Human form? No. "Decepticon Pretender".  Possibly.

Overall, I actually liked this movie. I thought the effects were amazing; the music was outstanding (most of it taken from the first movie, and I was nodding along at various points); the story was actually well written, if a little cheesy in places... the idea of Sam having the power of the Allspark in his head goes back to a comic-book story where Buster Witwicky (yes, that was his name) was given the Creation Matrix by Optimus for safekeeping. Yes, I thought, on the whole, it was enjoyable, possibly overlong but on the whole kept ticking along at a good pace. Did I want the DVD for Christmas? Yes please. Would I watch it repeatedly until I'd learned the script? Possibly.

I think I could some up my views on this film by considering if I would I watch it all the way through; the answer is probably. Although I can quite easily see myself skipping the boring bits (with the humans), there's enough pace to make it watchable, and I'll also like to find out all those Autobots' names!  Overall, I'd recommend watching the DVD with the subtitles turned on - that way, you'll get all the dialogue, character names and all the parts of the plot.

So, I'm looking forward to the new film, and I'll be posting a review here when I've seen it!

Thursday, 28 April 2011

Isaac Newton's Random Walk

Poor Isaac Newton.  He was having a pleasant afternoon nap, but was disturbed by a gravity-driven apple.  His attempts at destroying the apple that fell on his head have almost led to the death of a poor innocent bystander, and he's had to explain his actions to the local constabulary.  After a long and gruelling day, he's visited the local pub, and drunk slightly too much cider (stupid apples).  Now, having stepped out of the pub, he has to get to his house at the end of the street.  Alternatively, he could go to his aunt's house, at the other end of the street.

Conveniently, the pub is located at the middle of the street, which is 20 metres long.  His house is at one end, his aunt's house is at the other end.  Both possible destinations are 10 metres away.  In his slightly tipsy state of mind, the best that Mr Newton can manage is a stride of 1 metre; however, he's so unbalanced (he's also developing an apple-shaped bruise on his head) that it's not guaranteed that he'll keep going in the same direction.  In fact, it's 50/50 each time on which way he'll go.

How many steps will it take him to get home?  And at the rate of one step every 10 seconds, how much time will it take?



There are two ways of solving this one: the pure maths way, or the spreadsheet way (actually do some experiments on a spreadsheet).  Let's do the spreadsheet way first.



Each step is 1 metre long, but can be +1 metre or -1 metre, so we need to randomly produce a +1 or a -1 and add it to the previous distance walked.  This is easy enough in a spreadsheet - with a column of random +1 and -1 and a column which sums the previous column.  The function I've used for the random numbers is:

=(2*ROUNDUP(RANDBETWEEN(0,1),0))-1

I then look down the 'total distance covered' column until I find the first +10 or -10.

I've run the test 20 times, and have obtained the following results for the number of steps it takes Mr Newton:

22, 20, 30, 20, 82, 94, 142, 106, 52, 51, 76, 92, 44, 74, 142, 50, 25, 17, 82 and 16.

What is there to say on this?  Isaac only has to travel a net distance of 10 metres in either direction, and yet in some cases it's taken him over 100 steps to cover the distance (he's not just drunk, he's very drunk).  At his best, he's managed it in 16 steps, with most of them in the same direction!

The results here show how probability (chance) is a key part of this question.  We've not given Isaac any sense of direction at all, and he's at the mercy of probability.  As a result, mathematically, all we can aim for is an approximate, or an average distance that Newton can travel.  Unfortunately for him, the mathematical average of his wanderings is going to be close to zero - for every step he takes to the left, he has an equal chance of taking a step to the right.

Doing it the pure maths way involves probability.  There's a 50% chance that Newton will go to the left (let's call this a step of -1) and a 50% chance he'll go to the right (this is a step of +1).  Let's start him at zero, and assume that he has to reach either +10 (his home) or -10 (his aunt's home).

After his first step, he has a 50% chance of moving even closer to his target, and a 50% chance of returning to his starting position.  So the probability of him making two consecutive steps towards either target is (0.5 x 0.5) x 2 since he has two targets to aim for (one at each end of the street), which is 0.5 - in fact, after two steps, Isaac has either moved two steps towards one target (+1, +1 = +2 or -1, -1 = -2) or moved back to his start position (+1, -1  =0 or -1, +1 = 0).


However, the maths becomes considerably more complex after three steps, and more complicated still if we need Isaac to achieve ten steps in one direction or the other.  I won't do the maths here, but after a large number of steps, it becomes clear that the most probable location after a large number of steps is close to the start point, as mentioned above.  On average, the number of steps in one direction will be balanced by an equal or similar number of steps in the other.  This is known among mathematicians as the random walk problem, and Wikipedia has plenty to say on it (no surprises there).

The question becomes not "When will Mr Newton reach his destination?" but "How likely is he to have reached his destination after 10 or 20 or 30 or 40... steps?" and that's far more complicated than I'd like to cover here - it's why I prefer science to maths!

Other articles I've written with spreadsheet solutions include:


What is smog?

Over the last few days, we've seen in the news how some of the cities in Britain (well, we've had pictures of London, and on the television London = Britain) have been covered in smog.  The word "smog" comes from a combination of smoke and fog, but what causes it and where does it come from?

Smog usually comes from sources like car exhaust fumes, and fumes which have reacted in sunlight to produce other pollutants (called 'secondary pollutants').  Worse still, the primary pollutants (directly from car exhaust fumes or from burning coal) can react with the secondary pollutants to produce a real mix of gases, called photochemical smog.  "Photochemical" reactions are ones that use light to make them go - in the case of smog, it's sunlight that drives the reactions.

Photochemical smog is produced by the chemical reaction of sunlight, nitrogen oxides (NOx) and other organic compounds in the atmosphere.  Smog also contains airborne particles (called particulate matter - bits of dust, ash and smoke) and ground-level ozone.  Ozone is best kept in the upper atmosphere; at ground level it's toxic (despite what you might have heard about invigorating ozone at the seaside - that's just misinformed nonsense).

Nitrogen oxides are formed when nitrogen and oxygen in the air react together under high temperature such as in the engines of cars and trucks, coal power plants, and industrial manufacturing factories.  Nitrogen and oxygen make up about 98% of the atmosphere between them, and when these are drawn into a hot internal combustion engine, they react together to product nitrogen oxide (NO) and nitrogen dioxide (NO2).  Both NO and NO2 are harmful to human health.

So, smog contains ozone (toxic) and NOx (harmful), along with dust, smoke and so on.  It builds up when the air is still - very little wind - and can occur at times when there's high air pressure.  London has suffered serious instances of smog in the past, in particular in 1952.  Work has been done to reduce smog in Britain and in Europe, in particular reducing the sulphur content of fuels - burning fuels that contain sulphur leads to the formation of sulphur oxides which contribute to smog - and also, incidentally, to acid rain.  This is why smog is generally rare in London... that, and the fact that we rarely get the still, sunny weather that's needed to produce it!