Expected Value

Expected Value preview image

2 collaborators

Uri_dolphin3 Uri Wilensky (Author)
Dor Abrahamson (Author)

Tags

mathematics 

Tagged by Reuven M. Lerner over 11 years ago

Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0.4 • Viewed 553 times • Downloaded 87 times • Run 1 time
Download the 'Expected Value' modelDownload this modelEmbed this model

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


WHAT IS IT?

In this model you run experiments that demonstrate the mathematical idea "expected value" (sometimes called "expectation value"). There is a set of different possible outcomes, and each of these outcomes has a different value. The model predicts the expected value based on the probabilities of each of these outcomes. The user can then take samples from the population and compare them to the values predicted by the model.

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/.

PEDAGOGICAL NOTE

Expected-value analyses look at the 'value' of outcomes in probability experiments in terms of some utilitarian framework, such as money or points. As in life, some events are more significant to us, not just because they happen rarely or often. In that sense, expected-value simulations go beyond looking just at chance -- they introduces a 'worth' factor (weight, coefficient) associated with each type of experimental outcome. That is, these simulations examine not only the issue of what I should expect, but also, what it would be worth for me. For instance, if I draw 12 coins randomly from a sack containing an equal number of pennies, nickels, dimes, and quarters, we could talk about which 12 'coins' I could expect to get (a nominal classification) -- 3 'pennies,' 3 'nickels,' 3 'dimes,' and 3 'quarters,' on average. But we could extend the discussion to how much money I would get, that is, what would be the 'value' of my draw. To do this, we'd have to multiply the expected frequency of each type of coin by its value: 3 * 1 + 3 * 5 + 3 * 10 + 3 * 25 = 123 cents.

A more general way of putting this all together -- the sample size (12), the probabilities of each coin (1/4 for each of them), and the value of each coin (1, 5, 10, and 25) -- is: 12 * (1 * 1/4 + 5 * 1/4 + 10 * 1/4 + 25 * 1/4) = 123 cents.

Thus, the term 'expected value' may be defined as the sum of the products of the value of each possible event and the probability of that possible event.

HOW IT WORKS

The analogy utilized for the model is one of a tiled playground, with a certain number of marbles beneath each tile (0, 1, 2, 3, 4, 5 or 6 marbles). A wandering kid flips up some tiles at every go and counts up the marbles found beneath the tiles. That's a "sample." The kid cannot see the color of the tiles -- the colors are for us.

The idea of 'expected value' is that if we know how many tiles have 0, 1, 2,... or 6 marbles beneath them, then we can formulate an educated guess of how many marbles the wandering kid will find, on average. It's similar to asking, 'How many marbles are there on average under each tile?' We need to somehow take into account the chance of getting each one of the marble sets.

In the setting-up phase of using this model, you get to set up the relative number of tiles hiding 0 marbles, 1 marble, 2 marbles, ... and 6 marbles. We set the ratio between the number of tiles hiding each set of marbles. The computer program will do much of the calculations for us, but here's the gist of what it does:

Let's say that we set the sliders to the following ratio units: 0 : 1 : 6 : 5 : 0 : 4 : 0.

The number '5,' for example, indicates our value setting for marble sets of exactly 3 marbles. You can see immediately that the chance of getting a '2' (6 ratio units) is greater than the chance of getting a '3' (5 ratio units). But in order to determine just how big the chance is of getting each marble set, we need to state the ratio units relative to each other. We need a common denominator. In this particular setting, there is a total of 16 'ratio units': 0 + 1 + 6 + 5 + 0 + 4 + 0 = 16. Now we can say, for instance, that there is a 4/16 chance of getting a 5-marble set. That is a 25% chance of striking upon a tile that has exactly 5 marbles beneath it. We can also say that these sets of 5 marbles contribute .25 * 5, that is, 1.25 marbles, to the overall average marble-value of a single tile in the playground. Similarly, we can say there is a 5/16 chance of getting a set of 3, a 0/16 chance of getting 6-marble set, etc. If we sum up all pairs of 'value' and 'probability,' we get: (0 * 0/16) + (1 * 1/16) + (2 * 6/16) + (3 * 5/16) + (4 * 0/16) + (5 * 4/16) + (6 * 0/16) = 48/16 = 3 marbles per tile.

