# Binomial Rabbits

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)

## WHAT IS IT?

This model simulates a binomial probability distribution or (in the limit) normal distribution. It works by analogizing height variations to rabbit hops.

This model was created by a student in an effort to make sense of normal distributions. In particular, he sought to understand why height is distributed normally in human populations. For a detailed account of this case, see: Wilensky, U. (1997). What is Normal Anyway? Therapy for Epistemological Anxiety. Educational Studies in Mathematics. Volume 33, No. 2. pp. 171-202. http://ccl.northwestern.edu/papers/normal/.

The procedures for this model have been kept largely intact from the original code written by the student. With advances in the language, this code is no longer at all an optimal way of writing this model. We have kept the original code for research purposes --- please do not use it as an example of good NetLogo coding.

## HOW IT WORKS

A number of rabbits are placed at the center of the bottom of the world. A move pattern determines the way a rabbit moves. Each rabbit can choose to hop right or left a certain hop-size. The likelihood of a rabbit following each move pattern is given in terms of ratios. Each rabbit may have up to five different move patterns.

## HOW TO USE IT

### Setup

Method one (sliders setup): Press SETUP button. This creates the number of rabbits from the NUMBER slider and up to three hops and associated probability ratios from the six sliders above the NUMBER slider. Each time a rabbit hops, it chooses one of the three moves -- hop-1, hop-2, or hop-3 -- with a likelihood in the ratio of ratio-1, ratio-2, and ratio-3 to each other. For example, if ratio-1 = 2, ratio-2 = 4, and ratio-3 = 6, the rabbit has a 2-in-12 chance of making the hop-1 move, a 4-in-12 chance of making the hop-2 move, and a 6-in-12 chance of making the hop-3 move.

Method two (manual setup): In the Command Center, type "setup [number] [list of hops [list of probability ratios]" to initialize the rabbits (e.g. "setup 4000 [1 -1] [1 2]" will set up 4000 rabbits hopping either one unit to the right(1) or one unit to the left (-1) with a chance of hopping to the left being twice as much as that to the right.) Up to five steps and corresponding probability ratios can be used.

### Running

The GO-ONE-HOP button makes each rabbit hop once.

The GO button tells the rabbits to hop the number of times set by the HOPS slider. For example, if HOPS is set to 10, the GO button makes each rabbit hop 10 times. To stop the rabbits from hopping once they've started, press the GO button again.

There are two scale monitors and one scale slider in the Interface Window. X-SCALING is used to magnify the width of the world to facilitate more hops. It is manually set by users with the X-SCALING slider. The setting can be changed as the model runs. Y-SCALE is used to regulate the vertical scale -- to ensure that the highest yellow distribution bar is always 80% of the height of the world. This is done at each hop.

The figure inside the "y-scale" monitor is the number of rabbits a yellow line the height of the world represents. The figure inside the "x-scale" monitor is the number of steps represented by a full view. (The rabbits wrap around the left and right edges, so if they get to the edge, you should increase the x-scale.)

The following formulae can be used to evaluate the actual numbers of rabbits or steps hopped:

Actual Number of Rabbits for a Yellow Line = height of line * ( y-scale / 100 )

Cumulative Number of Steps Hopped so far = X-coordinate of a line * ( x-scale / 100 )

To find out exactly how many rabbits are represented by a line, control-click (Mac) or right-click (other) anywhere on the line and choose inspect patch from the menu that appears. The inspector will have a variable "turtle-bottom" which will tell you how many turtles (rabbits) are at the bottom of the line.)

## THINGS TO NOTICE

The purple average line shows where an average rabbit would be. Observe the movement of this line -- both its position and velocity -- and try to relate these to the settings.

Play with the NUMBER slider to see if what you predict is what you see when the number of rabbits is small. For what numbers of rabbits are your predictions the most accurate?

## THINGS TO TRY

Try different values for list of steps. What happens to the distribution?

Try different values for probability ratios. What happens to the distribution?

Is the distribution always symmetric? What would you expect?

## EXTENDING THE MODEL

Create a plot for 'hopping'. First decide what to plot, and then implement the proper NetLogo plot functions.

