# Random Basic Advanced

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

## WHAT IS IT?

Random Basic Advanced explores the effect of sample size on the distribution of sample mean.

At each run, a sample of random values is selected and displayed on "messengers," who each carry a brick to the top of a corresponding column in a bar chart. (So a messenger with "5" will carry the brick to the top of the fifth column from the left.) The values are also added into a histogram (below the view). The mean value from each batch of messenger is added to yet another histogram (at the bottom of the interface).

The larger the sample size, the smaller the variance of the distribution. That is, the sample space does not change, but extreme values become more and more rare as the sample size increases. Combinatorial analysis helps understand this relation.

This model is a part of the ProbLab curriculum. The ProbLab curriculum is currently under development at the CCL. For more information about the ProbLab curriculum please refer to http://ccl.northwestern.edu/curriculum/ProbLab/.

## HOW IT WORKS

At every trial (sampling), random values are assigned to as many "messengers" as you choose. The messengers each carry a brick. They go to a column according to their value and lay the brick at the top of that column. The mean value of the batch of messengers is plotted in a histogram.

## HOW TO USE IT

### Buttons

SETUP - prepares the model for running with your sample-space parameter setting.

GO - runs the model with the current settings.

### Sliders

SAMPLE-SIZE --- set the total number of integer values, beginning from 1, that can be randomly assigned to the messengers

### Switches

BUMP-DOWN? --- when set to "on," the columns in the view will all go down by one step to anticipate the columns reaching the top of the space.

### Monitors

BIGGEST-DIFFERENCE --- show the vertical difference between the tallest column and the shortest column. Note that columns can be so short that they are below min-pycor.

STD DEV --- standard deviation of the sample-mean distribution. This is a measure of shape the distribution tends towards. A lower standard deviation implies a narrower distribution.

### Plots

ALL VALUES FROM MESSENGERS --- plots all of the randomly assigned values in the messenger labels.

MEAN VALUES OF BATCHES OF MESSENGERS --- plots the mean of all the randomly-assigned values in the messenger labels.

## THINGS TO NOTICE

Each messenger "carries" a little brick. It swoops down to the highest point in a brick tower. It goes to the brick tower that is as far from the left wall as is the messenger's number. So a messenger with "7" will go to the seventh column from the left.

When the bricks are about to hit the top of the space, all the columns "bump down" to make space for the new bricks. But the monitor "ALL VALUES" keeps a record of all the bricks that have been laid. So, sometimes a column of bricks will be empty, because it is not tall enough to make it into the view, yet its corresponding column in the the plot will still be there.

## THINGS TO TRY

Run the model with NUM-MESSENGERS = 1. Compare the histogram in the plot to the towers in the graphic windows. What do you see? Now setup and run the model with NUM-MESSENGERS = 2. Is the histogram any different from before? Repeat this for values of NUM-MESSENGERS 10, 20, and 30. For a sample size of 1, the raw data (the bricks in the towers) are exactly the same as the histogram. For a sample size of 2, we begin to see a certain shallow bump in the middle of the distribution. For larger sample sizes, this bump becomes more and more acute. For a sample size of 30, the distribution is narrow.

Another comparison is to do with the likelihood of getting a low value, say "1," in different settings of NUM-MESSENGERS. Run the model 100 trial for different values of NUM-MESSENGERS and see if there is a pattern to this comparison.

What is the standard deviation dependent on? For a fixed number of messengers, would a larger sample space change the standard deviation? If so, why? For a fixed sample space, should a change in the number of messengers affect the standard deviation? If so, why? Can you determine a relation between these three values (NUM-MESSENGERS, SAMPLE-SPACE, and STD-DEV)? One way to begin would be to use NetLogo's BehaviorSpace.

Once the model has run for many trials, should the BIGGEST-DIFFERENCE increase or decrease? On the one hand, individual columns have "opportunities" to get very tall, but on the other hand, all columns have the same opportunities. Is this a paradox?

## PEDAGOGICAL NOTE

Why are we getting this pattern? Let's think about the case of NUM-MESSENGERS = 2 to understand the bump in the distribution plot:

The only way to get a value of "1," is if both the messengers have a value of "1," but to get a value of, say, "2," either both messengers have "2," or one has "1" and the other "3" or vice versa. So there are three different ways of getting "2." How about getting a "3?" There are more than three ways of getting "3": [3,3]; [2,4]; [4,2]; [1,5]; [5,1]. So there are five ways of getting "3." You can see that the nearer the value is to the middle (50), there are more and more ways of getting that value as a mean of two values. Because these values are random, over many runs we will get more means that are closer to the middle, so we get the bump.