This tells us that on any single pick within these settings, you should expect to find, on average, 3 marbles. "3" is our expected value. Thus, if you were to flip over 10 tiles, you should expect to find a total of 30 marbles.

HOW TO USE IT

Begin by choosing ratios of marble sets (or just use the default settings). Click SETUP, and watch the information updated in the view. Below are more features of the models that will let you change the way it looks and runs.

Sliders: RATIO-0-UNITS, RATIO-1-UNITS, RATIO-2-UNITS, RATIO-3-UNITS, RATIO-4-UNITS, RATIO-5-UNITS, RATIO-6-UNITS -- settings for the distribution of 'marble sets' (= 'points'). Note that the ratios are set in proportion to each other (See 'THINGS TO TRY'). (The labels under the sliders let the user know that the highest value is the lightest tile color, while the lowest value is the darkest tile color.)

SAMPLE-SIZE -- sets the number of tiles selected by the wandering kid at each run. Note that the kid can turn over the same tile more than once. This won't be visible in the view.

Switches: SETUP-APART? -- if 'On,' when SETUP is pressed, the display initially separates the population by point value, to illustrate the relative number of patches of different values. After a 3 second pause, the model scrambles the populations, producing a randomized display.

DIE-NUMS? -- if 'On,' you will see the marbles and not only colors, when the tiles are flipped over; if 'Off,' you'll see the colors and the numerical value assigned to them.

BLACK-OUT? -- if 'On,' you will only see the tiles the kid selected in the present sample; if 'Off,' you will always see all the tiles. In any case, the kid does not see the colors. The 'black-out' feature makes this model more coherent with S.A.M.P.L.E.R., a participatory simulation in ProbLab.

Buttons: SETUP -- initializes variables, re-colors the tiles, and resets the monitors and the graphs.

GO ONCE -- picks a starting point randomly among the tiles in the view, sends the kid for a single run over random tiles, counts up the total number of marbles found, and graphs this total, that is, 'bumps up' the histogram at the corresponding value.

CLEAR SELECTION -- re-covers the tiles that have been flipped (does not re-initialize variables).

GO -- does everything that the GO ONCE button does, but over and over, until turned off, that is, until you press on it again.

Monitors: % IN POPULATION -- shows the distribution percentage of each marble-set in the population, including the calculation that illustrates how that percentage was obtained. For instance, if the RATIO-3-UNITS's % IN POPULATION monitor is at 50%, then roughly half of all the tiles will have exactly 3 marbles beneath them.

EXPECTATION VALUE CALCULATION -- This monitor shows the calculation of the expected number of marbles that the kid will find beneath all the tiles the kid flips in a sample. The calculation first determines the value of the 'average tile' and then multiplies this value by the number of tiles in the kid's sample (how many tiles the kid flips). Thus, 'average value' * 'sample-size' = total expected value of sample. The formula for the expectation calculation is: sample-size * (0 * (ratio-0-units / ratios-total) + 1 * (ratio-1-units / ratios-total) + 2 * (ratio-2-units / ratios-total) + 3 * (ratio-3-units / ratios-total) + 4 * (ratio-4-units / ratios-total) + 5 * (ratio-5-units / ratios-total) + 6 * (ratio-6-units / ratios-total))

EXPECTED VALUE -- shows the result of the EXPECTED VALUE CALCULATION

MEAN OF SAMPLES-- monitors the cumulative average number of points obtained in a sample (so it keeps updating for each sample).

# OF RUNS -- monitors the number of times the tiles were selected and counted as a sample.

POINT TOTAL -- monitors the total number of marbles in the current sample. (updates the total as each tile is selected).

Plots: SAMPLE TOTALS -- plots the frequency of each point-total of a run. The green vertical line represents the average sample total, while the red vertical line represents the expected sample total.

CUMULATIVE MEAN -- plots the average number of points obtained in a single run in black against the expected value in red.

THINGS TO NOTICE

If the model is slowed down, using the bar on top of the display, one may see that the sample total is added on every time that the wandering kid selects another tile. Thus, one may monitor the running total for the current run of the kid.

A feature of this model is that the wandering kid may resample the same tiles during a single run. While the kid cannot go back to a tile it just selected, it can potentially go in a circle and come back to such a tile. This may skew the average away from the expected value, which does not account for such re-sampling (see 'EXTENDING THE MODEL,' below).

THINGS TO TRY

