Reactive voters model v1.0

Reactive voters model v1.0 preview image

1 collaborator

Joe_wasserman_face_cropped_square Joe Wasserman (Author)

Tags

elections 

Tagged by Joe Wasserman about 6 years ago

electoral system, voting behavior 

Tagged by Joe Wasserman about 6 years ago

electoral system@ 

Tagged by Joe Wasserman about 6 years ago

voter 

Tagged by Joe Wasserman about 6 years ago

voting 

Tagged by Joe Wasserman about 6 years ago

Visible to everyone | Changeable by everyone
Model was written in NetLogo 6.0.4 • Viewed 665 times • Downloaded 74 times • Run 0 times
Download the 'Reactive voters model v1.0' modelDownload this modelEmbed this model

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


Info tab cannot be displayed because of an encoding error

Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

globals [
  DRecGen ;; running record of general election victories and losses, Democrats
  RRecGen ;; running record of general election victories and losses, Republicans
  DCur ;; result of current election, Democrats
  RCur ;; result of current election, Republicans
  DVotes ;; current number of electoral votes for Democrats
  RVotes ;; current number of electoral votes for Republicans
  D9616gen ;; general election outcomes 1996-2016 for model validation and parameter search (Democrat: lose = 0, win = 1)
  globalfit ;; model fit based on correspondence between model-generated data and 1996-2016 historical data; higher is better
  globalpopfit ;; model fit based on mean squared difference between popular vote outcomes and predictions
]

patches-own [
  Abbr ;; 2-letter state abbreviation
  DMax ;; total population of Democratic voters in state
  RMax ;; total population of Republican voters in state
  votes ;; number of electoral votes of state
  DRecSt ;; running record of Dem's wins and losses
  RRecSt ;; running record of Repub's wins and losses
  PctD ;; percentage of Democrat voters in state who will vote
  PctR ;; percentage of Republican voters in state who will vote
  Dout ;; outcome for the Democratic candidate in state
  Rout ;; outcome for the Republican candidate in state
  Dpopout ;; popular votes for the Democratic candidate in state
  Rpopout ;; popular votes for the Republican candidate in state
  D9616 ;; state election outcomes 1996-2016 for model validation and parameter search (Democrat: lose = 0, win = 1)
  Dpop9616 ;; state popular votes, 1996–2016
  Rpop9616 ;; state popular vote, 1996–2016
  pfit ;; boolean comparison of state outcome to historical outcome, 0 or 1
  popfit ;; running mean squared error of popular votes across all states
]

to setup
  clear-all
  reset-ticks
  hist-gen ;; initiates general election with historical starting values, 1984–1992 elections
  hist-state ;; initates each state with historical starting values, 1984–1992 elections
  valid-state ;; import records of 1996–2016 state outcomes for model validation
  valid-gen ;; import records of 1996–2016 general election outcomes for model validation
  ask patches [
    set plabel-color white
    set plabel abbr
    set pfit 1
    set popfit 0
  ]
  color-patches
end 

to go
  ;; states look back at general election record and adjust current vote %
  look-gen
  ;; states look back at state election record and adjust current vote %
  look-state
  ;; all states adjust their current vote % based on growth-constant
  fixed-change
  ;; when cap-growth? switch is ON: ensure percent of partisan voters doesn't exceed 100% (i.e. historically observed maximum turnout)
  check-range
  ;; vote and determine state + general winner
  vote
  ;; visualize state voting
  color-patches
  ;; calculate model fit depending on model outcomes and add to model fit for running total
  if ticks < 6 [ model-fit ]
  ;; each tick = 1 4-year election cycle
  tick
end 

;; look back at general election record and adjust current vote %

to look-gen
  ask patches [
    set PctD PctD + ( ( last DRecGen * react-gen-win ) ;; decrease voting for winning
                  +   ( last RRecGen * react-gen-loss ) ;; increase voting for losing
                  ;;+   ( last RRecGen * ( item (length RRecGen - 1) RRecGen ) * react-2x-gen-loss ) ;; increase voting for losing twice in a row
      )
    set PctR PctR + ( ( last RRecGen * react-gen-win ) ;; decrease voting for winning
                  +   ( last DRecGen * react-gen-loss ) ;; increase voting for losing
                  ;;+   ( last DRecGen * ( item (length DRecGen - 1) RRecGen ) * react-2x-gen-loss ) ;; increase voting for losing
      )
  ]
end 

;; look back at state election record and adjust current vote %

to look-state
  ask patches [
    set PctD PctD + ( ( last DRecSt * react-st-win )  ;; decrease voting for winning
                  +   ( last RRecSt  * react-st-loss ) ) ;; increase voting for losing
    set PctR PctR + ( ( last RRecSt * react-st-win ) ;; decrease voting for winning
                  +   ( last DRecSt * react-st-loss ) ) ;; increase voting for losing
  ]
end 

;; all states adjust their current vote % based on growth-constant