Rewrite the model so rabbits take list variables. Are there now new capabilities you can give the rabbits?

## NETLOGO FEATURES

The limitation on the number of turtles constrains the limits of the "number" slider. You can make the corresponding change to the `number`

slider --- select the slider by clicking and dragging the mouse button over it. Then click on the edit button and change 'Maximum' to the new number. Having more rabbits to jump can be useful for certain statistical simulations.

You can also change the settings to have a bigger world to fit more hops or show very fine distribution diagrams.

Note that since turtles could not have list variables in earlier versions of the language, the global lists steps and ratios are used to hold the movement patterns and ratios. The turtles access these globals to know how to move. (if we were writing this model now, we would not code it this way as turtles in NetLogo can have list variables). The procedures `define-steps`

and 'define-ratios' use the primitives `first`

and `butfirst`

. Both of these are list operators --- that is, they operate on lists of things. The `first`

of a list is simply its first element. Likewise, the `butfirst`

of a list is a list of all elements except for the first.

## RELATED MODELS

Galton Box, Random Walk Left Right

## CREDITS AND REFERENCES

See: Wilensky, U. (1997). What is Normal Anyway? Therapy for Epistemological Anxiety. Educational Studies in Mathematics. Volume 33, No. 2. pp. 171-202. http://ccl.northwestern.edu/cm/papers/normal/

## HOW TO CITE

If you mention this model in a publication, we ask that you include these citations for the model itself and for the NetLogo software:

- Wilensky, U. (1997). NetLogo Binomial Rabbits model. http://ccl.northwestern.edu/netlogo/models/BinomialRabbits. Center for Connected Learning and Computer-Based Modeling, Northwestern Institute on Complex Systems, Northwestern University, Evanston, IL.
- Wilensky, U. (1999). NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern Institute on Complex Systems, Northwestern University, Evanston, IL.

## COPYRIGHT AND LICENSE

Copyright 1997 Uri Wilensky.

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

Commercial licenses are also available. To inquire about commercial licenses, please contact Uri Wilensky at uri@northwestern.edu.

This model was created as part of the project: CONNECTED MATHEMATICS: MAKING SENSE OF COMPLEX PHENOMENA THROUGH BUILDING OBJECT-BASED PARALLEL MODELS (OBPML). The project gratefully acknowledges the support of the National Science Foundation (Applications of Advanced Technologies Program) -- grant numbers RED #9552950 and REC #9632612.

This model was developed at the MIT Media Lab using CM StarLogo. See Wilensky, U. (1993). Thesis - Connected Mathematics: Building Concrete Relationships with Mathematical Knowledge. Adapted to StarLogoT, 1997, as part of the Connected Mathematics Project. Adapted to NetLogo, 2001, as part of the Participatory Simulations Project.

This model was converted to NetLogo as part of the projects: PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN CLASSROOMS and/or INTEGRATED SIMULATION AND MODELING ENVIRONMENT. The project gratefully acknowledges the support of the National Science Foundation (REPP & ROLE programs) -- grant numbers REC #9814682 and REC-0126227. Converted from StarLogoT to NetLogo, 2001.

## Comments and Questions

