Spatial-Social Interactions

Spatial-Social Interactions preview image

1 collaborator

Default-person Sean Dougherty (Author)


(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by the author
Model was written in NetLogo 6.0.1 • Viewed 121 times • Downloaded 7 times • Run 0 times
Download the 'Spatial-Social Interactions' modelDownload this modelEmbed this model

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


Social networks have a geographic distribution that may be distinct from the geographic distribution of news events that are shared among that network. As a result people can be exposed to events at a much higher frequency than would otherwise occur locally to them.

This model is motivated by the potential for future technology in freight transportation to alter the public reaction to accidents. There are currently ~11 fatalties per day in the United States resulting from large truck accidents. News stories for these events appear predominantly in the news of rural areas and rarely in metro areas since truck accidents are generally distributed across road miles instead of being distributed with the population. Changes in truck technology and social media sharing of these local events could increase the reaction to these incidents.

An even more extreme difference between event and population distribution can be tested using the Shark Attack environment.


The environment is modeled in three components. The events take place on black patches ("eventspace"). Urban areas appear in orange patches, and rural areas are indicated in green. People are only spawned into the urban and rural areas. All other patches are ignored.

People respond to events that take place on black patches within a selectable news-range along with events shared with them by their social networks. Those events are uniformly distributed over the black patches with average of event-frequency events per tick. Each time a person sees an event their level of concern increases by the event-severity. With every tick their concern level is decreased in accordance with the attention span as well.

Social networks can be configured by several different methods depending on what aspects of the social network are interesting to test.

Based on their level of concern people may also react to events:

  • If a person's concern level exceeds their concern threshold, they will share a local event with their outbound links. These people are shown in red. They remain passive about events that took place elsewhere.

  • If their concern level exceeds their active threshold, they will share events they see regardless of being local or not. These people are displayed in yellow. When they are actively sharing a news story their links will flash yellow.


Use the Setup button to set the population and network. Click on Go Once to run the model one "day" or Go to run it continuously. The Reset-concern button will reset all of the people, charts, and ticks but keep the existing network.

All settings on the left column above the setup button only apply before setup and will not impact the model if changed between ticks.

The environment can either be the heavy freight transportation network or a map of shark attacks across the United States.

Use num-people to set how many people to simulate. Urban-ratio splits how people are spawned between urban and rural locations with 1.0 meaning all people spawn into urban locations.

The network-mode has the following options:

  • Random networks are constructed among random people within the link distance. This option is best to mimic word of mouth in short distances. Number of followers is distributed by the Poisson distribution with a uniform number followed at the selected number in the interface. This can easily create disconnected geographic regions.

  • Scale-free networks randomly connect followers to influential people regardless of distance, but includes distance in preferences to linking to less influential people. Number followed is uniform at the selected number in the interface, and power-law for the followers.

  • Small World builds a lattice network in a loop with selectable rewiring ratio in the interface. These networks have uniform distribution of connections with no rewiring and normally distributed with many rewirings.

  • Triangles uses the Friends-of-Friends approach with a fully connected core of links with followers that also form "triangles" with friends. These links are non-directional. This network type aims to generate the clustering aspects of Facebook social network. The links tend to follow normal distributions unlike the other options and much higher clustering.

  • The Dual Scale-free network connects directionally with both followers and followed in power law relationships. Influential links are preferrentially made bidirectional, and additional links are also built between influential nodes. This was proposed as a way to mimic the Twitter network.

Except for Triangle networks, link-distance controls how the social network is built. Distance influences how close of links the network tries to build in pixels (roughly 8.4 km per pixel). Very long distance settings result in networks that are not built in regard to geographic distance while short settings will prefer short link distances.

The remaining settings can be changed between ticks:

Stop-at-mean-concern will shut the model down at a pre-set mean level of concern to simplify tick-based experiments.

Event-frequency establishes how many total events on average occur per tick across all of the environment. Event-severity is how much concern each event adds to the people. News-range configures how big of a geographic area hears about a local event.

Concern-threshold, Active-threshold, and concern-cap all control how people respond to their concern level. The concern-cap limits the total amount of concern a person can have. By making the concern-cap below either the active or concern thresholds you can prevent people from triggering these states. Attention-span sets how quickly concern decays for people. Low numbers are very rapid decay of concern, and high numbers are very slow decay with 10 disabling the feature. Move-in-range takes relocates all people so they are within range of a location they can directly see an event.

Two display toggles are available. The link display can be toggled to be able to examine the created network with the link-toggle button. The tiny-toggle button changes the people shape between large and tiny sizes which may make links and other patterns easier to see.

The layout button removes the geographic network and orders the network by the links. In the case of more than one follower per person, this could just be a tight ball. Click the undo-layout button to return to the model run.

The first column of plots: two plots provide information on the distribution of concern and the mean concern across all people split by urban (orange) and rural (green). The last plot is a time-series of the count of each population of concern (red) and active (yellow) over the ticks.

In the second column of plots there are two static histograms of the connectivity of the network. In the first the distribution of link lengths of the network is shown, and in the second the number of out-bound links for each person is shown. These can be used to confirm the construction of the network.The final histogram shows the distribution of number of events seen by each person.


  • Social networks with short distance links mimic word-of-mouth. Information moves slowly and can get stuck in local areas. Rural areas tend to have limited impact in these cases until the network is highly active.

  • With attention spans in use, it's very possible to have long periods of mild concern levels that seem stable until a sudden onset of active sharing occurs without a change in any settings. This is very sensitive to network configuration and an event being visible to influential people (lots of followers).

  • Showing the layout of the social network at the end of a run reveals patterns in concern that differ from the geography. Geographic neighbors can have very different concern levels and sharing activity.


  • Check out the shark attack data set to see interactions between coastal and inshore areas. How many news stories will the people of Omaha see?

  • Try networks with low activation thresholds but short attention spans. They'll share anything they see, but not stay concerned for long. This might be useful for panic types of events.

  • If you are using attention spans, try comparing the event frequency or severities which are necessary to activate the social media network to the setting which is necessary to quiet it.

  • Check out the different social networks for how their behavior differs. Some have an even rate of increase in concern, while others slowly increase until a rapid onset. The Triangle and Dual Scale Free networks correspond better to intuition with attention spans in use.


The black patches could represent anything geographically distinct from population distribution which produces information that travels across a social network. This seems possibly useful for other interactions like natural disasters and other infrastructure like electricity grids.

The split of urban and rural is not rigorously modeled. A better way to distribute people across these categories and their social network structures might improve the correspondence to reality. The method of color coding urban areas scaled to population isn't ideal either. In the NYC area some people may be isolated from observing any events because they end up signficantly offshore artificially. Some urban areas also overlap. A heatmap might work better, but introduces its own issues.

The agents are only mildly responsive to their environment and all operate with the same rules and thresholds. They are also perfectly perceptive and don't exaust on the issue unlike what happens in the real world.

The events having a single magnitude doesn't represent the real world well. Some shark attacks are just surf boards being bitten and others are fatalities.


import-pcolors is the most exotic element used in this ABM. This configures the environment and corrals the turtles to particular spawning locations.


Language Diffusion inspired the network approach. Grand Canyon inspired the approach to handle the geographic elements. Preferrential Attachment heavily informed the scale-free network approach, and Small World heavily informed the small world approach.


Thanks to the anonymous reviewers of Complexity Explorer for their valuable feedback to improve this model.

Scalefree Network and Small World Implementations heavily borrowed from Uri Wilensky. Friends of Friends implemented based on the model proposed by Allen Downey. The dual preferrential attachment is inspired by the Aparicio, Villzon-Terrazas, and Alvarez (2015) model of the Twitter network as published in the journal Entropy.

GIS Data:

Comments and Questions

Ask about nodes & links (Question)

How many nodes and links can be loaded on Netlogo? I try to load shp file which contains about 70000 nodes, and it always shows error on the output.

Posted about 1 month ago

Ask about nodes & links (Question)

How many nodes and links can be loaded on Netlogo? I try to load shp file which contains about 70000 nodes, and it always shows error on the output.

Posted about 1 month ago

Shape Files and the Model

I'm not familiar with the node count limits in NetLogo. I had the most success converting SHP data into a PNG image file though in terms of processing times for iterations and flexibility.

Posted about 1 month ago

Click to Run Model

;;   Spatial-Social Interactions

breed       [ people person ]     ;; the agents that interact with the environment
breed       [ events event ]      ;; turtles used to highlight where the environment has an event
patches-own [ urban               ;; this patch is an urban spot
              rural               ;; this patch is rural
              eventspace          ;; this patch is eventspace (an event can occur here)
              event-number ]      ;; the event number which has happened
people-own  [ concern             ;; the concern level of the person
              sharing             ;; whether or not they are sharing an event (1 = sharing this tick, 2 = sharing next tick)
              sharing-event       ;; the event number they are sharing
              shared-events-list  ;; the list of recent events they have shared - prevents runaway feedback loops
              home-patch          ;; the original patch so the person can go home after a "layout"
              shares              ;; the number of times this person has shared a story
              events-seen ]       ;; the number of events this person has seen (regardless of concern level)
globals     [ decay               ;; how much concern levels decay per tick
              count-eventspace    ;; number of eventspace patches
              link-state          ;; whether or not the link button has been toggled
              event-counter ]     ;; a running count of how many events to create event-numbers
extensions  [ rnd ]               ;; use this extension for weighted selection

to startup
  ;; This is really for it to be pretty, since we have to reload it following the clear-all

to setup
  ;; reset the event couunter
  set event-counter 1

  ;; load in the transportation network to preload patches

  ;; Sprout people in the urban spaces
  ask n-of ((urban-ratio) * num-people) patches with [urban and not eventspace]  [
    sprout-people 1 [ prepare-person set home-patch patch-here ]

  ;; Sprout people in the rural spaces
  ask n-of ((1 - urban-ratio) * num-people) patches with [rural and not eventspace]  [
    sprout-people 1 [ prepare-person set home-patch patch-here ]

  ;; now let's make the network
  if any? people [ make-network ]

  ;; hide the links
  ask links [ hide-link ]
  set link-state false


to go
  ;; calculate an exponential factor from the attention-span in case the user changed it
  ;; 10 = no decay, otherwise do use an exponential decay amount to make this respond somewhat linearly
  ifelse attention-span = 10 [ set decay 1 ] [set decay 1 - 10 ^ (- (attention-span ^ 0.5))]

  ;; clear out the old event markers since they are old news
  ask events [ die ]

  ;; Let's go ahead and trigger events in some of the cells
  ask patches with [eventspace] [
    ;; reset the incidents from the last tick back to normal
    if pcolor = cyan [ set pcolor black ]
    ;; trigger patches randomly to have a news event... uniform probability per eventspace patch
    if random-float 1.0 < event-freq / count-eventspace [
      ;; set the event number for this patch and increment the counter
      set event-number event-counter
      set event-counter event-counter + 1
      ;; set the patch color to show an event occured here
      set pcolor cyan

  ;; Since the people are cycled through in an order we need to do two passes so people can
  ;; react to local shares, and then react to the other people.

  ;; First pass - Set sharing for people who finished the last tick with an event to share. Also react to
  ;; local events.
  ask people [
    ;; if they ended the last tick in active sharing state, they are now sharing that story in this tick,
    ;; even without a local event. set them sharing normally, and make their links grey
    ifelse sharing = 2 [ set sharing 1 ask my-out-links [set color grey ]]
      ;; otherwise just clear the sharing out in case they shared normally last tick
      [set sharing 0 set sharing-event 0 ]

    ;; create their newspaper from local events, and then update their status if there are any events
    let newspaper [event-number] of patches in-radius news-range with [pcolor = cyan]
    ;; we pass handle-news false so that it knows it's getting a local newspaper
    handle-news newspaper false

  ;; Second pass - People react to the remote events shared to them
  ask people [
    ;; if someone in their network has shared it with them, they see it and are concerned
    if sum [sharing] of in-link-neighbors > 0 [
      ;; let's check to make sure we haven't seen this news story before. Get the list of events being shared to us.
      let event-list [sharing-event] of in-link-neighbors with [sharing > 0]
      ;; we pass handle-news true so that it knows it's getting a shared event-list
      handle-news event-list true
    ;; Clean up - If there is any concern, decay it, threshold it, and update the status
    if concern > 0 [
      set concern concern * decay
      if concern < concern-threshold [ set color blue ]
      if concern > active-threshold  [ set color yellow ]
      if concern > concern-cap [ set concern concern-cap ]

  ;; Now create visual indicators for events that have happened so they can be found on the
  ;; display (since patches are just one pixel)
  ask patches with [ pcolor = cyan ] [
    sprout-events 1 [
      ;; make the display a circle the size of the news-range
      set shape "circle"
      set size news-range
      set color cyan


  ;; if we've hit the stopping criteria, stop.
  if any? people [ if mean [concern] of people > stop-at-mean-concern [ stop ] ]

;; this makes an existing person into a fresh new one, but preserves their network

to prepare-person
  set shape "person"
  set color blue
  set concern initial-concern
  set size 10
  set shared-events-list []
  set shares 0
  set events-seen 0

;; this takes care of picking an event we haven't responded to before and setting up the sharing

to handle-news [ event-list secondary-mode ]
  ;; find one event that hasn't been shared with us.
  let this-event find-not-in-list event-list shared-events-list
  ;; if we got an event number back, that means we haven't seen that event before
  if this-event > 0 [
    ;; make us more concerned
    set concern concern + event-severity
    set events-seen events-seen + 1
    ;; add it to our list
    set shared-events-list lput this-event shared-events-list
    ;; keep our memory limited to the last 20 news stories. old news may reverberate around the network but
    ;; maybe that's realistic if there are long cycles in it.
    if length shared-events-list > 20 [
      set shared-events-list but-first shared-events-list
    ifelse not secondary-mode [
      ;; if this is an event in my area, we just set sharing
      if concern > concern-threshold or concern > active-threshold [
        set sharing 1
        set sharing-event this-event
        set shares shares + 1
    ] [
      ;; for events that weren't local but were shared to them...
      ;; if they are concerned, they will share the remote event with their network
      if concern > active-threshold [
        ;; set sharing to 2 so we know in the next round to handle this sharing. News can only move one
        ;; link length per tick.
        set sharing 2
        set sharing-event this-event
        ;; increment the sharing count for this person
        set shares shares + 1
        ;; make the active sharers show their links to make it obvious the span of the remote sharing
        ask my-out-links [show-link set color yellow ]
        ;; make it so the link display toggle button knows there are links showing
        set link-state true

;; this is used to search for new news by finding is a newspaper has news (needle-list)
;; they haven't seen before (haystack)

to-report find-not-in-list [needle-list haystack]
  foreach needle-list [
    needle -> if not member? needle haystack [ report needle ]
  report 0

;; if the user wants to keep the network but do another run of the model...

to reset-concern
  ;; have the people reset
  ask people [
  ;; hide any links that were showing for active sharers
  ask links [ hide-link ]

  ;; clear all the plots and reset the ticks so it's like a new run

;; this toggles the display of the links for convenience

to link-toggle
  ifelse link-state [ set link-state false ask links [hide-link] ]
                    [ set link-state true  ask links [show-link] ]

;; load up the environment into the patches and handle missing files

to load-environment
  let filename ""
  ;; if the files exist let's use them
  if geography-type = "freight-network"    [ set filename "transport dataset.png" ]
  if geography-type = "shark-attack-data"  [ set filename "shark dataset.png" ]
  ifelse file-exists? filename [
    import-pcolors filename
  ] [
    user-message "The graphics file for the map couldn't be found. Please check to make sure you extracted them from the ZIP file and placed them in the same directory."
  ;; set up some colors the PNG files use when imported
  let color-rural 56.8
  let color-urban 25
  let color-eventspace 1
  ;; Have the patches set some properties based on their colors for easy logic checks
  ask patches [
    set rural      pcolor = color-rural
    set urban      pcolor = color-urban
    set eventspace pcolor <= color-eventspace
  ;; give the eventspace patches a location property for analysis purposes
  ask patches with [ eventspace ] [
    ifelse count patches in-radius 4 with [ urban ] > count patches in-radius 4 with [ rural ] [ set urban true ] [ set rural true ]
  ;; Count how many eventspace patches we have to scale the event frequency to the size of the map
  set count-eventspace count patches with [eventspace]

;; allows the user to flip the size of the people so the icons aren't as distracting

to tiny-toggle
  ifelse [size] of one-of people = 1
    [ask people [ set size 10 ]]
    [ask people [ set size 1 ]]

;; create the social network

to make-network
  if num-followed > 0 [
    if network-mode = "random-network" [
      ask people [
        ;; create random links within the distance found
        create-links-from n-of num-followed find-nearby false
    if network-mode = "scale-free" [
    if network-mode = "small-world" [
    if network-mode = "triangles" [
    if network-mode = "dual-scale-free" [

to make-scale-free
  ;; preferrential attachment using Uri's netlogo lottery method. Depending on settings,
  ;; it will prefer local links.

  ;; use a boolean for speed in the loop

  ;; create one link to get the lottery started
  if num-followed > 0 and count links = 0 [ ask one-of people [ create-link-from one-of other people ] ]
  ;; begin the lottery!
  ask people [
    ;; create links to other people with probability of how many people they are linked to
    repeat num-followed [
      let candidate self
      ;; find a turtle that isn't me
      while [candidate = self] [
        ;; conduct the lottery
        set candidate find-scale-free
        ;; if the turtle who is possibly anywhere only has 1 link and is not local,
        ;; find a local link instead.
        if ([count my-out-links] of candidate <= 1 and distance candidate > link-distance ) [
          set candidate one-of find-nearby false
      create-link-from candidate

;; this implements Uri's method of building a scale-free network in NetLogo

to-report find-scale-free
  report [one-of both-ends] of one-of links

;; this is used during setup to find nearby people to connect to, making sure it's as least as big as the number to follow

to-report find-nearby [ one-link-only ]
  ;; have a variable ready to expand the scope of the search if we don't find enough links
  let focus 0
  ;; a place to store the agentset between runs so we can simply report it if the set is big enough
  let searchset no-turtles
  ;; until we find an agentset of at least count of required links, keep expanding the search radius
  loop [
    ifelse one-link-only
      [ set searchset other people with [ count my-in-links = 0 ] in-radius (link-distance + focus) ]
      [ set searchset other people in-radius (link-distance + focus) ]
    ifelse count searchset < num-followed [
      ;; we didn't find enough people, so we'll just expand the search area next time
      set focus focus + link-distance
      ;; we've got a big enough set, simply report it.
      report searchset

to make-twitter
  ;; inspired by
  ;; has 4 different preferential attachment types that are formed probabilistically until
  ;; all of the people have a link

  ;; these are weights, not probabilities
  ;; first, the types proposed by the authors
  let pw 1.0   ;; new node created as followed
  let qw 2.0   ;; new node created as a follower   (they recommend q

let rw 0.5 ;; add links between existing nodes (similar to rewires in smallworld) ;; this one I'm adding in because the network above has very low bidirectional links unless the weight ;; for r is enormous (they appear to have chosen equivalents of pw=1 and rw=30 roughly) let sw 1.0 ;; influential nodes follow other influential nodes that follow them ;; rebalance the weights into probabilities let tot pw + qw + sw + rw let p pw / tot let q qw / tot let r rw / tot let s sw / tot ;; make one link so the preferrential attachment doesn't fail if not any? links [ ask one-of people [ create-link-from one-of other people ] ] while [ count people with [ count my-links = 0 ] > 0 ] [ let rand random-float 1.0 if ( rand <= p ) [ ;; new node as followed let followed one-of people with [ count my-links = 0 ] ask one-of links [ let follower one-of both-ends ask follower [ create-link-from followed ] ] ] if ( rand <= p + q and rand > p ) [ ;; new node as follower let follower one-of people with [ count my-links = 0 ] ask one-of links [ let followed one-of both-ends ask follower [ create-link-from followed ] ] ] if ( rand <= p + q + s and rand > p + q ) [ ;; make a link bidirectional let candidate nobody ;; we need to find a link that isn't already bidirectional let attempts 0 ;; let's try 10 times to find one that isn't bidirectional before we give up while [candidate = nobody and attempts < 10 ] [ ;; selected a link weighted against the count of links the end points have set candidate rnd:weighted-one-of links [ count [my-links] of end1 + count [my-links] of end2 ] if (link [who] of [end2] of candidate [who] of [end1] of candidate != nobody) [ set candidate nobody ] set attempts attempts + 1 ] ;; if we found someone if candidate != nobody [ ask candidate [ ;; create a reversed link let far-end end2 ask end1 [ create-link-from far-end ] ] ] ] if ( rand > p + q + s ) [ ;; existing node as follower of another existing node ask one-of links [ let follower one-of both-ends let followed follower while [ follower = followed ] [ ask one-of links [ set followed one-of both-ends ] ] ask follower [ create-link-from followed ] ] ] ] end ;; make a small-world network taking into account the distance settings to make-small-world ;; This is a little complicated, but it makes a big lattice loop out of the people with link distances ;; based on the UI setting. With long distances it acts geographically random, and with short ;; distances it snakes around the country in a loop from neighbor to neighbor. let current-person one-of people let person-list [] let everyone-set people ;; where there are still people to link while [ count everyone-set > 0 ] [ ;; starting point for distance search let focus 0 ;; make our candidate list empty let candidate-set no-turtles ;; while the candidate list is empty while [count candidate-set = 0 ] [ ;; find candidates that are within the link range set candidate-set everyone-set with [ distance current-person < link-distance + focus ] ;; in case we didn't find any, increase the search distance set focus focus + link-distance ] ;; now pick a random one out of the candidate list let next-person one-of candidate-set ;; take that person out of the everyone list because they are taken care of set everyone-set everyone-set with [ self != next-person ] ;; put that onto the ordered person-list for order of linkage set person-list lput next-person person-list ;; make the next person the current person for the loop set current-person next-person ] ;; borrows heavily from Uri's implementation from here on let n 0 while [n < length person-list ] [ ;; create 2 legs to each has 2 in and 2 out connections. ;; with a small ratio of rewirings the loop is unlikely to ;; be severed or cut people out of the network. let lattice-legs 2 ;; have a counter to step down list let lattice 1 repeat lattice-legs [ make-edge item n person-list item ((n + lattice) mod length person-list) person-list set lattice lattice + 1 ] set n n + 1 ] ;; now rewire to the user specification let potential-edges links if any? potential-edges [ ask n-of (rewire-ratio * count potential-edges) potential-edges [ ;; "a" remains the same let node1 end1 ;; if "a" is not connected to everybody if [ count link-neighbors ] of end1 < (count people - 1) [ ;; find a node distinct from node1 and not already a neighbor of node1 let node2 one-of people with [ (self != node1) and (not link-neighbor? node1) ] ;; wire the new edge ask node1 [ create-link-from node2 ] ;; remove the old edge die ] ] ] end ;; this implements Uri's method of rewiring small world networks, modified for directed links to make-edge [node1 node2] ask node1 [ create-link-from node2 ] end ;; this implements Allen Downey's Friends of Friends network as an example of a ;; "triangle" network to boost clustering. Unlike the other networks here, ;; this is non-directional like Facebook. to make-friends-of-friends ;; let m count people ;; make the core a subset of the total, scaled here to the population let n log m 10 * 10 let p 0.10 ;; make the fully connected core ;; randomly select people to make up the core let core n-of n people ask core [ let node1 self ask other core [ create-link-with node1 ] ] ;; walk through each and make links to every other ;; the people that don't have links are the "others" let others people with [ count my-links = 0 ] ;; now make the triangles ask others [ let link-target one-of core let link-from self let friends [link-neighbors] of link-target ask friends [ if ( random-float 1.0 < p ) [ let fof link-neighbors ask link-from [ create-link-with one-of fof with [ self != link-from ] ] ] ] create-link-with link-target ] end

There is only one version of this model, created 4 months ago by Sean Dougherty.

Attached files

File Type Description Last updated
shark dataset.png png Shark Attack Dataset Supporting File 4 months ago, by Sean Dougherty Download
Spatial-Social Interactions.png preview Preview for 'Spatial-Social Interactions' 4 months ago, by Sean Dougherty Download
transport dataset.png png Transportation Dataset Supporting File 4 months ago, by Sean Dougherty Download

This model does not have any ancestors.

This model does not have any descendants.