to fixed-change
  ask patches [
    set PctD PctD + growth-constant
    set PctR PctR + growth-constant
  ]
end 

;; ensure that percent of partisan voters are within range 0–1
;; if cap-growth? is FALSE, percent is allowed to exceed 1

to check-range
  ask patches [
     if cap-growth? [
      if PctD > 1 [ set PctD 1 ]
      if PctR > 1 [ set PctR 1 ] ]

    if PctD < 0 [
      set PctD 0 ]
    if PctR < 0 [
      set PctR 0 ]
  ]
end 

;; calculate state votes to determine winner at state level, allocate electoral votes, and determine general election winner

to vote
  ask patches [
    set Dpopout ( PctD * DMax )
    set Rpopout ( PctR * RMax )
  ;; calculate D + R votes and determine state winner
    ifelse Dpopout > Rpopout [
      ;;dems win
      set Dout 1
      set Rout 0
    ] [
      ;;repubs win
      set Dout 0
      set Rout 1
    ]

  ;; just in case a state's votes are tied, which should happen very rarely if ever, flip a coin for the winner
      if Dpopout = Rpopout [
        let coin random 1
        ifelse coin = 1 [
        ;;dems win
        set Dout 1
        set Rout 0
        ] [
        ;;repubs win
        set Dout 0
        set Rout 1
      ]
      ]

   ;; append state winner to state winner records (DRecSt, RRecSt)
      set DRecSt lput Dout DRecSt
      set RRecSt lput Rout RRecSt
  ]

  ;; allocate electoral votes to general election, determine general election winner, and append general election winner to general winner records (DRecGen, RRecGen)
    ;; sum of all states (Dout * votes) vs sum of (Rout * votes)
  set DVotes sum [Dout * votes] of patches
  set RVotes sum [Rout * votes] of patches
  ifelse DVotes > RVotes [
    ;;dems win
    set DRecGen lput 1 DRecGen
    set RRecGen lput 0 RRecGen
    set DCur 1
    set RCur 0
  ] [
    ;;rpubs win
    set DRecGen lput 0 DRecGen
    set RRecGen lput 1 RRecGen
    set DCur 0
    set RCur 1
  ]
end 

;; color patches to visualize state level outcomes, blue = Dem, red = Repub

to color-patches
  ask patches [
  ifelse Dout = 1 [
    set pcolor blue ] [
    set pcolor red
  ]
  ]
end 

;; seed model with historical general election data

to hist-gen
  ;;set historical general election record, from 1984 (50) to 1992 (52)
  set DRecGen [ 0 0 1 ]
  set RRecGen [ 1 1 0 ]
  ;;set sitting president (52)
  set DCur 1
  set RCur 0
end 

;; seed model with historical state outcome data

