<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/random-walking/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.decisionsciencenews.com/2017/12/11/random-walking/"> R – Decision Science News</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>BAGEL SHOP IDEA</p>
<p><a rel="nofollow" href="https://i0.wp.com/www.decisionsciencenews.com/wp-content/uploads/2017/12/hex.jpg" target="_blank"><img sizes="(max-width: 485px) 100vw, 485px" src="https://i0.wp.com/www.decisionsciencenews.com/wp-content/uploads/2017/12/hex.jpg?w=450" alt="" class="wp-image-6469" data-recalc-dims="1"></a></p>
<p>I was sitting in a bagel shop on Saturday with my 9 year old daughter. We had brought along hexagonal graph paper and a six sided die. We decided that we would choose a hexagon in the middle of the page and then roll the die to determine a direction:</p>
<p>1 up (North)<br>
2 diagonal to the upper right (Northeast)<br>
3 diagonal to the lower right (Southeast)<br>
4 down (South)<br>
5 diagonal to the lower left (Southwest)<br>
6 diagonal to the upper left (Northwest)</p>
<p>Our first roll was a six so we drew a line to the hexagon northwest of where we started. That was the first “step.”</p>
<p>After a few rolls we found ourselves coming back along a path we had gone down before. We decided to draw a second line close to the first in those cases.</p>
<p>We did this about 50 times. The results are pictured above, along with kid hands for scale.</p>
<p>I sent the picture to my friend and serial co-author <a rel="nofollow" href="http://jakehofman.com/" target="_blank">Jake Hofman</a> because he likes a good kid’s science project and has a mental association for everything in applied math. He wrote “time for some Brownian motion?” and sent a <a rel="nofollow" href="http://jakehofman.com/talks/dalton_hunter_20071031.pdf" target="_blank">talk he’d given a decade ago at a high school</a> which taught me all kind of stuff I didn’t realize connecting random walks to Brownian motion, Einstein, the existence of atoms and binomial pricing trees in finance. (I was especially embarrassed not to have mentally connected random walks to binomial pricing because I had a slide on that in my job talk years ago and because it is the method we used in <a rel="nofollow" href="https://web.stanford.edu/~wfsharpe/art/qpaper/qpaper.pdf" target="_blank">an early distribution builder paper</a>.)</p>
<p>Back at home Jake did some simulations on random walks in one dimension (in which you just go forward or backward with equal probability) and sent them to me. Next, I did the same with hexagonal random walks (code at the end of this post). Here’s an image of one random walk on a hexagonal field.</p>
<p><a rel="nofollow" href="https://i2.wp.com/www.decisionsciencenews.com/wp-content/uploads/2017/12/lastwalk-0000.png" target="_blank"><img sizes="(max-width: 485px) 100vw, 485px" src="https://i2.wp.com/www.decisionsciencenews.com/wp-content/uploads/2017/12/lastwalk-0000.png?w=450" alt="" class="wp-image-6465" data-recalc-dims="1"></a></p>
<p>I simulated 5000 random walks of 250 steps, starting at the point 0,0. The average X and Y position is 0 at each step, as shown here.</p>
<p><a rel="nofollow" href="https://i0.wp.com/www.decisionsciencenews.com/wp-content/uploads/2017/12/ave_position-0001.png" target="_blank"><img sizes="(max-width: 485px) 100vw, 485px" src="https://i0.wp.com/www.decisionsciencenews.com/wp-content/uploads/2017/12/ave_position-0001.png?w=450" alt="" class="wp-image-6468" data-recalc-dims="1"></a></p>
<p>This might seem strange at first. But think about many walks of just one step. The number of one-step journeys in which your X position is increased a certain amount will be matched, in expectation, by an equal number of one-step journeys in which your X position is decreased by the same amount. Your average X position is thus 0 at the first step. Same is true for Y. The logic scales when you take two or more steps and that’s why we see the flat lines we do.</p>
<p>If you think about this wrongheadedly you’d think you weren’t getting anywhere. But of course you are. Let’s look at your average distance from the starting point at each step (below).</p>
<p><a rel="nofollow" href="https://i0.wp.com/www.decisionsciencenews.com/wp-content/uploads/2017/12/dist_from_origin-0003.png" target="_blank"><img sizes="(max-width: 485px) 100vw, 485px" src="https://i0.wp.com/www.decisionsciencenews.com/wp-content/uploads/2017/12/dist_from_origin-0003.png?w=450" alt="" class="wp-image-6467" data-recalc-dims="1"></a></p>
<p>The longer you walk, the more distant from the starting point you tend to be. Because distances are positive, the average of those distances is positive. We say you “tend to” move away from the origin at each step, because that is what happens on average over many trips. At any given step on any given trip, you could move towards or away from the starting point with equal probability. This is deep stuff.</p>
<p>Speaking of deep stuff, you might notice that the relationship is pretty. Let’s zoom in.</p>
<p><a rel="nofollow" href="https://i2.wp.com/www.decisionsciencenews.com/wp-content/uploads/2017/12/zoomed_dist_from_origin-0002.png" target="_blank"><img sizes="(max-width: 485px) 100vw, 485px" src="https://i2.wp.com/www.decisionsciencenews.com/wp-content/uploads/2017/12/zoomed_dist_from_origin-0002.png?w=450" alt="" class="wp-image-6466" data-recalc-dims="1"></a></p>
<p>The dashed line is the square root of the number of steps. It’s interesting to note that this square root relationship happens in a one-dimensional random walk as well. There’s a <a rel="nofollow" href="http://www.science.oregonstate.edu/~landaur/INSTANCES/WebModules/5_RandomWalk/RandomWalkFiles/Pdfs/RandomWalk.pdf" target="_blank">good explanation of it in this document</a>. As Jake put it, it’s as if the average walk is covered by a circular plate whose area grows linearly with the number of steps. (Why linearly? Because area of a circle is proportional to its radius squared. Since the radius grows as the square root of the number of steps, the radius squared is linear in the number of steps)</p>
<p>(*) As a sidenote, I was at first seeing something that grew more slowly than the square root and couldn’t figure out what the relationship was. It turns out that the square root relationship holds for the root mean squared distance (the mean of the squared distances) and I had been looking at the mean Euclidean distance. It’s a useful reminder that the term “average” has quite a few definitions. “Average” is a useful term for getting the gist across, but can lead to some confusion.</p>
<p>Speaking of gists, here’s the <a rel="nofollow" href="https://www.r-project.org/" target="_blank">R</a> code. Thanks to <a rel="nofollow" href="https://twitter.com/hadleywickham" target="_blank">@hadleywickham</a> for creating the <a rel="nofollow" href="https://www.tidyverse.org/" target="_blank">tidyverse</a> and making everything awesome.</p>
<p>RCODE<br>
</p>
<p>The post <a rel="nofollow" href="http://www.decisionsciencenews.com/2017/12/11/random-walking/" target="_blank">Random walking</a> appeared first on <a rel="nofollow" href="http://www.decisionsciencenews.com/" target="_blank">Decision Science News</a>.</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://www.decisionsciencenews.com/2017/12/11/random-walking/"> R – Decision Science News</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/miJgUjBrqTc" height="1"></a></div>