Run the model under different setting of the three switches. Why does DIE-NUMS? help one visualize the model better in some situations and under some settings, while not in others?

The relative ratios of the various marble sets are determined by relative values of all of the sliders on the left. In other words, if one sets RATIO-0-UNIT : RATIO-2-UNITS : ..., : RATIO-6-UNITS to 1 : 1 : 1 : 1 : 1 : 1 : 1, it is going to mean the same to the computer as the setting of 2 : 2 : 2 : 2 : 2 : 2 : 2 or 5 : 5 : 5 : 5 : 5 : 5 : 5. The sliders are designed to allow an exploration of a rich range of proportions of the different marble sets. Try extending the maximum value of the RATIO sliders, to obtain a richer range of proportions of marble sets.

Change the target-color to some color other than green. Change the 'little-guy-color,' which alters the color of the wandering kid.

Set the ratio-0-units to 0. Set all the other ratio sliders to some value, for instance 2. (It doesn't matter which, as long as they are the same.) Press SETUP. The model now simulates the sample space of dice, which do not have a '0,' and for which each 1-thru-6 value is equally likely to occur.

Set the ratios of the 0 and 1 to some non-zero value. Set the ratios of 2, 3, 4, 5 and 6 to 0. Press SETUP. This produces a sample space of a Boolean type ('true' or 'false'). This sample space would be coherent with the S.A.M.P.L.E.R. model of ProbLab, where tiles are either green (true) or blue (false), without in-between values.

Set the ratios of 5 and 6 to 0. Set the other ratios to non-zero values. Press SETUP. The model produces a sample space that could be seen as a tessellation of '4-blocks,' which appear in the 9-Block Stalagmite model of ProbLab. In that model, blocks have either 0, 1, 2, 3, or all 4 squares with the target-color.

EXTENDING THE MODEL

Add and change code so that the wandering kid cannot re-sample within a single sample.

Add and change code so that the wandering kid cannot re-sample within a single run of many samples.

Add a monitor that show the % difference between the expected value and the mean of samples.

Add another unit-value slider. It could for 7, so you'd need to create a die shape with 7 dots on it and integrate that die shape and its name into the lists in the code. You could possibly create a 'negative value,' which could be interpreted as an added expense, like owing marbles.

RELATED MODELS

This model is closely related to a variety of models in the ProbLab curriculum. As described in the 'THINGS TO TRY' section, one may set the ratios up so that they mirror the sample population of other models in the curriculum, including 9-Block Stalagmite and S.A.M.P.L.E.R. For instance, if one sets BLACK-OUT? to 'On,' this model would produce an effect that is similar to that of S.A.M.P.L.E.R., where one chooses a certain number of tiles and doesn't see any of the other tiles in the population.

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 Expected Value model. http://ccl.northwestern.edu/netlogo/models/ExpectedValue. 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.

CC BY-NC-SA 3.0

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

Click to Run Model

globals [
  ratio-list ; list of ratio-unit sliders
  my-sample-size ; keeps track of the original sample-size
  #patches ;; keeps the number of patches, so don't have to recalculate all the time

  ;; outputs that will be printed in the monitors
  expected-value-calculation
  expected-value
  ratio-monitor-list ; the "% in Population" monitors pick items from ratio-monitor-list

  the-little-guy ; wanders around picking tiles to turn over

  all-totals ; list of the totals from each run

  colors ; list of the colors given for each number of marbles

  target-color ; the default base color of the display

  little-guy-color ; the color of the little-guy
]

patches-own [ value index ] ; how many marbles are under the tile

breed [ outlines outline ]
breed [ little-guys little-guy ]

little-guys-own [ values ] ; list of numbers in the running total of the sample

to startup
  set expected-value-calculation ""
end 

to setup
  ca
  set expected-value-calculation ""
  setup-misc-globals ; collects ratio-unit sliders, etc.
  ;;checks for all 0s
  if sum ratio-list = 0 [ user-message "Cannot set all ratio-units sliders to 0"  stop ]
  setup-patches ; sets the values and colors of the patches
  setup-little-guy
  setup-monitors ; sets the global variables the monitors display
  set all-totals lput ( [sum values] of the-little-guy ) all-totals
  reset-ticks
end 

to go
  clear-selection
  ask little-guys
  [
    get-ready-for-next-sample
    repeat my-sample-size
    [
      set values ( lput value values )
      select-patch
      let prev-heading heading
      fd 1
      rt one-of [ -90 0 90 ]
    ]
  ]
  set all-totals lput ( [sum values] of the-little-guy ) all-totals
  tick
end 

;; collects ratio-unit sliders, sets colors, etc.

to setup-misc-globals
  set ratio-list ( list ratio-0-units
                        ratio-1-units
                        ratio-2-units
                        ratio-3-units
                        ratio-4-units
                        ratio-5-units
                        ratio-6-units )

  set my-sample-size sample-size
  set #patches count patches

  set all-totals []

  set little-guy-color 94

  ;; sets the range of patch colors from dark to light
  set target-color green
  set colors ( list (target-color - 4.5)
                    (target-color - 3)
                    (target-color - 1.5)
                     target-color
                    (target-color + 1.5)
                    (target-color + 3)
                    (target-color + 4.5) )
end 

;; sets the values and colors of the patches

to setup-patches
  ;;makes all patches have no value
  ask patches [ set value -1 ]
  let cur-val 0

  ;;finds the number of patches of each type that need to be printed:
  ;;makes the percentages, multiplies them by the number of patches
  let list-of-nums map [? / (sum ratio-list) * #patches] ratio-list
  ;;rounds the numbers of patches with a specific value
  let r-list-of-nums map [round ?] list-of-nums

  ;;tweaks the values, either in the positive or in the negative direction,
  ;;for the sum to equal to the number of patches on the display
  let nums setup-patches-polish list-of-nums r-list-of-nums

  ;;prints out the values on random patches that are not already taken
  foreach nums
  [
    ask n-of ? patches with [ value = -1 ]
    [ set value cur-val ]
    set cur-val cur-val + 1
  ]

  ;;if population to be shown, shows in block, then scrambles
  ifelse setup-apart?
  [
    print-out nums
    wait 2
    repeat (#patches / 4) [ disperse ]
    ask patches [ set value position pcolor colors ]
  ]
  ;;colors the patches from their given values
  [ recolor-patches ]
end 

;;tweaks the values so that they add up to the number of patches
;;(in the positive or negative direction)

to-report setup-patches-polish [ list-of-nums r-list-of-nums ]
  ;;tweaks the values, either in the positive or in the negative direction,
  ;;for the sum to equal to the number of patches on the display:
  ;;if the sum is below the number of patches, then searches for the highest remainder to round up
  while [sum r-list-of-nums < #patches]
  [
    let remainders map [remainder (? * #patches) #patches] list-of-nums
    ;;finds the position of the maximum remainder
    let pos-of-max position (max remainders) remainders
    ;;updates the list of numbers of each type of patch
    set r-list-of-nums (replace-item pos-of-max r-list-of-nums ((item pos-of-max r-list-of-nums) + 1))
    set list-of-nums (replace-item pos-of-max list-of-nums (floor (item pos-of-max list-of-nums) + 1))
  ]
  ;;if the sum is above the number of patches, then searches for the lowest remainder to round up
  ;;to prevent a bug that would make 0 always be the minimum remainder, all the 0's are changed
  ;;to large numbers, for them to not become negative
  while [sum r-list-of-nums > #patches]
  [
    let remainders map [remainder (? * #patches) #patches ] list-of-nums
    ;;remainders1 makes sure that the 0 is not deemed the minimum remainder, but
    ;;looks for minimum remainder above 0
    let remainders1 []
    foreach remainders
    [
      ifelse ? = 0
      [ set remainders1 (lput #patches remainders1) ]
      [ set remainders1 (lput ? remainders1) ]
    ]
    ;;finds the position of the minimum remainder
    let pos-of-min position (min remainders1) remainders1
    ;;updates the list of numbers of each type of patch
    set r-list-of-nums (replace-item pos-of-min r-list-of-nums ((item pos-of-min r-list-of-nums) - 1))
    set list-of-nums (replace-item pos-of-min list-of-nums (floor (item pos-of-min list-of-nums)))
  ]
  report r-list-of-nums
end 

;;shows the populations separately

to print-out [ list-of-nums ]
  ;;indexes the patches (from left to right, down to up), if had not already done so
  ask patches [ set index ((pxcor + max-pxcor) * (max-pxcor * 2 + 1) + (pycor + max-pycor)) ]

  ;;shows the separated populations
  let patch-now 0
  let temp 0
  foreach list-of-nums
  [
    repeat ?
    [
      ask patches with [index = patch-now] [ set pcolor item temp colors ]
      set patch-now patch-now + 1
    ]
    set temp temp + 1
  ]
end 

;;asks all the patches to switch its color with one of its neighbors

to disperse
  ask patches
  [
    let other-patch one-of neighbors4
    let temp-color pcolor
    set pcolor [pcolor] of other-patch
    ask other-patch [ set pcolor temp-color ]
  ]
end 

;;colors the patches according to their value

to recolor-patches
  ifelse black-out? [ ask patches [ set pcolor 0 ] ] [ ask patches [ set pcolor item value colors ] ]
end 

to setup-little-guy
  create-little-guys 1 [
    hide-turtle
    set color little-guy-color
    set shape "person"
    move-to one-of patches
    face one-of neighbors4
    set values []
    show-turtle
  ]
  set the-little-guy one-of little-guys
end 

;; sets the global variables the monitors display

to setup-monitors
  ;; the "% in Population" monitors pick items from ratio-monitor-list
  set ratio-monitor-list map [(word ? "/" (sum ratio-list) " = "
                                    precision (100 * ? / (sum ratio-list)) 1
                                    "%")]
                             ratio-list
  set expected-value  my-sample-size * sum map [ ? * item ? ratio-list / (sum ratio-list) ]
                                           [ 0 1 2 3 4 5 6 ]
  set expected-value-calculation word my-sample-size " * ("
  foreach [ 0 1 2 3 4 5 ] [
    set expected-value-calculation (word expected-value-calculation
                                         ? " * " item ? ratio-list "/" (sum ratio-list) " + ")
  ]
  ;; we separated out the "6 case" because we don't add a "+", but we do add a ") ="
  set expected-value-calculation (word expected-value-calculation
                                       6 " * " item 6 ratio-list "/" (sum ratio-list) ") = ")
end 


;; clears the red from the patches chosen before

to clear-selection
  recolor-patches
  ask turtles with [ breed = outlines ] [ die ]
end 

to get-ready-for-next-sample ;; little-guy procedure
  slide-to-random-patch
  face one-of neighbors4
  set values []
end 

to slide-to-random-patch ;; little-guy procedure
  let random-patch one-of patches
  while [ patch-here != random-patch ] [
    face random-patch
    fd 1
  ]
  setxy pxcor pycor
end 

;; highlights the point given to it

to select-patch ;; little-guy procedure
  let shapes-list (list "outline"
                        "outline1"
                        "outline2"
                        "outline3"
                        "outline4"
                        "outline5"
                        "outline6")
  ask patch-here
  [
    set pcolor item value colors
    sprout 1
    [
      set breed outlines
      ;; set the shape and label correctly.
      ifelse die-nums?
      [
        ;; if die-nums? the shape holds the value and there are no labels
        set shape (item value shapes-list)
      ]
      [
        ;; if not die-nums? the shape doesn't hold the label, so set the label
        set shape "outline"
        ;; sets label color to be opposite color in the list of colors
        set label-color item ((value + 2) mod length colors) colors
        ;; the " " on the end pushes the label into the middle of the patch
        set label word value " "
      ]
    ]
  ]
end 

to plot-vert-line [ x-coord ]
  plotxy x-coord plot-y-min
  plot-pen-down
  plotxy x-coord plot-y-max
  plot-pen-up
end 


; Copyright 2004 Uri Wilensky.
; See Info tab for full copyright and license.

There are 15 versions of this model.

Uploaded by When Description Download
Uri Wilensky over 11 years ago Updated to NetLogo 5.0.4 Download this version
Uri Wilensky about 12 years ago Updated version tag Download this version
Uri Wilensky about 12 years ago Updated to version from NetLogo 5.0.3 distribution Download this version
Uri Wilensky almost 13 years ago Updated to NetLogo 5.0 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Model from NetLogo distribution Download this version
Uri Wilensky over 14 years ago Model from NetLogo distribution Download this version
Uri Wilensky over 14 years ago Expected Value Download this version

Attached files

File Type Description Last updated
Expected Value.png preview Preview for 'Expected Value' over 11 years ago, by Uri Wilensky Download

This model does not have any ancestors.

This model does not have any descendants.