to hist-state
  ask patches [
   if pxcor = 0 [
      ;; set first column of states (AK–KS)
      if pycor = 16 [ set Abbr "AK" set Dmax 123594 set Rmax 193841 set votes 3 set DRecSt [ 0 0 0 ] set RRecSt [ 1 1 1 ] set PctD 0.633477353269576 set PctR 0.526204466547325 set Dout 0 set Rout 1 ]
      if pycor = 15 [ set Abbr "AL" set Dmax 813479 set Rmax 1318255 set votes 9 set DRecSt [ 0 0 0 ] set RRecSt [ 1 1 1 ] set PctD 0.84830708598501 set PctR 0.610111852410952 set Dout 0 set Rout 1 ]
      if pycor = 14 [ set Abbr "AR" set Dmax 505823 set Rmax 684872 set votes 6 set DRecSt [ 0 0 1 ] set RRecSt [ 1 1 0 ] set PctD 1 set PctR 0.492535831513042 set Dout 1 set Rout 0 ]
      if pycor = 13 [ set Abbr "AZ" set Dmax 1161167 set Rmax 1252401 set votes 11 set DRecSt [ 0 0 0 ] set RRecSt [ 1 1 1 ] set PctD 0.467676053487569 set PctR 0.456791395088314 set Dout 0 set Rout 1 ]
      if pycor = 12 [ set Abbr "CA" set Dmax 8753792 set Rmax 5509826 set votes 55 set DRecSt [ 0 0 1 ] set RRecSt [ 1 1 0 ] set PctD 0.585040745770519 set PctR 0.65892716031323 set Dout 1 set Rout 0 ]
      if pycor = 11 [ set Abbr "CO" set Dmax 1338870 set Rmax 1202484 set votes 9 set DRecSt [ 0 0 1 ] set RRecSt [ 1 1 0 ] set PctD 0.470307796873483 set PctR 0.468072756061619 set Dout 1 set Rout 0 ]
      if pycor = 10 [ set Abbr "CT" set Dmax 997772 set Rmax 693826 set votes 7 set DRecSt [ 0 0 1 ] set RRecSt [ 1 1 0 ] set PctD 0.683841599082756 set PctR 0.833513013349168 set Dout 1 set Rout 0 ]
      if pycor = 9 [ set Abbr "DC" set Dmax 282830 set Rmax 21381 set votes 3 set DRecSt [ 1 1 1 ] set RRecSt [ 0 0 0 ] set PctD 0.68104161510448 set PctR 0.968055750432627 set Dout 1 set Rout 0 ]
      if pycor = 8 [ set Abbr "DE" set Dmax 255459 set Rmax 185127 set votes 3 set DRecSt [ 0 0 1 ] set RRecSt [ 1 1 0 ] set PctD 0.493445132095561 set PctR 0.552663846980721 set Dout 1 set Rout 0 ]
      if pycor = 7 [ set Abbr "FL" set Dmax 4504975 set Rmax 4617886 set votes 29 set DRecSt [ 0 0 0 ] set RRecSt [ 1 1 1 ] set PctD 0.460113097186999 set PctR 0.470628768228579 set Dout 0 set Rout 1 ]
      if pycor = 6 [ set Abbr "GA" set Dmax 1877963 set Rmax 2089104 set votes 16 set DRecSt [ 0 0 1 ] set RRecSt [ 1 1 0 ] set PctD 0.53726617617067 set PctR 0.476401366327382 set Dout 1 set Rout 0 ]
      if pycor = 5 [ set Abbr "HI" set Dmax 325871 set Rmax 194191 set votes 3 set DRecSt [ 0 1 1 ] set RRecSt [ 1 0 0 ] set PctD 0.550248411181112 set PctR 0.704574362354589 set Dout 1 set Rout 0 ]
      if pycor = 4 [ set Abbr "IA" set Dmax 828940 set Rmax 800983 set votes 6 set DRecSt [ 0 1 1 ] set RRecSt [ 1 0 0 ] set PctD 0.707352763770599 set PctR 0.630339220682586 set Dout 1 set Rout 0 ]
      if pycor = 3 [ set Abbr "ID" set Dmax 236440 set Rmax 420911 set votes 4 set DRecSt [ 0 0 0 ] set RRecSt [ 1 1 1 ] set PctD 0.579483166976823 set PctR 0.481443820665176 set Dout 0 set Rout 1 ]
      if pycor = 2 [ set Abbr "IL" set Dmax 3419348 set Rmax 2345946 set votes 20 set DRecSt [ 0 0 1 ] set RRecSt [ 1 1 0 ] set PctD 0.717490585924568 set PctR 0.739188370064784 set Dout 1 set Rout 0 ]
      if pycor = 1 [ set Abbr "IN" set Dmax 1374039 set Rmax 1557286 set votes 11 set DRecSt [ 0 0 0 ] set RRecSt [ 1 1 1 ] set PctD 0.617464278670402 set PctR 0.635320037552511 set Dout 0 set Rout 1 ]
      if pycor = 0 [ set Abbr "KS" set Dmax 514765 set Rmax 736456 set votes 6 set DRecSt [ 0 0 0 ] set RRecSt [ 1 1 1 ] set PctD 0.758470369974649 set PctR 0.610967932911131 set Dout 0 set Rout 1 ]
    ]
    if pxcor = 1 [
     ;; set second column of states (KY–NV)
      if pycor = 16 [ set Abbr "KY" set Dmax 751985 set Rmax 1202971 set votes 8 set DRecSt [ 0 0 1 ] set RRecSt [ 1 1 0 ] set PctD 0.884464450753672 set PctR 0.513044786615804 set Dout 1 set Rout 0 ]
      if pycor = 15 [ set Abbr "LA" set Dmax 927837 set Rmax 1178638 set votes 8 set DRecSt [ 0 0 1 ] set RRecSt [ 1 1 0 ] set PctD 0.879433564300626 set PctR 0.622231762424086 set Dout 1 set Rout 0 ]
      if pycor = 14 [ set Abbr "MA" set Dmax 1995196 set Rmax 1188314 set votes 11 set DRecSt [ 0 1 1 ] set RRecSt [ 1 0 0 ] set PctD 0.660906998610663 set PctR 0.677463195754657 set Dout 1 set Rout 0 ]
      if pycor = 13 [ set Abbr "MD" set Dmax 1677928 set Rmax 1024703 set votes 10 set DRecSt [ 0 0 1 ] set RRecSt [ 1 1 0 ] set PctD 0.589161751874931 set PctR 0.690047750421342 set Dout 1 set Rout 0 ]
      if pycor = 12 [ set Abbr "ME" set Dmax 421923 set Rmax 335593 set votes 4 set DRecSt [ 0 0 1 ] set RRecSt [ 1 1 0 ] set PctD 0.624331927863615 set PctR 0.615340606031711 set Dout 1 set Rout 0 ]
      if pycor = 11 [ set Abbr "MI" set Dmax 2872579 set Rmax 2313746 set votes 16 set DRecSt [ 0 0 1 ] set RRecSt [ 1 1 0 ] set PctD 0.65139444380816 set PctR 0.672044381708277 set Dout 1 set Rout 0 ]
      if pycor = 10 [ set Abbr "MN" set Dmax 1573354 set Rmax 1346695 set votes 10 set DRecSt [ 1 1 1 ] set RRecSt [ 0 0 0 ] set PctD 0.648930247102686 set PctR 0.555315791623196 set Dout 1 set Rout 0 ]
      if pycor = 9 [ set Abbr "MO" set Dmax 1441911 set Rmax 1594511 set votes 10 set DRecSt [ 0 0 1 ] set RRecSt [ 1 1 0 ] set PctD 0.730886302968769 set PctR 0.508719601181804 set Dout 1 set Rout 0 ]
      if pycor = 8 [ set Abbr "MS" set Dmax 562949 set Rmax 724597 set votes 6 set DRecSt [ 0 0 0 ] set RRecSt [ 1 1 1 ] set PctD 0.711002239989768 set PctR 0.673192133006347 set Dout 0 set Rout 1 ]
      if pycor = 7 [ set Abbr "MT" set Dmax 231667 set Rmax 279240 set votes 3 set DRecSt [ 0 0 1 ] set RRecSt [ 1 1 0 ] set PctD 0.666935731027725 set PctR 0.516426729694886 set Dout 1 set Rout 0 ]
      if pycor = 6 [ set Abbr "NC" set Dmax 2189316 set Rmax 2362631 set votes 15 set DRecSt [ 0 0 0 ] set RRecSt [ 1 1 1 ] set PctD 0.508853906882332 set PctR 0.480253158449203 set Dout 0 set Rout 1 ]
      if pycor = 5 [ set Abbr "ND" set Dmax 141278 set Rmax 216794 set votes 3 set DRecSt [ 0 0 0 ] set RRecSt [ 1 1 1 ] set PctD 0.701935191608035 set PctR 0.628449126820853 set Dout 0 set Rout 1 ]
      if pycor = 4 [ set Abbr "NE" set Dmax 333319 set Rmax 512814 set votes 5 set DRecSt [ 0 0 0 ] set RRecSt [ 1 1 1 ] set PctD 0.652060038581659 set PctR 0.671483227836994 set Dout 0 set Rout 1 ]
      if pycor = 3 [ set Abbr "NH" set Dmax 384826 set Rmax 345790 set votes 4 set DRecSt [ 0 0 1 ] set RRecSt [ 1 1 0 ] set PctD 0.543206540098642 set PctR 0.585569276150265 set Dout 1 set Rout 0 ]
      if pycor = 2 [ set Abbr "NJ" set Dmax 2215422 set Rmax 1670003 set votes 14 set DRecSt [ 0 0 1 ] set RRecSt [ 1 1 0 ] set PctD 0.648276490889772 set PctR 0.812492552408589 set Dout 1 set Rout 0 ]
      if pycor = 1 [ set Abbr "NM" set Dmax 472422 set Rmax 376930 set votes 5 set DRecSt [ 0 0 1 ] set RRecSt [ 1 1 0 ] set PctD 0.553778189838746 set PctR 0.564624731382485 set Dout 1 set Rout 0 ]
      if pycor = 0 [ set Abbr "NV" set Dmax 539260 set Rmax 512058 set votes 6 set DRecSt [ 0 0 1 ] set RRecSt [ 1 1 0 ] set PctD 0.350754737974261 set PctR 0.343375164532143 set Dout 1 set Rout 0 ]
    ]
    if pxcor = 2 [
      ;; set third row of states (NY–WY)
       if pycor = 16 [ set Abbr "NY" set Dmax 4804945 set Rmax 2962567 set votes 29 set DRecSt [ 0 1 1 ] set RRecSt [ 1 0 0 ] set PctD 0.716855239758207 set PctR 0.792099891749284 set Dout 1 set Rout 0 ]
      if pycor = 15 [ set Abbr "OH" set Dmax 2940044 set Rmax 2859768 set votes 18 set DRecSt [ 0 0 1 ] set RRecSt [ 1 1 0 ] set PctD 0.675140235996468 set PctR 0.662399886983839 set Dout 1 set Rout 0 ]
      if pycor = 14 [ set Abbr "OK" set Dmax 503966 set Rmax 960165 set votes 7 set DRecSt [ 0 0 0 ] set RRecSt [ 1 1 1 ] set PctD 0.938686339951505 set PctR 0.617528237334208 set Dout 0 set Rout 1 ]
      if pycor = 13 [ set Abbr "OR" set Dmax 1037291 set Rmax 866831 set votes 7 set DRecSt [ 0 1 1 ] set RRecSt [ 1 0 0 ] set PctD 0.598977528967281 set PctR 0.548846314910288 set Dout 1 set Rout 0 ]
      if pycor = 12 [ set Abbr "PA" set Dmax 3276363 set Rmax 2970733 set votes 20 set DRecSt [ 0 0 1 ] set RRecSt [ 1 1 0 ] set PctD 0.683429766481919 set PctR 0.603164606176321 set Dout 1 set Rout 0 ]
      if pycor = 11 [ set Abbr "RI" set Dmax 296571 set Rmax 180543 set votes 4 set DRecSt [ 0 1 1 ] set RRecSt [ 1 0 0 ] set PctD 0.719227436263155 set PctR 0.728939920129831 set Dout 1 set Rout 0 ]
      if pycor = 10 [ set Abbr "SC" set Dmax 865941 set Rmax 1155389 set votes 9 set DRecSt [ 0 0 0 ] set RRecSt [ 1 1 1 ] set PctD 0.553749042948654 set PctR 0.499837716994017 set Dout 0 set Rout 1 ]
      if pycor = 9 [ set Abbr "SD" set Dmax 170924 set Rmax 232584 set votes 3 set DRecSt [ 0 0 0 ] set RRecSt [ 1 1 1 ] set PctD 0.730663920806908 set PctR 0.587822034189798 set Dout 0 set Rout 1 ]
      if pycor = 8 [ set Abbr "TN" set Dmax 1087437 set Rmax 1522925 set votes 11 set DRecSt [ 0 0 1 ] set RRecSt [ 1 1 0 ] set PctD 0.858459846409493 set PctR 0.552423789746705 set Dout 1 set Rout 0 ]
      if pycor = 7 [ set Abbr "TX" set Dmax 3877868 set Rmax 4685047 set votes 36 set DRecSt [ 0 0 0 ] set RRecSt [ 1 1 1 ] set PctD 0.588419977162709 set PctR 0.532773950826961 set Dout 0 set Rout 1 ]
      if pycor = 6 [ set Abbr "UT" set Dmax 327670 set Rmax 740600 set votes 6 set DRecSt [ 0 0 0 ] set RRecSt [ 1 1 1 ] set PctD 0.559797967467269 set PctR 0.435635970834459 set Dout 0 set Rout 1 ]
      if pycor = 5 [ set Abbr "VA" set Dmax 1981473 set Rmax 1822522 set votes 13 set DRecSt [ 0 0 0 ] set RRecSt [ 1 1 1 ] set PctD 0.524180748362456 set PctR 0.631277427652451 set Dout 0 set Rout 1 ]
      if pycor = 4 [ set Abbr "VT" set Dmax 219262 set Rmax 121180 set votes 3 set DRecSt [ 0 0 1 ] set RRecSt [ 1 1 0 ] set PctD 0.609280221835065 set PctR 0.727199207790064 set Dout 1 set Rout 0 ]
      if pycor = 3 [ set Abbr "WA" set Dmax 1755396 set Rmax 1304894 set votes 8 set DRecSt [ 0 0 1 ] set RRecSt [ 1 1 0 ] set PctD 0.565706541429968 set PctR 0.560378850695919 set Dout 1 set Rout 0 ]
      if pycor = 2 [ set Abbr "WI" set Dmax 1677211 set Rmax 1478120 set votes 10 set DRecSt [ 0 1 1 ] set RRecSt [ 1 0 0 ] set PctD 0.620712599666947 set PctR 0.629756041458068 set Dout 1 set Rout 0 ]
      if pycor = 1 [ set Abbr "WV" set Dmax 331001 set Rmax 489371 set votes 5 set DRecSt [ 0 1 1 ] set RRecSt [ 1 0 0 ] set PctD 1 set PctR 0.494459213970587 set Dout 1 set Rout 0 ]
      if pycor = 0 [ set Abbr "WY" set Dmax 82868 set Rmax 174419 set votes 3 set DRecSt [ 0 0 0 ] set RRecSt [ 1 1 1 ] set PctD 0.822512912101173 set PctR 0.454921768843991 set Dout 0 set Rout 1 ]
    ]
  ]