This way of finding all the different possible compound events is called combinatorial analysis --- determining all the combinations for a given set of variables each with a set of possible values. Once we know all the combinations, we can group them so as to predict the chances of getting any outcome from each group. For instance, if we know that there are triple as many ways for two messengers to form a mean of "2" than to form a mean of "1," then we can predict that we will get a "2" three times as much as we get a "1," if we run the simulation long enough. That is where combinatorial analysis (theoretical probability) meets experimental simulations (empirical probability).

Can we extend this way of thinking in order to understand the difference between the distribution we get for NUM-MESSENGERS = 2 as compared to the distribution we get for NUM-MESSENGERS = 3? For NUM-MESSENGERS = 3, we get an even narrower distribution. Why? Extending our previous way of thinking, we can expect that with three messengers the number of combinations for getting mean values of 1, 2, 3 etc. rises even more sharply than for NUM-MESSENGERS = 2. Let's see: for "1" there is only one combination: [1,1,1], just like for NUM-MESSENGERS = 2. But for "2" there are more than just three as in the previous example. Look: [2,2,2]; [1,2,3]; [1,3,2]; [2,3,1]; [2,1,3]; [3,1,2]; [3,2,1]; [1,1,4]; [1,4,1]; [4,1,1], for a total of ten combinations.

You might notice that the more messengers in a batch (the higher the setting of NUM-MESSENGERS), the less likely it is to get a low mean sample value, say "1." For NUM-MESSENGERS = 10, you would get a "1" only if all the messengers chose "1" randomly at the same time. That happens once every 100^10, which is "1" with 1000 zeros after it. That's pretty rare...

## EXTENDING THE MODEL

In the model, the bricks laid by the messengers are NetLogo "turtles". However, in NetLogo, the more turtles are visible, the longer it takes to update the display. Thus, the closer the display gets to being full of bricks, the slower the model runs. To eliminate this problem, one may want to use colored NetLogo "patches", rather than "turtles", to represent the bricks in the display histogram.

Currently, the brick columns in the display show the absolute height of each column --- not the proportionate height of the columns. This means that once a column is considerably taller than other columns, these other columns may be shown as empty. They are not tall enough to enter the display --- they are "under water." We have chosen this design option, because we think it helps users "get into" the model when they first start working with it. But you might want to change this or add an option that gives you the proportionate height of the columns. For a clue on how to make this work, take a look at the code of the Rugby model.

## NETLOGO FEATURES

The `display`

command is used to make the motion of the messengers animate.

## RELATED MODELS

See the ProbLab model Random Basic. In that model, there is only a single messenger. This model extends Random Basic in that we now have compound events, that is, we look to understand the chances of two or more independent events occurring simultaneously.

## CREDITS AND REFERENCES

This model is a part of the ProbLab curriculum. The ProbLab Curriculum is currently under development at Northwestern's Center for Connected Learning and Computer-Based Modeling. . For more information about the ProbLab Curriculum please refer to http://ccl.northwestern.edu/curriculum/ProbLab/.

## 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:

- Abrahamson, D. and Wilensky, U. (2004). NetLogo Random Basic Advanced model. http://ccl.northwestern.edu/netlogo/models/RandomBasicAdvanced. 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 2004 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 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.

## Comments and Questions