;; The procedures for this model have been kept largely intact from ;; the original code written by the student. With advances in the ;; language, this code is no longer at all an optimal way of writing ;; this model. We have kept the original code for research purposes -- ;; please do not use it as an example of good NetLogo coding. turtles-own [ random-no total-ratio step x-zoom x-ave ] patches-own [ turtle-quant turtle-bottom ] globals [ x-ave-glob x-scale kx y-scale ky y-scale-distr ky-distr step1 step2 step3 step4 step5 steps ratio1 ratio2 ratio3 ratio4 ratio5 ratios total-ratios ] ;; x-zoom: intermediate variable for zooming ;; x-ave: intermediate variable for average line ;; x-ave-glob: intermediate variable for average line ;; kx: x axis scaling factor = 2 ^ x_scale ;; ky: normalization factor for the original line ;; ky-distr: normalization factor for the distribution line ;; step1 to step5: step sizes ;; ratio1 to ratio5: probability ratio corresponding to steps ;; turtle-quant: number of turtles on each patch ;; turtle-bottom: number of turtles on each patch of the bottom line to setup clear-all set steps sentence hop-1 list hop-2 hop-3 set ratios sentence ratio-1 list ratio-2 ratio-3 crt number [ set x-zoom 0 set x-ave 0 setxy 0 0 set color red set shape "rabbit" set heading 90 ] set kx x-scaling ;; below is the y-scale factor to ensure that the height of the original line and ;; average line are always about the same height, 90% of the world-height. set ky (number / (world-height - 1)) / 0.9 set y-scale-distr (world-width - 1) * ky set y-scale 0 set x-scale (world-width - 1) * kx set ky-distr 0 ask patches [ plot-green ] define-steps define-ratios reset-ticks end to go-one-hop hopping plot-violet plot-yellow tick end to go if hops = ticks [ stop ] go-one-hop end to hopping set kx x-scaling set x-scale (world-width - 1) * kx ask turtles [ ht set-step set x-zoom (x-zoom + step) set x-ave (x-zoom / ky) setxy (x-zoom / kx) ycor st ] end to set-step ;; turtle procedure set total-ratio (ratio1 + ratio2 + ratio3 + ratio4 + ratio5) set random-no (random-float total-ratio) if random-no <= ratio1 [ set step step1 ] if (random-no > ratio1) and (random-no <= ratio1 + ratio2) [ set step step2 ] if (random-no > ratio1 + ratio2) and (random-no <= ratio1 + ratio2 + ratio3) [ set step step3 ] if (random-no > ratio1 + ratio2 + ratio3) and (random-no <= ratio1 + ratio2 + ratio3 + ratio4) [ set step step4 ] if random-no > ratio1 + ratio2 + ratio3 + ratio4 [ set step step5 ] end to plot-yellow ask patches [ unplot-yellow set turtle-quant (count turtles-here) ] let most-turtles max [ turtle-quant ] of patches ask patches [ set ky-distr (most-turtles / ky / int (.80 * world-height)) set y-scale (100 * ky-distr * ky) set turtle-bottom [turtle-quant] of patch pxcor 0 if pycor < turtle-bottom / (ky * ky-distr) [ set pcolor yellow ] ] end to plot-violet ask patches [ unplot-violet ] set x-ave-glob (((sum [ x-ave ] of turtles) * ky) / number) ask patches [ if ((pxcor = round (x-ave-glob / kx)) or (pxcor = (round ((x-ave-glob / kx) - world-width))) or (pxcor = (round ((x-ave-glob / kx) - (2 * world-width))))) and (pycor <= (number / ky) ) [ set pcolor violet ] ] end to plot-green ;; patch procedure if (pxcor = 0) and (pycor <= (number / ky)) [ set pcolor green ] end to define-steps if not empty? steps [ set step1 first steps set steps butfirst steps ] if not empty? steps [ set step2 first steps set steps butfirst steps ] if not empty? steps [ set step3 first steps set steps butfirst steps ] if not empty? steps [ set step4 first steps set steps butfirst steps ] if not empty? steps [ set step5 first steps set steps butfirst steps ] end to define-ratios set total-ratios 0 if not empty? ratios [ set ratio1 first ratios set ratios butfirst ratios ] if not empty? ratios [ set ratio2 first ratios set ratios butfirst ratios ] if not empty? ratios [ set ratio3 first ratios set ratios butfirst ratios ] if not empty? ratios [ set ratio4 first ratios set ratios butfirst ratios ] if not empty? ratios [ set ratio5 first ratios set ratios butfirst ratios ] end to unplot-yellow ;; patch procedure if pcolor = yellow [ set pcolor black ] end to unplot-violet ;; patch procedure if pcolor = violet [ set pcolor black ] plot-green end ; Copyright 1997 Uri Wilensky. ; See Info tab for full copyright and license.

There are 10 versions of this model.

## Attached files

File | Type | Description | Last updated | |
---|---|---|---|---|

Binomial Rabbits.png | preview | Preview for 'Binomial Rabbits' | almost 7 years ago, by Uri Wilensky | Download |

This model does not have any ancestors.

This model does not have any descendants.