end 

;; import 1996-2016 state election outcomes to find model parameters with BehaviorSearch that best predict these outcomes

to valid-state
  ask patches [
   if pxcor = 0 [
      ;; set first column of states (AK–KS)
      if pycor = 16 [ set D9616 [ 0 0 0 0 0 0 ]  set Dpop9616 [ 80380 79004 111025 123594 122640 116454 ]  set Rpop9616 [ 122746 167398 190889 193841 164676 163387 ] ]
      if pycor = 15 [ set D9616 [ 0 0 0 0 0 0 ]  set Dpop9616 [ 662165 692611 693933 813479 795696 729547 ]  set Rpop9616 [ 769044 941173 1176394 1266546 1255925 1318255 ] ]
      if pycor = 14 [ set D9616 [ 1 0 0 0 0 0 ]  set Dpop9616 [ 475171 422768 469953 422310 394409 380494 ]  set Rpop9616 [ 325416 472940 572898 638017 647744 684872 ] ]
      if pycor = 13 [ set D9616 [ 1 0 0 0 0 0 ]  set Dpop9616 [ 653288 685341 893524 1034707 1025232 1161167 ]  set Rpop9616 [ 622073 781652 1104294 1230111 1233654 1252401 ] ]
      if pycor = 12 [ set D9616 [ 1 1 1 1 1 1 ]  set Dpop9616 [ 5119835 5861203 6745485 8274473 7854285 8753792 ]  set Rpop9616 [ 3828380 4567429 5509826 5011781 4839958 4483814 ] ]
      if pycor = 11 [ set D9616 [ 0 0 0 1 1 1 ]  set Dpop9616 [ 671152 738227 1001732 1288633 1323102 1338870 ]  set Rpop9616 [ 691848 883748 1101255 1073629 1185243 1202484 ] ]
      if pycor = 10 [ set D9616 [ 1 1 1 1 1 1 ]  set Dpop9616 [ 735740 816015 857488 997772 905083 897572 ]  set Rpop9616 [ 483109 561094 693826 629428 634892 673215 ] ]
      if pycor = 9 [ set D9616 [ 1 1 1 1 1 1 ]  set Dpop9616 [ 158220 171923 202970 245800 267070 282830 ]  set Rpop9616 [ 17339 18073 21256 17367 21381 12723 ] ]
      if pycor = 8 [ set D9616 [ 1 1 1 1 1 1 ]  set Dpop9616 [ 140355 180068 200152 255459 242584 235603 ]  set Rpop9616 [ 99062 137288 171660 152374 165484 185127 ] ]
      if pycor = 7 [ set D9616 [ 1 0 0 1 1 0 ]  set Dpop9616 [ 2546870 2912253 3583544 4282074 4237756 4504975 ]  set Rpop9616 [ 2244536 2912790 3964522 4045624 4163447 4617886 ] ]
      if pycor = 6 [ set D9616 [ 0 0 0 0 0 0 ]  set Dpop9616 [ 1053849 1116230 1366149 1844123 1773827 1877963 ]  set Rpop9616 [ 1080843 1419720 1914254 2048759 2078688 2089104 ] ]
      if pycor = 5 [ set D9616 [ 1 1 1 1 1 1 ]  set Dpop9616 [ 205012 205286 231708 325871 306658 266891 ]  set Rpop9616 [ 113943 137845 194191 120566 121015 128847 ] ]
      if pycor = 4 [ set D9616 [ 1 1 0 1 1 0 ]  set Dpop9616 [ 620258 638517 741898 828940 822544 653669 ]  set Rpop9616 [ 492644 634373 751957 682379 730617 800983 ] ]
      if pycor = 3 [ set D9616 [ 0 0 0 0 0 0 ]  set Dpop9616 [ 165443 138637 181098 236440 212787 189765 ]  set Rpop9616 [ 256595 336937 409235 403012 420911 409055 ] ]
      if pycor = 2 [ set D9616 [ 1 1 1 1 1 1 ]  set Dpop9616 [ 2341744 2589026 2891550 3419348 3019512 3090729 ]  set Rpop9616 [ 1587021 2019421 2345946 2031179 2135216 2146015 ] ]
      if pycor = 1 [ set D9616 [ 0 0 0 1 0 0 ]  set Dpop9616 [ 887424 901980 969011 1374039 1152887 1033126 ]  set Rpop9616 [ 1006693 1245836 1479438 1345648 1420543 1557286 ] ]
      if pycor = 0 [ set D9616 [ 0 0 0 0 0 0 ]  set Dpop9616 [ 387659 399276 434993 514765 440726 427005 ]  set Rpop9616 [ 583245 622332 736456 699655 692634 671018 ] ]
          ]
    if pxcor = 1 [
     ;; set second column of states (KY–NV)
      if pycor = 16 [ set D9616 [ 1 0 0 0 0 0 ]  set Dpop9616 [ 636614 638898 712733 751985 679370 628854 ]  set Rpop9616 [ 623283 872492 1069439 1048462 1087190 1202971 ] ]
      if pycor = 15 [ set D9616 [ 1 0 0 0 0 0 ]  set Dpop9616 [ 927837 792344 820299 782989 809141 780154 ]  set Rpop9616 [ 712586 927871 1102169 1148275 1152262 1178638 ] ]
      if pycor = 14 [ set D9616 [ 1 1 1 1 1 1 ]  set Dpop9616 [ 1571763 1616487 1803800 1904097 1921290 1995196 ]  set Rpop9616 [ 718107 878502 1071109 1108854 1188314 1090893 ] ]
      if pycor = 13 [ set D9616 [ 1 1 1 1 1 1 ]  set Dpop9616 [ 966207 1145782 1334493 1629467 1677844 1677928 ]  set Rpop9616 [ 681530 813797 1024703 959862 971869 943169 ] ]
      if pycor = 12 [ set D9616 [ 1 1 1 1 1 1 ]  set Dpop9616 [ 312788 319951 396842 421923 401306 357735 ]  set Rpop9616 [ 186378 286616 330201 295273 292276 335593 ] ]
      if pycor = 11 [ set D9616 [ 1 1 1 1 1 0 ]  set Dpop9616 [ 1989653 2170418 2479183 2872579 2564569 2268839 ]  set Rpop9616 [ 1481212 1953139 2313746 2048639 2115256 2279543 ] ]
      if pycor = 10 [ set D9616 [ 1 1 1 1 1 1 ]  set Dpop9616 [ 1120438 1168266 1445014 1573354 1546167 1367716 ]  set Rpop9616 [ 766476 1109659 1346695 1275409 1320225 1322951 ] ]
      if pycor = 9 [ set D9616 [ 1 0 0 0 0 0 ]  set Dpop9616 [ 1025935 1111138 1259171 1441911 1223796 1071068 ]  set Rpop9616 [ 890016 1189924 1455713 1445814 1482440 1594511 ] ]
      if pycor = 8 [ set D9616 [ 0 0 0 0 0 0 ]  set Dpop9616 [ 394022 404614 458094 554662 562949 485131 ]  set Rpop9616 [ 439838 572844 684981 724597 710746 700714 ] ]
      if pycor = 7 [ set D9616 [ 0 0 0 0 0 0 ]  set Dpop9616 [ 167922 137126 173710 231667 201839 177709 ]  set Rpop9616 [ 179652 240178 266063 242763 267928 279240 ] ]
      if pycor = 6 [ set D9616 [ 0 0 0 1 0 0 ]  set Dpop9616 [ 1107849 1257692 1525849 2142651 2178391 2189316 ]  set Rpop9616 [ 1225938 1631163 1961166 2128474 2270395 2362631 ] ]
      if pycor = 5 [ set D9616 [ 0 0 0 0 0 0 ]  set Dpop9616 [ 106905 95284 111052 141278 124827 93758 ]  set Rpop9616 [ 125050 174852 196651 168601 188163 216794 ] ]
      if pycor = 4 [ set D9616 [ 0 0 0 0 0 0 ]  set Dpop9616 [ 236761 231780 254328 333319 302081 284494 ]  set Rpop9616 [ 363467 433862 512814 452979 475064 495961 ] ]
      if pycor = 3 [ set D9616 [ 1 0 1 1 1 1 ]  set Dpop9616 [ 246214 266348 340511 384826 369561 348526 ]  set Rpop9616 [ 196532 273559 331237 316534 329918 345790 ] ]
      if pycor = 2 [ set D9616 [ 1 1 1 1 1 1 ]  set Dpop9616 [ 1652329 1788850 1911430 2215422 2125101 2148278 ]  set Rpop9616 [ 1103078 1284173 1670003 1613207 1477568 1601933 ] ]
      if pycor = 1 [ set D9616 [ 1 1 0 1 1 1 ]  set Dpop9616 [ 273495 286783 370942 472422 415335 385234 ]  set Rpop9616 [ 232751 286417 376930 346832 335788 319667 ] ]
      if pycor = 0 [ set D9616 [ 1 0 0 1 1 1 ]  set Dpop9616 [ 203974 279978 397190 533736 531373 539260 ]  set Rpop9616 [ 199244 301575 418690 412827 463567 512058 ] ]
          ]
    if pxcor = 2 [
      ;; set third row of states (NY–WY)
      if pycor = 16 [ set D9616 [ 1 1 1 1 1 1 ]  set Dpop9616 [ 3756177 3942215 4314280 4804945 4485741 4556118 ]  set Rpop9616 [ 1933492 2258577 2962567 2752771 2490431 2819533 ] ]
      if pycor = 15 [ set D9616 [ 1 0 0 1 1 0 ]  set Dpop9616 [ 2148222 2186190 2741167 2940044 2827709 2394164 ]  set Rpop9616 [ 1859883 2351209 2859768 2677820 2661437 2841005 ] ]
      if pycor = 14 [ set D9616 [ 0 0 0 0 0 0 ]  set Dpop9616 [ 488105 474276 503966 502496 443547 420375 ]  set Rpop9616 [ 582315 744337 959792 960165 891325 949136 ] ]
      if pycor = 13 [ set D9616 [ 1 1 1 1 1 1 ]  set Dpop9616 [ 649641 720342 943163 1037291 970488 1002106 ]  set Rpop9616 [ 538152 713577 866831 738475 754175 782403 ] ]
      if pycor = 12 [ set D9616 [ 1 1 1 1 1 0 ]  set Dpop9616 [ 2215819 2485967 2938095 3276363 2990274 2926441 ]  set Rpop9616 [ 1801169 2281127 2793847 2655885 2680434 2970733 ] ]
      if pycor = 11 [ set D9616 [ 1 1 1 1 1 1 ]  set Dpop9616 [ 233050 249508 259765 296571 279677 252525 ]  set Rpop9616 [ 104683 130555 169046 165391 157204 180543 ] ]
      if pycor = 10 [ set D9616 [ 0 0 0 0 0 0 ]  set Dpop9616 [ 506283 565561 661699 862449 865941 855373 ]  set Rpop9616 [ 573458 785937 937974 1034896 1071645 1155389 ] ]
      if pycor = 9 [ set D9616 [ 0 0 0 0 0 0 ]  set Dpop9616 [ 139333 118804 149244 170924 145039 117458 ]  set Rpop9616 [ 150543 190700 232584 203054 210610 227721 ] ]
      if pycor = 8 [ set D9616 [ 1 0 0 0 0 0 ]  set Dpop9616 [ 909146 981720 1036477 1087437 960709 870695 ]  set Rpop9616 [ 863530 1061949 1384375 1479178 1462330 1522925 ] ]
      if pycor = 7 [ set D9616 [ 0 0 0 0 0 0 ]  set Dpop9616 [ 2459683 2433746 2832704 3528633 3308124 3877868 ]  set Rpop9616 [ 2736167 3799639 4526917 4479328 4569843 4685047 ] ]
      if pycor = 6 [ set D9616 [ 0 0 0 0 0 0 ]  set Dpop9616 [ 221633 203053 241199 327670 251813 310676 ]  set Rpop9616 [ 361911 515096 663742 596030 740600 515231 ] ]
      if pycor = 5 [ set D9616 [ 0 0 0 1 1 1 ]  set Dpop9616 [ 1091060 1217290 1454742 1959532 1971820 1981473 ]  set Rpop9616 [ 1138350 1437490 1716959 1725005 1822522 1769443 ] ]
      if pycor = 4 [ set D9616 [ 1 1 1 1 1 1 ]  set Dpop9616 [ 137894 149022 184067 219262 199239 178573 ]  set Rpop9616 [ 80352 119775 121180 98974 92698 95369 ] ]
      if pycor = 3 [ set D9616 [ 1 1 1 1 1 1 ]  set Dpop9616 [ 1123323 1247652 1510201 1750848 1755396 1742718 ]  set Rpop9616 [ 840712 1108864 1304894 1229216 1290670 1221747 ] ]
      if pycor = 2 [ set D9616 [ 1 1 1 1 1 0 ]  set Dpop9616 [ 1071971 1242987 1489504 1677211 1620985 1382536 ]  set Rpop9616 [ 845029 1237279 1478120 1262393 1407966 1405284 ] ]
      if pycor = 1 [ set D9616 [ 1 0 0 0 0 0 ]  set Dpop9616 [ 327812 295497 326541 303857 238269 188794 ]  set Rpop9616 [ 233946 336475 423778 397466 417655 489371 ] ]
      if pycor = 0 [ set D9616 [ 0 0 0 0 0 0 ]  set Dpop9616 [ 77934 60481 70776 82868 69286 55973 ]  set Rpop9616 [ 105388 147947 167629 164958 170962 174419 ] ]
    ]
  ]