globals [ counter ;; used in setting up the messengers at-top? ;; Boolean that discontinues run when columns reach the top of the space max-y-histogram ;; how high the columns can rise (or how far up the yellow goes) list-of-labels ;; list of all the outcomes list-of-label-means ;; list of the mean values of messengers in each iteration through Go height ;; height, from the bottom of the view, that bricks may rise to space-color ;; background color of space where bricks stack up ] breed [ messengers messenger ] ;; messengers carry a brick to the random-value column. ;; they place the brick on top of the column breed [ column-counters column-counter ] ;; column-counters live on top of each column. Messengers go to column-counters. breed [ bricks brick ] ;; when a messenger brings a square bricks that indicate events in histogram columns messengers-own [ destination ] ;; destination is the top of the column that the messenger heads towards column-counters-own [ my-column ;; what column it is in, with the left-most pycor being "1" my-column-patches ;; all patches that are in its column as an agentset num-messengers-pointing-to-me ;; how many messengers are about to move towards it my-ycor ;; its ycor, even if this ycor is out of bounds below the edge of the world ] to setup clear-all set height world-height - 10 set space-color white set max-y-histogram (min-pycor + height) ;; bricks placed above this line cause ;; all bricks to bump down create-histogram-space setup-column-counters set at-top? false set list-of-label-means [] reset-ticks end to create-histogram-space ;; this code supports a slider for sample-space (the slider does not exist now) ask patches [ ifelse (pxcor < (min-pxcor + sample-space) ) and (pycor < max-y-histogram) [ set pcolor space-color ] [ set pcolor white - 2 ] ] end to setup-column-counters ;; column-counters show messengers where to take their bricks. ask patches with [ (pycor = min-pycor ) and pcolor = space-color ] [ sprout 1 [ set breed column-counters ht set heading 0 ;; each column-counter knows its column in the histogram set my-column floor (max-pxcor + pxcor + 1) ;; each column-counter knows its patches set my-column-patches patches with [ pxcor = [pxcor] of myself ] set my-ycor ycor ] ] end to go ;; forever button if at-top? and (not bump-down?) [ stop ] place-messengers-and-choose-random-values ask messengers [point-to-your-column] ask column-counters [count-num-messengers-pointing-to-you] if bump-down? [ bump-down ] move-messengers tick histogram-labels histogram-label-means ask messengers [ die ] end to place-messengers-and-choose-random-values ;; each messenger is born and gets a random value from the sample space ;; messengers are centered over the middle of the space and equally distributed across it let increment ( sample-space / num-messengers ) let it round (min-pxcor + increment / 2) repeat num-messengers [ ask patch round (it + counter * increment) (max-y-histogram + 4) [ sprout 1 [ set breed messengers set shape "messenger" ht set color 3 + 10 * counter set label-color red set heading 180 set size world-height - height + 2 set label 1 + random sample-space ] ] set counter counter + 1 ] set counter 0 ask messengers [st] end to point-to-your-column ;; turtle procedures. Each messenger points towards the top of its column set destination one-of column-counters with [ my-column = [label] of myself ] face destination ;; messenger heads to column top end ;; Each column-counter figures out how many messengers point at it to count-num-messengers-pointing-to-you ;; turtle procedure set num-messengers-pointing-to-me count messengers with [destination = myself] end to move-messengers ;; Each messenger goes to the top of the column of its value while [any? messengers with [distance destination > 3] ] [ ask messengers with [distance destination > 3] [ ;; messenger will stop when it appears on top of its destination face destination ;; this is a precaution in case the column-counter has gone up fd 1 ] display ] ask messengers [ lay-your-brick ] end to lay-your-brick ;; when messenger has arrived, the column-counter builds a brick and moves above it ask destination [ ifelse my-ycor < min-pycor [ set my-ycor my-ycor + 1 ] [ create-brick fd 1 if (ycor = max-y-histogram) [ set at-top? true ] set my-ycor ycor ] ] ht end to create-brick ;; turtle procedure ;; its patch creates the square brick ask patch-here [ sprout 1 [ set breed bricks set shape "brick" set color black ] ] end to histogram-labels set list-of-labels ( sentence list-of-labels [label] of messengers ) set-current-plot "All Values From Messengers" histogram list-of-labels let maxbar modes list-of-labels let maxrange length ( filter [ ? = item 0 maxbar ] list-of-labels ) set-plot-y-range 0 max list 10 maxrange end to histogram-label-means ;; the histogram displays the mean values from the batches of messengers over all runs. ;; for even numbered sample spaces, mean values that fall in between the center columns ;; are assigned randomly either to the left-side column or to the right-side column let mean-num ( mean [ label ] of messengers ) ifelse ( mean-num - (int mean-num) ) = .5 [ if random 2 = 0 [ set mean-num round mean-num ] ] [ set mean-num round mean-num ] set list-of-label-means ( sentence mean-num list-of-label-means ) set-current-plot "Mean Values of Batches of Messengers" histogram list-of-label-means end to bump-down ;; when columns have reached the top of the space, they all go down by one brick ;; first, we determine how far above the max line we would go if we didn't bump down (it might zero) let expected-max-height ( max [ my-ycor + num-messengers-pointing-to-me ] of column-counters ) let num-over-the-top ( expected-max-height - max-y-histogram ) if num-over-the-top <= 0 [stop] repeat num-over-the-top [ ask column-counters [ ifelse my-ycor <= min-pycor [ set my-ycor my-ycor - 1 ] [ (set heading 180) (fd 1) (ask bricks-here [die]) (set heading 0) (set my-ycor ycor)] ] ] end to-report max-diff ;; difference in height between tallest and shortest columns; ;; "short" can be below the bottom of the world) report max [my-ycor] of column-counters - min [my-ycor] of column-counters end ; Copyright 2004 Uri Wilensky. ; See Info tab for full copyright and license.

There are 15 versions of this model.

## Attached files

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

Random Basic Advanced.png | preview | Preview for 'Random Basic Advanced' | about 10 years ago, by Uri Wilensky | Download |

This model does not have any ancestors.

This model does not have any descendants.