;; Team Assembly ;; Grouping turtles ;; Friend group ties undirected-link-breed [ friend-group-links friend-group-link ] globals [ ;;;;;;;;;;;;;;;;;;;;;; ;; Global variables ;; ;;;;;;;;;;;;;;;;;;;;;; friend-group-size N-friend-groups friend-group-ID ;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Used to read csv files ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;; csv_data number_of_people ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Variables related to time management ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; current.year current.episode ;; one of the three interaction episodes: for interaction with peers, for social media usage, for government campaigns interaction.episode ;; the one we are currently at weeks days current.day actual.gamma.gov ;; decay function of government effect ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Coefficients employed in the individiual decision-making process ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Social media and government opinion variables ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; gamma.social.media ;; social media influence stance on a given topic gamma.gov ;; government stance gamma.gov.knowledge ;; government trying to educate people ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Used to monitor and report data about number of items bought ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ff.price.index ;; this should be an average price per item tzero.mean.ff.p.consume ;; likelihood of consuming at the beginning of the simulation ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Agents' variables associated with the family group and outside friends ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Variables related to cycle campaigns ticks-since-last-change current-cycle ;; These are the variances that can be saved if necessary variance.attribute.1 variance.attribute.2 variance.attribute.3 variance.attribute.4 variance.p.take-action ] turtles-own [ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Characteristics of the agents ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; friend-group-member? ;; A flag to mark those agents that are part of a friend group agent-friend-group-ID ;; Their friend group ID ag.serial ag.sex ;; Suggested: 1=Female, 2=Male ag.age ;; Suggested: 0.2= 18-24, 0.4= 25-34; 0.6= 35-44; 0.8= 45-54; 1= 55+ ag.income ;; Suggested: 0.15: <1000, 0.3: 1001-1499, 0.45: 1500-2000, 0.60: 2000-2999, 0.75: 3000-4999, 0.9: 5000+ ag.education ;; Suggested: 0.2: primary education, 0.4: secondary education, 0.6: associate degree, 0.8: undergraduate degree, 1: graduate degree ag.attribute.1 ;; range: [0,1] ag.attribute.2 ;; range: [0,1] ag.attribute.3 ;; range: [0,1] ag.attribute.4 ;; range: [0,1] ;; TO ADD MORE ATTRIBUTES ;;;;;;;;;;;;;;;;;;;; ;; ag.attribute.5 ;; ;; uncomment as many as you need here ;; ag.attribute.6 ;; ;; .............. ;; ;; ag.attribute.n ;; ;;;;;;;;;;;;;;;;;;;; ag.p.take-action ;; agent's probability to take action ;; attributes setup during each simulation, static ag.peer-susceptibility.alpha ;; Personal susceptibility towards other people ( personal influence is just 1 - susceptability) ag.social-media.alpha ;; Susceptability towards social media ag.gov-influence.alpha ;; Susceptability towards government campaigns behavior.take-action ;; dichotomous variable ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Agent's variables related to fashion purchases choices and fast fashion attituted ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ] friend-group-links-own [ link-friend-group-ID ;; Identify the link among members of the same friend group friend-group-bridge? ;; Flag that identifies whether a link is a bridge to an agent outside of the friend group ] ;;;;;;;;;;;;;;;;; ;; World setup ;; ;;;;;;;;;;;;;;;;; ;; General setup of the model to setup clear-all clear-output ;; Close all files from last run file-close-all reset-ticks ;; Fix the seed to vary the results of the simulation (THIS IS FOR LATER) if (seed?) [random-seed new-seed] if (file-exists? "Average_attributes.txt" = TRUE) [file-delete "Average_attributes.txt"] if (file-exists? "Individual_attributes.txt" = TRUE) [file-delete "Individual_attributes.txt"] if (file-exists? "Variances.txt" = TRUE) [file-delete "Variances.txt"] ;; Read data from csv file and initialize agent's basic variables create-people ;; Initialize parameters for the decision-making model (from linear regression) init-parameters ;; Initialize additional agents' variables setup-population ;; Create friend groups create-friend-groups ;; Create the visualization build-layout ask links [set color white] ;; links within a friend group are colored white ask links with [friend-group-bridge? = TRUE] [set color cyan set thickness 0.01] ;; links with agents outside the friend group are colored cyan ;; Initialize time variables ;; Initialise time and episode variables set weeks 1 set days 1 set current.day "" set interaction.episode 2 set current.episode "" define-current.phase.of.day define-current.day.of.week define-current.year ;; setup cycle for government campaigns. The number of cycles depends on the number of attributes the government is influencing. set current-cycle 1 ;; Initialize the likelihood of taking the action (using the lin regression equation) ask turtles [set ag.p.take-action est-prob] update-visual end ;;;;;;;;;;;;;;;;;;;;;;;;; ;; BUILD VISUALIZATION ;; ;;;;;;;;;;;;;;;;;;;;;;;;; ;; Arrange agent's in open/circle networks per family ;; the "Simple" layout hides links, while the "Cirle" layout shows links. ;; If you have many agents and would like to be able to click on a turtle to see its attributes from the plot, we suggest using the "Simple" layout. to build-layout if ((layout? = "Simple")) [ ask friend-group-links [set hidden? TRUE] ask turtles [set size 1] ask turtles [set label ""] ] if ((layout? = "Cirle")) [ ask friend-group-links [set hidden? FALSE set color red] ask friend-group-links with [friend-group-bridge?] [ set hidden? FALSE set color cyan] ask turtles [set size 1] ifelse (Labels?) [ ask turtles [ set label agent-friend-group-ID set label-color white]] [ ask turtles [ set label ""]] layout-circle sort turtles max-pxcor - 1 ] end to update-visual ask turtles [ set shape "person" set size 0.1 set heading 0 ;; set xy based on agent's concerns and prob to buy fast fashion. Agents are plotted based on the chosen attribute on the x-axis and the probability to take action in the y-axis if plot.x.axis = "Attribute.1" [ setxy ( ag.attribute.1 ) ( ag.p.take-action ) ;; let my.ag.to-inf ag.attribute.1 ;;let locals friend-group-link-neighbors ;; let negative.locals (locals with [abs(ag.attribute.1 - my.ag.to-inf ) > tolerance.threshold]) ;;repeat (count negative.locals [ ;; let ;; ] ] if plot.x.axis = "Attribute.2" [ setxy ( ag.attribute.2 ) ( ag.p.take-action ) ] if plot.x.axis = "Attribute.3" [ setxy ( ag.attribute.3 ) ( ag.p.take-action ) ] if plot.x.axis = "Attribute.4" [ setxy ( ag.attribute.4 ) ( ag.p.take-action ) ] ;; TO ADD MORE ATTRIBUTES ;; if plot.x.axis = "Attribute.5" [ ;; setxy ( ag.attribute.5 ) ( ag.p.take-action ) ;; ;;] ;; You will need to add it as an option in chooser of "plot.x.axis" in the interface section update-colours ] end ;; agents are color-coded based on their probability to take the action. ;; For "Opt.1", we set the color to red if the probability is higher than 0.7, to yellow if it is between 0.4 and 0.7, and to lime if it is below 0.4. ;; For "Opt.2", we set the color to lime if the probability is higher than 0.7, to yellow if it is between 0.4 and 0.7, and to red if it is below 0.4. to update-colours if Colours? = "Opt.1" [ if (ag.p.take-action <= 0.4) [set color lime] if ((ag.p.take-action >= 0.4) AND ((ag.p.take-action) <= 0.7)) [set color yellow] if (ag.p.take-action > 0.7) [set color red] ] if Colours? = "Opt.2" [ if (ag.p.take-action <= 0.4) [set color red] if ((ag.p.take-action >= 0.4) AND ((ag.p.take-action) <= 0.7)) [set color yellow] if (ag.p.take-action > 0.7) [set color lime] ] end ;; Initialize agents' by reading input database or generating the data randomly to create-people if Data? = "random" [ let %count 0 while [%count <= num_agents] [ set %count %count + 1 ;; create one person based on each row in the csv file until the final line - which is empty create-turtles 1 [ set ag.serial %count set ag.sex (random(2)) set ag.age (random(5) + 1) / 5 ;; 5 age categories set ag.income (random(5) + 1) / 5 ;; here we will have 5 income categories set ag.education (random(5) + 1) / 5 ;; 5 education categories set ag.attribute.1 (random(50) + 1) / 50 ;; we will have random values ranging from 0 to 1 in 0.02 increments. Adjust the value 50 for more or less increments set ag.attribute.2 (random(50) + 1) / 50 set ag.attribute.3 (random(50) + 1) / 50 set ag.attribute.4 (random(50) + 1) / 50 ;; TO ADD MORE ATTRIBUTES ;; set.ag.attribute.5 (random(50) + 1) / 50 ] set number_of_people %count ] ] if Data? = "file" [ set csv_data "your_file.csv" file-open csv_data let %count 0 ;; Assuming first line contains header let %header file-read-line ;; Import data until the end of the file while [%count <= num_agents] [ set %count %count + 1 let %case file-read-line set %case word %case "," let %data.list [] ;; create one person based on each row in the csv file until the final line - which is empty create-turtles 1 [ while [not empty? %case] [ let %pos position "," %case let %item read-from-string substring %case 0 %pos set %data.list lput %item %data.list set %case substring %case (%pos + 1) length %case ] ;; Make sure that the order aligns with the order of your data in the csv file set ag.serial item 0 %data.list set ag.sex item 1 %data.list set ag.age item 2 %data.list set ag.income item 3 %data.list set ag.education item 4 %data.list set ag.attribute.1 item 5 %data.list set ag.attribute.2 item 6 %data.list set ag.attribute.3 item 7 %data.list set ag.attribute.4 item 8 %data.list set ag.p.take-action item 9 %data.list ;; not nececessary because it will be recalculated with the to est-prob function ;; TO ADD MORE ATTRIBUTES ;; set.ag.attribute.5 item x %data.list ] set number_of_people %count ] file-close ] end ;;;;;;;;;;;;;;;;;;;;;;;;; ;; Setup friend groups ;; ;;;;;;;;;;;;;;;;;;;;;;;;; ;; Create friend groups to create-friend-groups ;; Setup variables set N-friend-groups 0 ;; while there are turtles with no friend group, keep creating friend groups while [count turtles with [friend-group-member? = 0] > 0] [create-a-friend-group] ;; this function connect turtles with other turtles in friend groups other than their own connect-friend-groups ;; making sure that the flag for friend group brigde is initiated for all links ask friend-group-links with [friend-group-bridge? != TRUE] [set friend-group-bridge? FALSE] end to create-a-friend-group ;; reset the agentset to zero let a-friend-group nobody ;; update counter of friend groups in the simulation set N-friend-groups N-friend-groups + 1 ;; the following routine creates a distribution of friend groups set friend-group-size friend.group.size;; adult per friend group, which is set by the user in the interface window ;; ask to those agents who are not engaged in a friend group to be part of an agentset ;; but before check if there is enough free agents to build a friend group ;; otherwise set friend group size equal to free agents if friend-group-size > (count turtles with [(friend-group-member? = 0)]) [ set friend-group-size (count turtles with [(friend-group-member? = 0)]) ] repeat friend-group-size [ let a-member nobody let potential-members turtles with [friend-group-member? = 0] set a-member max-one-of potential-members [ag.p.take-action] ask a-member [ set friend-group-member? true set agent-friend-group-ID N-friend-groups set label agent-friend-group-ID set label-color white ] set a-friend-group (turtle-set a-friend-group a-member) ] ;; create connections among the friend group members ;; If agent-set = 1, no friend group links are created, but it counts as 1 friend group ask a-friend-group ;; calling agents of the agent set [ create-friend-group-links-with other a-friend-group ;; calling links between agents [ set thickness (0.005) set color white ;; identify friend-group links from the others applying a label set link-friend-group-ID N-friend-groups set label-color white ] ] end ;; this function connects agents with other agents randomly to connect-friend-groups let i 1 while [i < N-friend-groups] [ let t-size count turtles with [agent-friend-group-ID = i] ask N-of t-size turtles with [agent-friend-group-ID = i] [ let m 1 while [m <= outside.friends.num] [ ;; Connect with a random agent of another team let out-friend-group-agent one-of other turtles with [agent-friend-group-ID != i] create-friend-group-link-with out-friend-group-agent ask friend-group-link-with out-friend-group-agent [ set friend-group-bridge? TRUE set color cyan ] set m m + 1 ] ] set i i + 1 ] end ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Setup additional variables related to agents ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; to setup-population ask turtles [ set color grey ;; setup susceptability towards other peers in the friend group set ag.peer-susceptibility.alpha 0 + precision(random-float 1)3 if ag.peer-susceptibility.alpha < 0.1 [set ag.peer-susceptibility.alpha 0.1] if ag.peer-susceptibility.alpha > .90 [set ag.peer-susceptibility.alpha 0.90] ;; setup susceptability towards social media set ag.social-media.alpha 0 + precision(random-float 1)3 if ag.social-media.alpha < 0.1 [set ag.social-media.alpha 0.1] if ag.social-media.alpha > .90 [set ag.social-media.alpha 0.90] ;; setup susceptibility towards government campaigns set ag.gov-influence.alpha 0 + precision(random-float 1)3 if ag.gov-influence.alpha < 0.1 [set ag.gov-influence.alpha 0.1] if ag.gov-influence.alpha > .90 [set ag.gov-influence.alpha 0.90] ] end ;; Initialize parameters of the decision making process at the beginning of the simulation to init-parameters set b0 0.3 ;; constant set b1 0.1 ;; sex set b2 -0.15 ;; age set b3 0.08 ;; income set b4 -0.12 ;; education set b5 0.18 ;; attribute 1 set b6 -0.05 ;; attribute 2 set b7 0.09 ;; attribute 3 set b8 0.14 ;; attribute 4 ;; TO ADD MORE ATTRIBUTES ;; set b9 x ;; attribute 5 end ;; Report probability to purchase fast fashion based on the linear regression function. to-report est-prob let y (b0 + (b1 * ag.sex) + (b2 * ag.age) + (b3 * ag.income) + (b4 * ag.education ) + (b5 * ag.attribute.1) + (b6 * ag.attribute.2) + (b7 * ag.attribute.3) + (b8 * ag.attribute.4) ) ;; TO ADD MORE ATTRIBUTES ;; add another coefficient times the attribute to the decision making function report y end ;;;;;;;;;;;;;;;;;;;;; ;; Time management ;; ;;;;;;;;;;;;;;;;;;;;; ;; Report the interaction episode to define-current.phase.of.day ifelse (interaction.episode = 3) [ set current.episode "Government campaigns"] [ ifelse (interaction.episode = 2) [ set current.episode "Social media" ] [ set current.episode "Peers" ] ] end ;;Report the day of the week in words to define-current.day.of.week if (days mod 7) = 0 [ set current.day "Sunday" ] if (days mod 7) = 1 [ set current.day "Monday" ] if (days mod 7) = 2 [ set current.day "Tuesday" ] if (days mod 7) = 3 [ set current.day "Wednesday" ] if (days mod 7) = 4 [ set current.day "Thursday" ] if (days mod 7) = 5 [ set current.day "Friday" ] if (days mod 7) = 6 [ set current.day "Saturday" ] end ;; Change year every 365 days to define-current.year ifelse days >= 731 [set current.year 2019] [ifelse days >= 366 [set current.year 2018] [set current.year 2017]] end ;;;;;;;;;;;;;;;;;;;; ;; RUN SIMULATION ;; ;;;;;;;;;;;;;;;;;;;; ;; Stop simulation after the set number of ticks to go if ticks >= num_ticks [stop] set ticks-since-last-change ticks-since-last-change + 1 ;; this is for the case of cyclic campaigns if ticks-since-last-change > length.cycle [select-new-cycle] ;; Define the phase of the current day. There are three phases: for interaction with friends, for social media, and for government campaign. define-current.phase.of.day ;; Increase number of weeks by one on Monday morning ;; Increase number of days after by one after all three phases have happened ;; Reset the phases to 1 to start from 1 the next tick. if interaction.episode = 4 [ if (days mod 7 = 0) [ set weeks weeks + 1 ;; Every 7 days 1 week passes ] set days days + 1 ;; Every 3 phases 1 day passes set interaction.episode 1 ;; Reset to the first phase. ] ;; Ask agent to interact with one of the three infuencing factors. This is the main function that begins the interaction with government, social media, or peers. interaction-episode ;; update the plot update-visual wait 0.1 ;; wait to make sure the plot is updated. Otherwise might lag. define-current.day.of.week define-current.year set interaction.episode interaction.episode + 1 find-variances ;; Here is the code that can be uncommented to save the data. Notice that the files are erased at the beginning of every simulation in the setup. Uncomment the lines to save the files. Otherwise no data will be saved if (ticks mod 5 = 0) ;; save the average attributes every five ticks [ ;;save-average-attributes ;;save-variances ] if (ticks = 1) or (ticks = round (num_ticks / 2) ) or (ticks = (num_ticks - 1 )) [ ;;save-individual-attributes ] tick end ;; Ask agent to interact with one of the three factors based on the phase of the day to interaction-episode ;; We can choose to isolate an influence or to have them all. This is set by the user. ;; everything stands for all influences acting if influence? = "Everything" [ ;; agetns interact with peer at every time step deterministically if interaction.episode = 1 [ peer-interaction ] ;; Social media usage if interaction.episode = 2 [ social-media-manage-function ] ;; Government campaigns if interaction.episode = 3 [ ;; we can set to have both social media and peer pressure but no campaigns. This is set up to find a baseline model, where no policies are implemented. if campaigns.type != "None" [ government-campaigns ] ] ] ;; This is the code that runs when we want to isolate and study just one influence if influence? = "Peer influence" [ if interaction.episode = 1 [peer-interaction] ] if influence? = "Social media" [ if interaction.episode = 2 [social-media-manage-function] ] if influence? = "Government" [ if interaction.episode = 3 [ if campaigns.type != "None" [government-campaigns] ] ] ;; Call this function to estimate behavior and update probability of taking an action estimate-behavior end ;; This next function will be called after each interaction to update agent's probability of taking the action and to check the bahevior to estimate-behavior ask turtles [ set behavior.take-action 0 set ag.p.take-action est-prob let random.p precision(random-float 1)3 ;; If the probability of buying fast fashion is higher than this random float, then the agent will buy. This can be adjusted as necessary. if (ag.p.take-action > random.p) [ set behavior.take-action 1 ] ] end ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; SOCIAL MEDIA AS AN EXTERNAL INFLUENCE ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Here are all the functions associated with social media influence to social-media-manage-function ;; this function decides what topic the agent will be influenced on. By default, we have 4 attributes to affect, so we select one randomly let value.inf 0 ;; TO ADD MORE ATTRIBUTES ;; right now it is set up to 4 attributes. If you add more, change the number "4" to the number of your attributes set value.inf random 4 + 1 if value.inf = 1 ;; attribute.1 is influenced [ ask turtles [ set ag.attribute.1 (social-media-general-function ag.attribute.1) ;; call the function that will carry on the influencing ] ] if value.inf = 2 ;; attribute.2 will be influenced [ ask turtles [ set ag.attribute.2 (social-media-general-function ag.attribute.2) ] ] if value.inf = 3 ;; attribute.3 will be influenced [ ask turtles [ set ag.attribute.3 (social-media-general-function ag.attribute.3) ] ] if value.inf = 4 ;; attribute.4 will be influenced [ ask turtles [ set ag.attribute.4 (social-media-general-function ag.attribute.4) ] ] ;; TO ADD MORE ATTRIBUTES ;; if value.inf = 5 ;; attribute.5 will be influenced ;; [ ;; ask turtles [ ;; set ag.attribute.5 (social-media-general-function ag.attribute.5) ;; ] ;; ] end ;; this function takes agent's current view as an input and returns the updated view after the influence to-report social-media-general-function [to-inf] if to-inf < polarization.threshold or to-inf > (1 - polarization.threshold) [ ;; this is set up for the function on the next line to be more simple let b 0 set b ( ag.social-media.alpha * 50 ) ;; the opinion the function will be influencing the agent towards set gamma.social.media ( ( b * (to-inf ) ^ 3 ) - ( 3 * b * (to-inf) ^ 2 )/ 2 + (3 * b * to-inf) / 4 + (1 / 2) - (b / 8 ) + social.media.bias ) ;; function I derived and its on the slides if gamma.social.media > 1 [ set gamma.social.media 1 ] ;; if it is larger than 1 (because with this function, it could be), we set it to 1 if gamma.social.media < 0 [ set gamma.social.media 0.1 ] ;; similar for when it is less then 0 ;; this is for the next function to simplify the sintax let diff.view 0 set diff.view abs(to-inf - gamma.social.media ) ;; here we are calculating the new value of the attribute based on the social media "opinion" and the susceptibility fo the agent. set to-inf ( (1 - ag.social-media.alpha) * (e ^ (ag.social-media.alpha * diff.view) ) * to-inf + ag.social-media.alpha * (e ^( - (1 - ag.social-media.alpha) * diff.view ) ) * gamma.social.media ) ;; in case it is too large or too small, we manually reset it to be within the admissible range. if to-inf <= 0.05 [set to-inf 0.05] if to-inf >= 1 [set to-inf 0.95] ] report to-inf end ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; GOVERNMENT AS AN EXTERNAL INFLUENCE ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; to government-campaigns let value-of-ad current-cycle if campaigns.type = "Cycle" [ ;; When this option is chosen, the government has campaigns for different topics every certain number of ticks. The user has to choose the length of the cycle as well ;; There are four types of campaigns because we have four attributes by default (this can be adjusted) ;; in this case, we go from cycle 1 to cycle 2,3,4 and then start with 1 again. set value-of-ad current-cycle ] if campaigns.type = "random" [ ;; When we have random campaigns, we assume that people just bump into advertisement, campaigns, etc. We select a random attribute at each time step ;; TO ADD MORE ATTRIBUTES ;; Change the number "4" to your current number of attributes set value-of-ad random 4 + 1 ] ;; Recall that we need to have the average opinion of the entire agentset and the opinion of the agent if value-of-ad = 1 ;; cycle 1 stands attribute.1 [ ask turtles [ let average.opinion.attribute.1 mean [ag.attribute.1] of turtles set ag.attribute.1 (gov-influence-general-function ag.attribute.1 average.opinion.attribute.1) ] ] if value-of-ad = 2 ;; cycle 2 stands attribute.2 [ ask turtles [ let average.opinion.attribute.2 mean [ag.attribute.2] of turtles set ag.attribute.2 (gov-influence-general-function ag.attribute.2 average.opinion.attribute.2) ] ] if value-of-ad = 3 ;; cycle 3 stands attribute.3 [ ask turtles [ let average.opinion.attribute.3 mean [ag.attribute.3] of turtles set ag.attribute.3 (gov-influence-general-function ag.attribute.3 average.opinion.attribute.3) ] ] if value-of-ad = 4 ;; cycle 4 stands attribute.4 [ ask turtles [ let average.opinion.attribute.4 mean [ag.attribute.4] of turtles set ag.attribute.4 (gov-influence-general-function ag.attribute.4 average.opinion.attribute.4) ] ] ;; TO ADD MORE ATTRIBUTES ;;if value-of-ad = 5 ;; cycle 5 stands attribute.5 ;; [ ;; ask turtles [ ;; let average.opinion.attribute.5 mean [ag.attribute.5] of turtles ;; set ag.attribute.5 (gov-influence-general-function ag.attribute.5 average.opinion.attribute.5) ;; ] ;; ] end to select-new-cycle let new-cycle current-cycle while [new-cycle = current-cycle] [ ;; TO ADD MORE ATTRIBUTES ;; Change the number "4" to your current number of attributes set new-cycle random 4 + 1 ] set current-cycle new-cycle ; Reset the ticks since the last change set ticks-since-last-change 0 end ;; to-inf stands for the attribute we are aiming to influence to-report gov-influence-general-function [to-inf average.opinion] ;; here the government acts with probability 50%, but this can be adjusted as necessary. If the influencing does not happen, we report the same value back let random.p (precision(random-float 1)2 ) if (0.5 < random.p) [ ;; this is the opinion that the government will be reporting set gamma.gov (average.opinion * government.goals) ;; we assume there is a decay overtime of susceptibility to governmental influence. If this line is erased, the susceptibility is static. let ag.gov-influence.alpha.updated (ag.gov-influence.alpha * (e ^ (-0.0125 * weeks))) ;; these two lines are added for simplicity of sintax let diff.view 0 set diff.view abs( to-inf - gamma.gov ) ;; this line generates agent's updated opinion on a topic set to-inf ( (1 - ag.gov-influence.alpha.updated) * (e ^( ag.gov-influence.alpha.updated * diff.view) ) * to-inf + ag.gov-influence.alpha.updated * (e ^ ( - (1 - ag.gov-influence.alpha.updated) * diff.view ) ) * gamma.gov ) ;; reset manually of too low or too large if to-inf <= 0.05 [set to-inf 0.05] if to-inf >= 1 [set to-inf 0.95] ] report to-inf end ;;;;;;;;;;;;;;;;;;;; ;; PEER INFLUENCE ;; ;;;;;;;;;;;;;;;;;;;; to peer-interaction ;; we want the agent to interact with some of its friends, not necessarily all of them. Idially, with those it has stronger ties, but for now we can just choose randomly. ask turtles [ let friend.locals friend-group-link-neighbors if count friend.locals > 3 [ let randomF random 7 - 3 let friendsToLocalCount count friend.locals ;; we select the number of friends set by the user +- 1 to 4 friends to assure variability let friendsCountThreshold min list friendsToLocalCount (socialization.beta + randomF) let friends.locals.random n-of friendsCountThreshold friend.locals ;; once the agentset to be interacted with is selected, we call the peer influence function that will decide what topic friends will interact about peer-influence-manage-function (friends.locals.random) ] ] end ;; Here is a function that will decide on what topic the agents will interact to peer-influence-manage-function [temp.locals] ;; TO ADD MORE ATTRIBUTES ;; Change number "4" to your number of attributes let random.p random 4 + 1 if random.p = 1 [ set ag.attribute.1 (peer-influence temp.locals ag.attribute.1) ] if random.p = 2 [ set ag.attribute.2 (peer-influence temp.locals ag.attribute.2) ] if random.p = 3 [ set ag.attribute.3 (peer-influence temp.locals ag.attribute.3) ] if random.p = 4 [ set ag.attribute.4 (peer-influence temp.locals ag.attribute.4) ] ;; if random.p = 5 [ set ag.attribute.5 (peer-influence-env temp.locals ag.attribute.5) ] end to-report peer-pressure [locals to-inf] if society? = "Not polarized" [ set to-inf (non-polarizing locals to-inf) ] if society? = "Polarized" [ set to-inf (polarizing locals to-inf) ] if society? = "Non polarized to polarized" [ ifelse ticks < change.at [ set to-inf (non-polarizing locals to-inf) ] [ set to-inf (polarizing locals to-inf) ] ] if society? = "Polarized to non polarized" [ ifelse ticks < change.at [ set to-inf (polarizing locals to-inf) ] [ set to-inf (non-polarizing locals to-inf) ] ] report to-inf end to-report peer-influence [locals to-inf] ;; Here I define those that can affect an agent let temp.alpha 0 set temp.alpha ag.peer-susceptibility.alpha let my.agent.to-inf 0 set my.agent.to-inf to-inf ;; Individual concern of the agent weighted for personal factor alpha let ag.ind.to-inf.concern (1 - temp.alpha) * to-inf ;; Take into account the opinion of locals whose influence is larger than the agent's own influence, and disregard the rest (or whose susceptibility is smaller -> same thing) ;; count the number of agents more influential than me. This is done to find whether I have influential friends at all. If not, we skip the peer influencing. let count-of-agents-influencing count locals with [ag.peer-susceptibility.alpha < [ag.peer-susceptibility.alpha] of myself] if count-of-agents-influencing > 0 [ ;; take all my neighbors and find those highly concerned. If sharing.info.threshold=0.5, then this takes all of them let friends.who.care (locals with [to-inf > (1 - sharing.threshold) or to-inf < sharing.threshold]) ;; find those more influential than me from the highly concerned ones let num.friends.who.care count (friends.who.care with [ag.peer-susceptibility.alpha < [ag.peer-susceptibility.alpha] of myself]) let num.friends count-of-agents-influencing ;; for simplicity ;; in case we have a polarized society, we want to separate those agents who are similar enough in opinion, and those who are too far in opinion because the former ;; will have a homogenizing effect, while the later - polarizing if society? = "Polarized" [ ;; we have friends with opinion similar to mine let friends.too.far (friends.who.care with [abs(to-inf - my.agent.to-inf) >= tolerance.threshold]) ;; and those with a different opinion. If polatization.society = 0.5, then the friend.too.far is everyone and friends.close enough is empty. let friends.close.enough (friends.who.care with [abs(to-inf - my.agent.to-inf) <= tolerance.threshold]) ;; if an agent has at least one friend who cares if num.friends.who.care > 0 [ ;; we separate the influence into two categories: those than homogenize and those that polarize let friends.opinion.to-inf.positive ( sum [to-inf ] of friends.close.enough with [ag.peer-susceptibility.alpha < [ag.peer-susceptibility.alpha] of myself] ) let friends.opinion.to-inf.negative ( sum [to-inf] of friends.too.far with [ag.peer-susceptibility.alpha < [ag.peer-susceptibility.alpha] of myself] ) ;; here we calculate the overall opinion of friends, combining the homogenizing and the polarizing let friends.opinion.to-inf (( ( ag.peer-susceptibility.alpha) * (friends.opinion.to-inf.positive + (count(friends.too.far) - friends.opinion.to-inf.negative)) ) / num.friends.who.care ) ;; behavior in case of polarized agentset. let friends.behavior.positive ( sum [ag.p.take-action] of friends.close.enough with [ag.peer-susceptibility.alpha < [ag.peer-susceptibility.alpha] of myself] ) let friends.behavior.negative ( sum [ag.p.take-action] of friends.too.far with [ag.peer-susceptibility.alpha < [ag.peer-susceptibility.alpha] of myself] ) ;; user can choose to have the behavior to be polarizing or not. If yes, it will be calculated the same way as their opinion. Otherwise, behavior is homogenizing if behavior.polarization = "yes" [ let friends.behavior (((ag.peer-susceptibility.alpha) * (friends.behavior.positive + (count(friends.too.far) - friends.behavior.negative))) / num.friends.who.care) set to-inf (ag.ind.to-inf.concern + (friends.opinion.to-inf / 3) + (2 * friends.behavior / 3) ) ] if behavior.polarization = "no" [ let friends.behavior (((ag.peer-susceptibility.alpha) * (friends.behavior.positive + friends.behavior.negative)) / num.friends.who.care) set to-inf (ag.ind.to-inf.concern + (friends.opinion.to-inf / 3) + (2 * friends.behavior / 3) ) ] ] ] ;; in case we have a non polarized agentset, both the opinion and behavior of more influential and concerned friends is homogenizing if society? = "Not polarized" [ if num.friends.who.care > 0 [ let friends.opinion.to-inf ( (ag.peer-susceptibility.alpha) * (sum [to-inf] of friends.who.care with [ag.peer-susceptibility.alpha < [ag.peer-susceptibility.alpha] of myself]) ) / num.friends.who.care let friends.behavior ( (ag.peer-susceptibility.alpha) * (sum [ag.p.take-action] of friends.who.care with [ag.peer-susceptibility.alpha < [ag.peer-susceptibility.alpha] of myself]) ) / num.friends.who.care set to-inf (ag.ind.to-inf.concern + (friends.opinion.to-inf / 3) + (2 * friends.behavior / 3) ) ] ] ] ;; manually reset if out of bu=ounds if to-inf <= 0.05 [set to-inf 0.05] if to-inf >= 1 [set to-inf 0.95] report to-inf end to-report polarizing [locals to-inf] let temp.alpha 0 set temp.alpha ag.peer-susceptibility.alpha let my.agent.to-inf 0 set my.agent.to-inf to-inf ;; Individual concern of the agent weighted for personal factor alpha let ag.ind.to-inf.concern (1 - temp.alpha) * to-inf ;; Take into account the opinion of locals whose influence is larger than the agent's own influence, and disregard the rest (or whose susceptibility is smaller -> same thing) ;; count the number of agents more influential than me. This is done to find whether I have influential friends at all. If not, we skip the peer influencing. let count-of-agents-influencing count locals with [ag.peer-susceptibility.alpha < [ag.peer-susceptibility.alpha] of myself] if count-of-agents-influencing > 0 [ ;; take all my neighbors and find those highly concerned. If sharing.info.threshold=0.5, then this takes all of them let friends.who.care (locals with [to-inf > (1 - sharing.threshold) or to-inf < sharing.threshold]) ;; find those more influential than me from the highly concerned ones let num.friends.who.care count (friends.who.care with [ag.peer-susceptibility.alpha < [ag.peer-susceptibility.alpha] of myself]) let num.friends count-of-agents-influencing ;; for simplicity ;; in case we have a polarized society, we want to separate those agents who are similar enough in opinion, and those who are too far in opinion because the former ;; will have a homogenizing effect, while the later - polarizing ;; we have friends with opinion similar to mine let friends.too.far (friends.who.care with [abs(to-inf - my.agent.to-inf) >= tolerance.threshold]) ;; and those with a different opinion. If polatization.society = 0.5, then the friend.too.far is everyone and friends.close enough is empty. let friends.close.enough (friends.who.care with [abs(to-inf - my.agent.to-inf) <= tolerance.threshold]) ;; if an agent has at least one friend who cares if num.friends.who.care > 0 [ ;; we separate the influence into two categories: those than homogenize and those that polarize let friends.opinion.to-inf.positive ( sum [to-inf ] of friends.close.enough with [ag.peer-susceptibility.alpha < [ag.peer-susceptibility.alpha] of myself] ) let friends.opinion.to-inf.negative ( sum [to-inf] of friends.too.far with [ag.peer-susceptibility.alpha < [ag.peer-susceptibility.alpha] of myself] ) ;; here we calculate the overall opinion of friends, combining the homogenizing and the polarizing let friends.opinion.to-inf (( ( ag.peer-susceptibility.alpha) * (friends.opinion.to-inf.positive + (count(friends.too.far) - friends.opinion.to-inf.negative)) ) / num.friends.who.care ) ;; behavior in case of polarized agentset. let friends.behavior.positive ( sum [ag.p.take-action] of friends.close.enough with [ag.peer-susceptibility.alpha < [ag.peer-susceptibility.alpha] of myself] ) let friends.behavior.negative ( sum [ag.p.take-action] of friends.too.far with [ag.peer-susceptibility.alpha < [ag.peer-susceptibility.alpha] of myself] ) ;; user can choose to have the behavior to be polarizing or not. If yes, it will be calculated the same way as their opinion. Otherwise, behavior is homogenizing if behavior.polarization = "yes" [ let friends.behavior (((ag.peer-susceptibility.alpha) * (friends.behavior.positive + (count(friends.too.far) - friends.behavior.negative))) / num.friends.who.care) set to-inf (ag.ind.to-inf.concern + (friends.opinion.to-inf / 3) + (2 * friends.behavior / 3) ) ] if behavior.polarization = "no" [ let friends.behavior (((ag.peer-susceptibility.alpha) * (friends.behavior.positive + friends.behavior.negative)) / num.friends.who.care) set to-inf (ag.ind.to-inf.concern + (friends.opinion.to-inf / 3) + (2 * friends.behavior / 3) ) ] ] ] ;; manually reset if out of bu=ounds if to-inf <= 0.05 [set to-inf 0.05] if to-inf >= 1 [set to-inf 0.95] report to-inf end to-report non-polarizing [locals to-inf] ;; Here I define those that can affect an agent let temp.alpha 0 set temp.alpha ag.peer-susceptibility.alpha let my.agent.to-inf 0 set my.agent.to-inf to-inf ;; Individual concern of the agent weighted for personal factor alpha let ag.ind.to-inf.concern (1 - temp.alpha) * to-inf ;; Take into account the opinion of locals whose influence is larger than the agent's own influence, and disregard the rest (or whose susceptibility is smaller -> same thing) ;; count the number of agents more influential than me. This is done to find whether I have influential friends at all. If not, we skip the peer influencing. let count-of-agents-influencing count locals with [ag.peer-susceptibility.alpha < [ag.peer-susceptibility.alpha] of myself] if count-of-agents-influencing > 0 [ ;; take all my neighbors and find those highly concerned. If sharing.info.threshold=0.5, then this takes all of them let friends.who.care (locals with [to-inf > (1 - sharing.threshold) or to-inf < sharing.threshold]) ;; find those more influential than me from the highly concerned ones let num.friends.who.care count (friends.who.care with [ag.peer-susceptibility.alpha < [ag.peer-susceptibility.alpha] of myself]) let num.friends count-of-agents-influencing ;; for simplicity if num.friends.who.care > 0 [ let friends.opinion.to-inf ( (ag.peer-susceptibility.alpha) * (sum [to-inf] of friends.who.care with [ag.peer-susceptibility.alpha < [ag.peer-susceptibility.alpha] of myself]) ) / num.friends.who.care let friends.behavior ( (ag.peer-susceptibility.alpha) * (sum [ag.p.take-action] of friends.who.care with [ag.peer-susceptibility.alpha < [ag.peer-susceptibility.alpha] of myself]) ) / num.friends.who.care set to-inf (ag.ind.to-inf.concern + (friends.opinion.to-inf / 3) + (2 * friends.behavior / 3) ) ] ] ;; manually reset if out of bu=ounds if to-inf <= 0.05 [set to-inf 0.05] if to-inf >= 1 [set to-inf 0.95] report to-inf end ;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Code to save updates ;; ;;;;;;;;;;;;;;;;;;;;;;;;;; ;; This function saves the average values of the attributes of the entire agentset. to save-average-attributes if (file-exists? "Average_attributes.txt" != TRUE) [ file-open "Average_attributes.txt" file-write ( list "ticks" "ag.avg.attribute.1" "ag.avg.attribute.2" "ag.avg.attribute.3" "ag.avg.attribute.4" "ag.avg.prob.take-action" ) file-print "" ] file-open "Average_attributes.txt" file-write ticks file-write mean [ag.attribute.1] of turtles file-write mean [ag.attribute.2] of turtles file-write mean [ag.attribute.3] of turtles file-write mean [ag.attribute.4] of turtles file-write mean [ag.p.take-action] of turtles file-print "" file-close end to save-individual-attributes if (file-exists? "Individual_attributes.txt" != TRUE) [ file-open "Individual_attributes.txt" file-write ( list "ag.serial" "ag.attribute.1" "ag.attribute.2" "ag.attribute.3" "ag.attribute.4" "ag.p.take-action" ) file-print "" ] file-open "Individual_attributes.txt" ask turtles[ file-write ag.serial file-write ag.attribute.1 file-write ag.attribute.2 file-write ag.attribute.3 file-write ag.attribute.4 file-write ag.p.take-action file-print "" ] file-close end to save-variances if (file-exists? "Variances.txt" != TRUE) [ file-open "Variances.txt" file-write ( list "ticks" "variance.env" "variance.work-awn" "variance.knowledge" "variance.p.fast-fashion" ) file-print "" ] file-open "Variances.txt" file-write ticks file-write variance.attribute.1 file-write variance.attribute.2 file-write variance.attribute.3 file-write variance.attribute.4 file-write variance.p.take-action file-print "" file-close end to find-variances let mean.value.attribute.1 (mean [ag.attribute.1] of turtles) let variance.sum.attribute.1 0 let mean.value.attribute.2 (mean [ag.attribute.2] of turtles) let variance.sum.attribute.2 0 let mean.value.attribute.3 (mean [ag.attribute.3] of turtles) let variance.sum.attribute.3 0 let mean.value.attribute.4 (mean [ag.attribute.4] of turtles) let variance.sum.attribute.4 0 let mean.value.p.take-action (mean [ag.p.take-action] of turtles) let variance.sum.p.take-action 0 ask turtles [ set variance.sum.attribute.1 ( (find-difference ag.attribute.1 mean.value.attribute.1) + variance.sum.attribute.1 ) set variance.sum.attribute.2 ( (find-difference ag.attribute.2 mean.value.attribute.2) + variance.sum.attribute.2 ) set variance.sum.attribute.3 ( (find-difference ag.attribute.3 mean.value.attribute.3) + variance.sum.attribute.3 ) set variance.sum.attribute.4 ( (find-difference ag.attribute.4 mean.value.attribute.4) + variance.sum.attribute.4 ) set variance.sum.p.take-action ( (find-difference ag.p.take-action mean.value.p.take-action) + variance.sum.p.take-action ) ] set variance.attribute.1 ( variance.sum.attribute.1 / num_agents ) set variance.attribute.2 ( variance.sum.attribute.2 / num_agents ) set variance.attribute.3 ( variance.sum.attribute.3 / num_agents ) set variance.attribute.4 ( variance.sum.attribute.4 / num_agents ) set variance.p.take-action ( variance.sum.p.take-action / num_agents ) end to-report find-difference [value mean.value ] let diff (value - mean.value) ^ 2 report diff end @#$#@#$#@ GRAPHICS-WINDOW 477 143 914 581 -1 -1 214.5 1 10 1 1 1 0 1 1 1 0 1 0 1 0 0 1 ticks 30.0 BUTTON 20 26 86 59 NIL setup\n NIL 1 T OBSERVER NIL NIL NIL NIL 1 CHOOSER 19 70 157 115 Colours? Colours? "Opt.1" "Opt.2" 1 CHOOSER 174 70 312 115 layout? layout? "Simple" "Circle" 1 SWITCH 671 27 774 60 Labels? Labels? 0 1 -1000 BUTTON 103 27 166 60 Go go\n T 1 T OBSERVER NIL NIL NIL NIL 1 PLOT 921 141 1341 580 Changes in attributes NIL NIL 0.0 1.0 0.0 1.0 true true "" "" PENS "avg.attribute.1" 1.0 0 -13840069 true "" "if ticks > 0 [plot mean [ag.attribute.1] of turtles]" "avg.attribute.2" 1.0 0 -13791810 true "" "if ticks > 0 [plot mean [ag.attribute.2] of turtles]" "avg.p.take-action" 1.0 0 -955883 true "" "if ticks > 0 [plot mean [ag.p.take-action] of turtles]" "avg.attribute.3" 1.0 0 -4699768 true "" "if ticks > 0 [plot mean [ag.attribute.3] of turtles]" "avg.attributte.4" 1.0 0 -8990512 true "" "if ticks > 0 [plot mean [ag.attribute.4] of turtles]" SLIDER 18 421 190 454 socialization.beta socialization.beta round(outside.friends.num * 0.2) outside.friends.num 10.0 1 1 NIL HORIZONTAL SLIDER 183 27 355 60 num_agents num_agents 24 1050 495.0 1 1 NIL HORIZONTAL SLIDER 20 170 192 203 government.goals government.goals 0.5 1.5 1.5 0.1 1 NIL HORIZONTAL SLIDER 365 27 537 60 num_ticks num_ticks 0 550 550.0 5 1 NIL HORIZONTAL CHOOSER 20 210 190 255 campaigns.type campaigns.type "Cycle" "random" "None" 2 SLIDER 20 261 192 294 length.cycle length.cycle 10 30 30.0 1 1 NIL HORIZONTAL CHOOSER 333 70 471 115 influence? influence? "Everything" "Peer influence" "Social media" "Government" 0 CHOOSER 773 95 911 140 plot.x.axis plot.x.axis "Attribute.1" "Attribute.2" "Attribute.3" "Attribute.4" 1 SLIDER 18 382 190 415 friend.group.size friend.group.size 5 15 5.0 1 1 NIL HORIZONTAL SLIDER 18 340 191 373 outside.friends.num outside.friends.num 10 50 10.0 1 1 NIL HORIZONTAL SLIDER 250 396 459 429 polarization.threshold polarization.threshold 0 0.5 0.5 0.05 1 NIL HORIZONTAL SLIDER 16 465 190 498 sharing.threshold sharing.threshold 0 0.5 0.5 0.05 1 NIL HORIZONTAL CHOOSER 253 168 465 213 society? society? "Polarized" "Not polarized" "Non polarized to polarized" "Polarized to non polarized" 0 SLIDER 251 267 464 300 tolerance.threshold tolerance.threshold 0.05 0.5 0.05 0.05 1 NIL HORIZONTAL CHOOSER 251 310 463 355 behavior.polarization behavior.polarization "yes" "no" 1 SWITCH 553 27 656 60 seed? seed? 0 1 -1000 CHOOSER 489 69 627 114 Data? Data? "random" "file" 0 TEXTBOX 22 149 172 167 Government settings\n 11 0.0 1 TEXTBOX 253 138 403 166 Polarized agentset \nand tolerance threshold\n 11 0.0 1 TEXTBOX 254 377 404 395 Social media polarization 11 0.0 1 TEXTBOX 20 321 170 339 Socialization parameters\n 11 0.0 1 SLIDER 252 224 463 257 change.at change.at 0 500 130.0 10 1 NIL HORIZONTAL SLIDER 250 442 459 475 social.media.bias social.media.bias -0.3 0.3 0.0 0.05 1 NIL HORIZONTAL PLOT 919 589 1339 833 plot 1 NIL NIL 0.0 10.0 0.0 0.2 true true "" "" PENS "variance.attribute.1" 1.0 0 -955883 true "" "plot variance.attribute.1" "variance.attribute.2" 1.0 0 -13791810 true "" "plot variance.attribute.2" "variance.attribute.3" 1.0 0 -13840069 true "" "plot variance.attribute.3" "variance.attribute.4" 1.0 0 -4699768 true "" "plot variance.attribute.4" "variance.p.take-action" 1.0 0 -8630108 true "" "plot variance.p.take-action" @#$#@#$#@ ## WHAT IS IT? This model aims to represent the changes in individual probability to take any action based on changes in attributes.The action is anything that can be reasonably influenced by the three influencing methods implemented in this model: peer pressure, social media, and state campaigns, and for which the user has a decision-making model. For example, it can represent habits such as smoking, exercising, eating meat, buying certain products, opinion on a topic, etc. By default, the agents are defined by age, sex, income, education, and four additional attributes for the user to setup. These are assumed to be related to the action to be studied. The user can remove some of these attributes or add more, but portions of code will have to be modified. The model can be run without any data as it is setup to generate random agents and has a sample linear regression for decision model. In order to use this model for real data, please change to initialize the agents from a file and change the decision making model. ## HOW IT WORKS The model consists of an agents that represent individual consumers/decision-makers, whose probability to take an action we aim to change. In general, this model can be used for any kind social setting, where the main ways of influence are: peer interactions, social media, and the state. How each influence works: 1) Peer influence: agents are connected to 15 other agents, although this can be adjusted as necessary. At every time step, an agent interacts with 10/15 other agents (otherwise, the specified number by the user), and their opinion is modified based on two criterias - whether the other agent is more influential (less suscpetible) and whether the other agent is highly concerned about the topic. This second criteria can be removed by setting the sharing.threshold slider to 0.5, which means every agent will share their opinion (provided that they are more influential). There are two settings for peer interaction: non polarizing and polarizing. The first one refers to the homogenizing effect of socialization, meaning that agents' opinion converge to the average of that of their neighbors over time. The second refers to the polarizing effect of socialization, where agents who encounter opinions drastically different to that of their own tend to get further into their belief and away from the opposite. What we consider "drastically different" is set by the tolerance.threshold, which is the allowable difference between opinions to make is not too different. Anything above that would qualify as drastically different. 2) Social media influence: this is an external entity with a feedback loop that caters information to each agents individually at every time step. It is based on the opinion the agent had the time step before, and it acts as a polarizing agent, meaning that its feedback loop is set to return an opinion more extreme than the one an agent had in the previous time step. The user can set what portion of the agentset gets polarized by social media with polarization.threshold. This value ranges represent the necessary deviation from the extreme opinions (0 and 1) of agents for them to be affected. For example, if it is set to 0.1, then only agents whose concerns are above 1-0.1=0.9 or below 0+0.1=0.1 are influenced. Conversely, if it is set to 0.5, all agents are influenced. You can also choose social media bias by choosing it from the social.media.bias slider, where zero represents neutral, negarive values represent an "anti" take action, and positive values represent "pro" take action. 3) Government: this is another external entity with a feedback loop, but it bases its opinion on the average opinion of all agents rather than their individual opinions. This means that, at every time step, it calculates an average opinion about a topic, adjusts its own opinion, and dessiminates it to agents. The feedback loop will simply multiply the average opinion by the parameter government_int. If it is below 1, it will promote anti-action stances in our case, and if it is above 1, it promotes pro-action stances. The state does not influence everyone at every time step, but selects agents randomly. There are two kinds of campaigns: cyclic (influencing the same topic over certain number of time steps) and random (influencing a different topic every time step, chosen randomly). By default, we have setup four attributes to influence, but the user can add more or select to have less. In such case, portions of code will have to be replicated. ## HOW TO USE IT First, select whether you would like agents to be randomly generated or to initialize them from a csv file. In case you choose to upload your own, make sure to normalize them to [0,1]. Otherwise, changes have to be made. You can change the number of attributes you would like to initialize. After that, make sure to select all the parameters regarding socialization, all the thresholds, etc. These are the parameters: 1) Government related: - government_goals: the stance that the govenrnment represents (ranging from pro-action to anti-action). - campaign.type: random, cycle, or none. - length.cycle: if cycle was selected, choose the number of time steps. 2) Socialization parameters: - friend.group.size: number of best friends. - outside.friends.num: number of acquaintances. - socialization.beta: number of friends an agent interacts with, on average. - sharing.threshold: the level of concern a neighbor has to have for them to share their view with me. If set to 0.5, then everyone shares their opinion. 3) Polarized agentset: - society?: polarized or not. - tolerance.threshold: level of tolerance towards opinion very different to that of the agent. If set to 1, the agent is tolerant to everyone, equivalent to a non polarized agentset. - behavior.polarization: choose whether the behavior is polarizing as well, or if only the opinion is polarizing and behavior is homogenizing. 4) Social media influence: - polarization.threshold: the level of interest an agent has to show in order to see polarizing content. If set to 0.5, everyone sees polarizing content. - social.media.bias: this allows you to choose whether social media content is overall neutral, biased towards the action or against it. The positive values represent social media being more pro-action, zero represent neutrality, and negative values represent social media being anti-action. ## THINGS TO NOTICE There are two plots in the interface section. 1) Black plot: this plot represent an agent's attribute on the x-axis and their probability to take the action on the y-axis. It allows the user to see how changes in a specific variable are affecting the action variable. The user can choose to see any of the four defaul attributes on the x-axis, but only one at a time. 2) Graph 1 (top): this plot allows the user to see changes in average attributes and average probability to take the action over time. 3) Graph 1 (bottom): this graph allows the user to see changes in the variantion of agents attributes, which is an additional metric to sense how spread are the opinions. ## THINGS TO TRY First and foremost, please refer to the code for additional questions about the model. Almost every line is commented and there is additional information on how each implemented function works, which might be useful. Some of our suggestions are: - Try isolating each one of the influences in the 'influence?' chooser. This will allow you to see how each individual influence affects the agents. You can learn the isolated effect of social media, peer influence, and the state. - Play with the government.goals. You can change it mid simulation, or cancel the campaigns all together by selection "None" in campaigns.type. This will allow you to see how resilient are agents to abrupt changes in influenced. The same can be done for social media with "polarization.threshold" and with peer influence by changing the "sharing.threshold". ## EXTENDING THE MODEL Some suggestions to improve this model are: - Improving the feedback loop for government. As of right now, it is a primitive linear function, but this can be improved to be a more sophisticated. - Be critical about our choice of peer influencing function and social media influence function. In the study cited below you can find very detailed explanation of our choices and justifications of it. However, you might want to change this. In case of government and social medi influences, the lines of code to make changes to are highlighted. However, the peer pressure function is more delicate and will require considerably more changes. We suggest creating a new one if you wish to change it instead of editing the existing one. - If you wish to add more attributes than the four by default, some code will have to be added. Everywhere that is the case, we have added commented out code that you will have to add. Search for ";; TO ADD MORE ATTRIBUTES" and change the code everywhere this line exists. There are instructions on what to do to add more attributes, and we set up sample codes to add a fifth attribute. To add more, you will just need to replicate the code for the fifth attribute. - Similarly, if you need to have less than four attributes, please erase portions of the code that are identical to those commented out. Also, if you choose to change their names from ag.attribute.n to something else, be sure to do so everywhere in the code and in the interface section. ## CREDITS AND REFERENCES Copyright 2024 Daria Soboleva. This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. To view a copy of this license, visit https://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA. @#$#@#$#@ default true 0 Polygon -7500403 true true 150 5 40 250 150 205 260 250 airplane true 0 Polygon -7500403 true true 150 0 135 15 120 60 120 105 15 165 15 195 120 180 135 240 105 270 120 285 150 270 180 285 210 270 165 240 180 180 285 195 285 165 180 105 180 60 165 15 arrow true 0 Polygon -7500403 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150 box false 0 Polygon -7500403 true true 150 285 285 225 285 75 150 135 Polygon -7500403 true true 150 135 15 75 150 15 285 75 Polygon -7500403 true true 15 75 15 225 150 285 150 135 Line -16777216 false 150 285 150 135 Line -16777216 false 150 135 15 75 Line -16777216 false 150 135 285 75 bug true 0 Circle -7500403 true true 96 182 108 Circle -7500403 true true 110 127 80 Circle -7500403 true true 110 75 80 Line -7500403 true 150 100 80 30 Line -7500403 true 150 100 220 30 butterfly true 0 Polygon -7500403 true true 150 165 209 199 225 225 225 255 195 270 165 255 150 240 Polygon -7500403 true true 150 165 89 198 75 225 75 255 105 270 135 255 150 240 Polygon -7500403 true true 139 148 100 105 55 90 25 90 10 105 10 135 25 180 40 195 85 194 139 163 Polygon -7500403 true true 162 150 200 105 245 90 275 90 290 105 290 135 275 180 260 195 215 195 162 165 Polygon -16777216 true false 150 255 135 225 120 150 135 120 150 105 165 120 180 150 165 225 Circle -16777216 true false 135 90 30 Line -16777216 false 150 105 195 60 Line -16777216 false 150 105 105 60 car false 0 Polygon -7500403 true true 300 180 279 164 261 144 240 135 226 132 213 106 203 84 185 63 159 50 135 50 75 60 0 150 0 165 0 225 300 225 300 180 Circle -16777216 true false 180 180 90 Circle -16777216 true false 30 180 90 Polygon -16777216 true false 162 80 132 78 134 135 209 135 194 105 189 96 180 89 Circle -7500403 true true 47 195 58 Circle -7500403 true true 195 195 58 circle false 0 Circle -7500403 true true 0 0 300 circle 2 false 0 Circle -7500403 true true 0 0 300 Circle -16777216 true false 30 30 240 cow false 0 Polygon -7500403 true true 200 193 197 249 179 249 177 196 166 187 140 189 93 191 78 179 72 211 49 209 48 181 37 149 25 120 25 89 45 72 103 84 179 75 198 76 252 64 272 81 293 103 285 121 255 121 242 118 224 167 Polygon -7500403 true true 73 210 86 251 62 249 48 208 Polygon -7500403 true true 25 114 16 195 9 204 23 213 25 200 39 123 cylinder false 0 Circle -7500403 true true 0 0 300 dot false 0 Circle -7500403 true true 90 90 120 face happy false 0 Circle -7500403 true true 8 8 285 Circle -16777216 true false 60 75 60 Circle -16777216 true false 180 75 60 Polygon -16777216 true false 150 255 90 239 62 213 47 191 67 179 90 203 109 218 150 225 192 218 210 203 227 181 251 194 236 217 212 240 face neutral false 0 Circle -7500403 true true 8 7 285 Circle -16777216 true false 60 75 60 Circle -16777216 true false 180 75 60 Rectangle -16777216 true false 60 195 240 225 face sad false 0 Circle -7500403 true true 8 8 285 Circle -16777216 true false 60 75 60 Circle -16777216 true false 180 75 60 Polygon -16777216 true false 150 168 90 184 62 210 47 232 67 244 90 220 109 205 150 198 192 205 210 220 227 242 251 229 236 206 212 183 fish false 0 Polygon -1 true false 44 131 21 87 15 86 0 120 15 150 0 180 13 214 20 212 45 166 Polygon -1 true false 135 195 119 235 95 218 76 210 46 204 60 165 Polygon -1 true false 75 45 83 77 71 103 86 114 166 78 135 60 Polygon -7500403 true true 30 136 151 77 226 81 280 119 292 146 292 160 287 170 270 195 195 210 151 212 30 166 Circle -16777216 true false 215 106 30 flag false 0 Rectangle -7500403 true true 60 15 75 300 Polygon -7500403 true true 90 150 270 90 90 30 Line -7500403 true 75 135 90 135 Line -7500403 true 75 45 90 45 flower false 0 Polygon -10899396 true false 135 120 165 165 180 210 180 240 150 300 165 300 195 240 195 195 165 135 Circle -7500403 true true 85 132 38 Circle -7500403 true true 130 147 38 Circle -7500403 true true 192 85 38 Circle -7500403 true true 85 40 38 Circle -7500403 true true 177 40 38 Circle -7500403 true true 177 132 38 Circle -7500403 true true 70 85 38 Circle -7500403 true true 130 25 38 Circle -7500403 true true 96 51 108 Circle -16777216 true false 113 68 74 Polygon -10899396 true false 189 233 219 188 249 173 279 188 234 218 Polygon -10899396 true false 180 255 150 210 105 210 75 240 135 240 house false 0 Rectangle -7500403 true true 45 120 255 285 Rectangle -16777216 true false 120 210 180 285 Polygon -7500403 true true 15 120 150 15 285 120 Line -16777216 false 30 120 270 120 leaf false 0 Polygon -7500403 true true 150 210 135 195 120 210 60 210 30 195 60 180 60 165 15 135 30 120 15 105 40 104 45 90 60 90 90 105 105 120 120 120 105 60 120 60 135 30 150 15 165 30 180 60 195 60 180 120 195 120 210 105 240 90 255 90 263 104 285 105 270 120 285 135 240 165 240 180 270 195 240 210 180 210 165 195 Polygon -7500403 true true 135 195 135 240 120 255 105 255 105 285 135 285 165 240 165 195 line true 0 Line -7500403 true 150 0 150 300 line half true 0 Line -7500403 true 150 0 150 150 pentagon false 0 Polygon -7500403 true true 150 15 15 120 60 285 240 285 285 120 person false 0 Circle -7500403 true true 110 5 80 Polygon -7500403 true true 105 90 120 195 90 285 105 300 135 300 150 225 165 300 195 300 210 285 180 195 195 90 Rectangle -7500403 true true 127 79 172 94 Polygon -7500403 true true 195 90 240 150 225 180 165 105 Polygon -7500403 true true 105 90 60 150 75 180 135 105 plant false 0 Rectangle -7500403 true true 135 90 165 300 Polygon -7500403 true true 135 255 90 210 45 195 75 255 135 285 Polygon -7500403 true true 165 255 210 210 255 195 225 255 165 285 Polygon -7500403 true true 135 180 90 135 45 120 75 180 135 210 Polygon -7500403 true true 165 180 165 210 225 180 255 120 210 135 Polygon -7500403 true true 135 105 90 60 45 45 75 105 135 135 Polygon -7500403 true true 165 105 165 135 225 105 255 45 210 60 Polygon -7500403 true true 135 90 120 45 150 15 180 45 165 90 sheep false 15 Circle -1 true true 203 65 88 Circle -1 true true 70 65 162 Circle -1 true true 150 105 120 Polygon -7500403 true false 218 120 240 165 255 165 278 120 Circle -7500403 true false 214 72 67 Rectangle -1 true true 164 223 179 298 Polygon -1 true true 45 285 30 285 30 240 15 195 45 210 Circle -1 true true 3 83 150 Rectangle -1 true true 65 221 80 296 Polygon -1 true true 195 285 210 285 210 240 240 210 195 210 Polygon -7500403 true false 276 85 285 105 302 99 294 83 Polygon -7500403 true false 219 85 210 105 193 99 201 83 square false 0 Rectangle -7500403 true true 30 30 270 270 square 2 false 0 Rectangle -7500403 true true 30 30 270 270 Rectangle -16777216 true false 60 60 240 240 star false 0 Polygon -7500403 true true 151 1 185 108 298 108 207 175 242 282 151 216 59 282 94 175 3 108 116 108 target false 0 Circle -7500403 true true 0 0 300 Circle -16777216 true false 30 30 240 Circle -7500403 true true 60 60 180 Circle -16777216 true false 90 90 120 Circle -7500403 true true 120 120 60 tree false 0 Circle -7500403 true true 118 3 94 Rectangle -6459832 true false 120 195 180 300 Circle -7500403 true true 65 21 108 Circle -7500403 true true 116 41 127 Circle -7500403 true true 45 90 120 Circle -7500403 true true 104 74 152 triangle false 0 Polygon -7500403 true true 150 30 15 255 285 255 triangle 2 false 0 Polygon -7500403 true true 150 30 15 255 285 255 Polygon -16777216 true false 151 99 225 223 75 224 truck false 0 Rectangle -7500403 true true 4 45 195 187 Polygon -7500403 true true 296 193 296 150 259 134 244 104 208 104 207 194 Rectangle -1 true false 195 60 195 105 Polygon -16777216 true false 238 112 252 141 219 141 218 112 Circle -16777216 true false 234 174 42 Rectangle -7500403 true true 181 185 214 194 Circle -16777216 true false 144 174 42 Circle -16777216 true false 24 174 42 Circle -7500403 false true 24 174 42 Circle -7500403 false true 144 174 42 Circle -7500403 false true 234 174 42 turtle true 0 Polygon -10899396 true false 215 204 240 233 246 254 228 266 215 252 193 210 Polygon -10899396 true false 195 90 225 75 245 75 260 89 269 108 261 124 240 105 225 105 210 105 Polygon -10899396 true false 105 90 75 75 55 75 40 89 31 108 39 124 60 105 75 105 90 105 Polygon -10899396 true false 132 85 134 64 107 51 108 17 150 2 192 18 192 52 169 65 172 87 Polygon -10899396 true false 85 204 60 233 54 254 72 266 85 252 107 210 Polygon -7500403 true true 119 75 179 75 209 101 224 135 220 225 175 261 128 261 81 224 74 135 88 99 wheel false 0 Circle -7500403 true true 3 3 294 Circle -16777216 true false 30 30 240 Line -7500403 true 150 285 150 15 Line -7500403 true 15 150 285 150 Circle -7500403 true true 120 120 60 Line -7500403 true 216 40 79 269 Line -7500403 true 40 84 269 221 Line -7500403 true 40 216 269 79 Line -7500403 true 84 40 221 269 wolf false 0 Polygon -16777216 true false 253 133 245 131 245 133 Polygon -7500403 true true 2 194 13 197 30 191 38 193 38 205 20 226 20 257 27 265 38 266 40 260 31 253 31 230 60 206 68 198 75 209 66 228 65 243 82 261 84 268 100 267 103 261 77 239 79 231 100 207 98 196 119 201 143 202 160 195 166 210 172 213 173 238 167 251 160 248 154 265 169 264 178 247 186 240 198 260 200 271 217 271 219 262 207 258 195 230 192 198 210 184 227 164 242 144 259 145 284 151 277 141 293 140 299 134 297 127 273 119 270 105 Polygon -7500403 true true -1 195 14 180 36 166 40 153 53 140 82 131 134 133 159 126 188 115 227 108 236 102 238 98 268 86 269 92 281 87 269 103 269 113 x false 0 Polygon -7500403 true true 270 75 225 30 30 225 75 270 Polygon -7500403 true true 30 75 75 30 270 225 225 270 @#$#@#$#@ NetLogo 6.3.0 @#$#@#$#@ @#$#@#$#@ @#$#@#$#@ @#$#@#$#@ @#$#@#$#@ default 0.0 -0.2 0 0.0 1.0 0.0 1 1.0 0.0 0.2 0 0.0 1.0 link direction true 0 Line -7500403 true 150 150 90 180 Line -7500403 true 150 150 210 180 @#$#@#$#@ 0 @#$#@#$#@