end 

;; import 1996-2016 general election outcomes to find model parameters with BehaviorSearch that best predict these outcomes

to valid-gen
  set D9616gen [ 1 0 0 1 1 0 ]
end 

;; PROC TO CALCULATE MODEL FIT: GENERAL OUTCOME + STATE OUTCOME

to model-fit
    ask patches [
    ;; boolean (1 or 0) for correctly predicting state outcome
    ifelse ( Dout = ( item ticks D9616 ) ) [
      set pfit 1 ] [
      set pfit 0 ]
    ;; mean of squared error between predicted and historical pular votes at state level
    set popfit ( sqrt ( ( Dpopout - ( item ticks Dpop9616 ) ) ^ 2 ) / 510
               + sqrt ( ( Rpopout - ( item ticks Rpop9616 ) ) ^ 2 ) / 510 )
    ]
  ;; each general election outcome that concords with historical record adds 1000 to model fit
  if ( DCur = ( item ticks D9616gen ) ) [
      set globalfit globalfit + 1000 ]

  ;; each state election outcome that concords with historical record adds 1 to model fit
  set globalfit globalfit + sum [pfit] of patches

  ;; running total of sum of mean squared error between predicted and historical pular votes at state level
  set globalpopfit globalpopfit + sum [popfit] of patches
end 

There are 6 versions of this model.

Uploaded by When Description Download
Joe Wasserman about 6 years ago Fixed bug that allowed voters to go negative in some instances Download this version
Joe Wasserman about 6 years ago Added info to Info pane Download this version
Joe Wasserman about 6 years ago Removed decimals from all reporters Download this version
Joe Wasserman about 6 years ago Added additional parameters to hopefully increase model fidelity Download this version
Joe Wasserman about 6 years ago Fixed typos in info Download this version
Joe Wasserman about 6 years ago Initial upload Download this version

Attached files

File Type Description Last updated
Reactive voters model v1.0.png preview Reactive voters preview about 6 years ago, by Joe Wasserman Download

This model does not have any ancestors.

This model does not have any descendants.