Safe Sex Attitudes and Behaviors

Safe Sex Attitudes and Behaviors preview image

1 collaborator

169052_10150377794380507_3657409_n Lizz B (Author)

Tags

attitude 

Tagged by Lizz B over 11 years ago

attitudes and behavior 

Tagged by Lizz B over 11 years ago

certainty 

Tagged by Lizz B over 11 years ago

justification 

Tagged by Lizz B over 11 years ago

safe sex 

Tagged by Lizz B over 11 years ago

sex 

Tagged by Lizz B over 11 years ago

std 

Tagged by Lizz B over 11 years ago

sti 

Tagged by Lizz B over 11 years ago

Model group MAM-2013 | Visible to everyone | Changeable by the author
Model was written in NetLogo 5.0.4 • Viewed 820 times • Downloaded 58 times • Run 0 times
Download the 'Safe Sex Attitudes and Behaviors' modelDownload this modelEmbed this model

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


Info tab cannot be displayed because of an encoding error

Comments and Questions

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

Click to Run Model

;;; --------------------------------------------------------------------- ;;;
;; --- Temporary breeds for setting up social groups/cliques --- ;;

;; default turtle type, will later be changed to male or female
breed [ people person ]
breed [ leaders leader ] ;; "clique leader" in a way
                         ;; helps with creating spatial layout and
                         ;; (optional) some initial links between groups

;; Breeds (agentsets) for gender
;; (once social groups/networks established)
breed [males male]
breed [females female]

;; a way to access the links to members of each clique
links-own [ group ]

;; Link breeds - turtles can either be friends, or sexual partners
; In this model, turtles can have multiple friends,
; but only one sexual partner at a time
undirected-link-breed [sexual-partners sexual-partner]
undirected-link-breed [friends friend]


;;; --------------------------------------------------------------------- ;;;
;;;
;;; GLOBAL VARIABLES
;;;
;;; --------------------------------------------------------------------- ;;;

globals
[
  ;; The next 3 values are set by sliders, where default is scale 0 - 100
  
  ;; The chance out of 100 that an infected person will transmit infection
  ;; during one week of couplehood if they have unsafe sex
  ;infection-chance 
  
  ;; Used as an average for generating chance out of 100 that an agent 
  ;; will use/wants to use a condom (depends on gender)
  ;avg-female-condom-intention 
  ;avg-male-condom-intention  
                             
  
  ;; The next two values are used only in assign-sex-ed-level, and
  ;; will be assigned depending on the %-receive-condom-sex-ed slider value
  ;; Average level of accurate knowledge if agent received:
  no-condom-sex-ed-level ;; sex education that did not include/cover condom use
  condom-sex-ed-level    ;; sex education that included condom use for STI protection
  
  
  ;; The next two values are determined by the symptomatic? chooser
  males-symptomatic?   ;; If true, males will be symptomatic IF infected with an STI
  females-symptomatic? ;; If true, females will be symptomatic IF infected with an STI
                                 

  ;; The next two values are the maximum value for tendency of any agent 
  ;; to make a friend or sexual partner link on a given turn. (scale 1 to 100)
  ;; Used as an upper bound for generating random chance for individual agents 
  max-friendship-factor ;; Maximum friendship-making-coupling tendency value
  max-coupling-factor   ;; Maximum coupling tendency value (sexual partner)
                     
  ;; The next two values are the average tendency of an agent to form a
  ;; friendship/sexual partnership with another agent
  ;; Both are set to the max factor / 2
  ;; Average tendency of a person to couple with another person
 
  avg-friendship-tendency ;; Average tendency of a person to make friends with another person
  avg-coupling-tendency   ;; Average tendency of a person to couple with another person 
                          ;; in order to couple, the pairings must consist of one male and one female,
                          ;; and both partners must be single/uncoupled

  avg-relationship-length ;; Average number of ticks a sexual partnership/couple will stay together (commitment)
  
  
  certainty-delta ;; the amount that certainty increases
                  ;; whenever an agent repeats their attitude to others
                  ;; as certainty increases, it becomes harder to change an agent's opinion
  
  justification-delta ;; the amount that justification decreases
                      ;; every time an agent thinks they "got away" with unsafe sex
 
]


;;; --------------------------------------------------------------------- ;;;
;;;
;;; Turtle/Agent Variables
;;;
;;; --------------------------------------------------------------------- ;;;

turtles-own
[
  ;; The percent chance a person uses protection (condoms) while in a couple
  ;; The likelihood (0 - 100%) of this agent practicing safe sex (reflects behavior)
  ;; Likelihood is influenced by three components:
  ;; attitude, certainty, and justification

  safe-sex-likelihood

  ;; Variable used to determine how much this agent's safe sex likelihood
  ;; has changed since the last tick
  old-safe-sex-likelihood 
  
  ;; ATTITUDE:
  ;; The intention or desire of an agent to practice safe sex (use a condom)
  ;; Evolves over time through talking to peers, or becoming infected
  attitude 
                 
  
  ;; CERTAINTY:
  ;; how confidently/strongly an agent feels about their attitude
  ;; The chance that an attitude changes is inversely proportional to certainty
  certainty ;; initially set to mesosystem-condom-encouragement
            ;; i.e. how much their upbringing encouraged safe sex
            ;; might consist of parents' beliefs, life experiences, religious attitudes, etc.
  
  
  ;; JUSTIFICATION:
  ;; the logic or reasoning to rationalize having a postive attitude towards safe sex,
  ;; which is independent of how strongly they feel about it (certainty)
  ;; or what their actual attitude is
  justification ;; initially set to the level of accurate education this agent has about safe sex and condom usage
  
  
  had-unsafe-sex? ;; Whether this person had sex without a condom on the last tick
  
  infected? ;; If true, the person is infected (and infectious)
  known?    ;; The person is infected and knows it (due to being symptomatic)
  ;; In this model, agents that know they are infected
  ;; always use condoms to protect their sexual partners
  ;; If an agent is not symptomatic/of a symptomatic gender,
  ;; their known? variable never gets set to true, which 
  ;; may enable an STI to more easily spread through a population
  
  coupled?      ;; If true, the person is in a sexually active couple.
  partner       ;; The person that is our current partner in a couple.
  couple-length ;; How long the person has been in a couple.
  
  friendship-tendency ;; How likely this person is to make a new friend
  coupling-tendency   ;; How likely the person is to join a couple.
  commitment          ;; How long the person will stay in a couple/relationship.
  
  group-membership ;; which clique/friend group/cluster this agent is part of
  
  num-friends ;; The number of friends that an agent wants to have

]


;;; --------------------------------------------------------------------- ;;;
;;;
;;; SETUP PROCEDURES
;;;
;;; --------------------------------------------------------------------- ;;;

;;
;; Calls all separate setup functions - setting globals, cliques, individuals
;;
;;

to setup
  clear-all
  setup-globals
  setup-clusters ;; set up social groups/cliques
  setup-people   ;; change breeds to male/female, set individual turtle attributes
  
  ;; By default, setup infects two random individuals in the model with an STI
  ;; but if you want to also explore spread of attitudes without an STI spreading
  ;; through the population, comment out the line below

  infect-random ;; infect one random male and one random female

               
  ; To set up, don't initialize any sexual partnerships, since
  ; they'll form on their own (i.e. only create friendship links) 
  ask links [assign-link-color]
  
  reset-ticks
end 

;;; --------------------------------------------------------------------- ;;;
;;
;; Initialize global variables
;;

to setup-globals
  
  ;; the amount certainty increases when an agent repeats their attitude
  set certainty-delta .1 
  
  ;; the amount justification decreases when an agent thinks they "got away with" unsafe sex
  set justification-delta 2
  
  ;; These could also be set in assign-sex-ed-level
  set no-condom-sex-ed-level 20
  set condom-sex-ed-level 80
  
  ;; Call functions to set whether females and males show symptoms of the STI
  ;; based on value of chooser/drop-down in interface
  run word "set-" symptomatic?
  
  ;; For simplicity, use predetermined values to set these variables
  ;; (compared to AIDS model, which uses sliders) 
  
  set max-friendship-factor 70
  set max-coupling-factor 40
  set avg-friendship-tendency (max-friendship-factor / 2)
  set avg-coupling-tendency (max-coupling-factor / 2)
  set avg-relationship-length 25
end 


;;
;; Setter functions for the symptomatic? chooser/drop-down
;;
;;

to set-females-symptomatic?
  set females-symptomatic? true
  set males-symptomatic? false
end 

to set-males-symptomatic?
  set males-symptomatic? true
  set females-symptomatic? false
end 

to set-both-symptomatic?
  set females-symptomatic? true
  set males-symptomatic? true
end 

to set-neither-symptomatic?
  set males-symptomatic? false
  set females-symptomatic? false
end 



;;; --------------------------------------------------------------------- ;;;
;;
;; Set up social clusters of networked agents
;;
;;

to setup-clusters
  
  create-leaders num-cliques [ ]
  
  ;; The number of total inter-group links between members
  let num-links ( ( avg-num-friends - 1 ) * clique-size ) / 2
  ; The - 1 accounts for each member initially linking to the leader
  ; Multiplying by clique-size ensures there are enough for all group members
  ; Then divide by 2, since you only need 1 link to connect 2 people
  
  ;; if only 1 cluster, leader setxy 0 0 by default
  if (num-cliques > 1) ;; if more than 1 cluster
  [
    ;; The "leaders" are the central person of the clique/social group
    layout-circle leaders 10

    ;; Create links between all "leaders"
    ask leaders [ create-friends-with other leaders ]
    ; Assume that all leaders interact/are social butterflies/charismatic,
    ; hence why their entire friend group likes them too.
  ]
  
  let groupID 0
  while [ groupID < num-cliques ]
  [
    create-people clique-size [ set group-membership groupID ]
    
    ;; if only 1 cluster, layout-circle works 14.5
    ;; leader is in the center of the group
    layout-circle people with [group-membership = groupID ] 5 - 0.5 * max( list (num-cliques - 5) (0) )
    ask people with [group-membership = groupID ]
    [
      setxy xcor + [xcor] of leader groupID ycor + [ycor] of leader groupID
      create-friend-with leader groupID
    ]
    
    ;; Agents make friendship links with people in their clique/friend circle
    let linkcounts 0
    while [linkcounts < num-links ]
    [
      ask one-of people with [group-membership = groupID]
      [
        let choice (one-of other people with [not link-neighbor? myself and group-membership = groupID])
        if choice != nobody
          [
            create-friend-with choice [ set group groupID ]
            set linkcounts linkcounts + 1
          ]
      ]
    ]
    
    ;; Increment the groupID to differentiate clique ID #'s
    set groupID groupID + 1
  ]
  
  ;; Leaders are used for spatially setting up discrete clusters
  ;; and for providing some links between groups.
  ;; If they are disabled, there are no initial inter-group links,
  ;; but agents might still form friendships or sexual partnerships 
  ;; with agents that are not in their clique.
  if (not social-butterflies?) [ask leaders [ die ] ]
end 


;;; --------------------------------------------------------------------- ;;;
;;
;; Initialize individual agents by setting gender and unique member variables
;;
;;

to setup-people
  
  ;; Don't actually CREATE turtles here, that's done by setup-clusters
  ask turtles
  [
    ;; Set ideal number of friends for each agent to
    ;; the initial number of friend links they have
    set num-friends (count friend-neighbors)
    
    set breed males ;; Default breed male, change half to female later
    set coupled? false ;; Everyone is initially single
    set partner nobody
    set had-unsafe-sex? false ;; Whether this person had unsafe sex on the last tick
    
    set infected? false ;; Initially, no one is infected
    set known? false
                                       
  ]
  
  ;; Set genders of turtles to be 50% male, 50% female
  ask n-of (count turtles / 2) turtles [set breed females ]
  
  ask turtles
  [
    ;; Individual variables per agent are set randomly following
    ;; a normal distribution based on slider or global values
    assign-normally-distributed-member-variables
    
    
    ;; Determine how much this agent's likelihood of practicing safe sex
    ;; has changed since last tick.
    ;; (If likelihoods of all agents stop changing significantly,
    ;; the simulation will stop.)
    update-safe-sex-likelihood
    set old-safe-sex-likelihood safe-sex-likelihood
    
    
    assign-turtle-color ;; Color is determined by likelihood of practicing safe sex
    assign-shape        ;; Shape is determined by gender and sick status
    set size 2.5        ;; Make shapes a bit easier to distinguish by increasing size
  ]
end 


;;; --------------------------------------------------------------------- ;;;
;;
;; Helper procedure to approximate a "normal" distribution
;; around the given average value

;; Generate many small random numbers and add them together.
;; This produces a normal distribution of tendency values.
;; A random number between 0 and 100 is as likely to be 1 as it is to be 99.
;; However, the sum of 20 numbers between 0 and 5
;; is much more likely to be 50 than it is to be 99.
;; (from the AIDS model)

to-report random-near [center] ;; turtle procedure
  let result 0
  repeat 40 [ set result (result + random-float center) ]
  report result / 20
end 


;;
;; Assign values to variables of agents in the population using
;; the helper procedure RANDOM-NEAR so that individual agents variables
;; follow an approximately "normal" distribution around average values.
;;

to assign-normally-distributed-member-variables ;; turtle procedure
  
    ;;
    ;; The below variables will vary for each turtle, and the values
    ;; follow an approximately normal distribution
    ;;
    
    ;; How long the person will stay in a couple-relationship. (doesn't change)
    set commitment random-near avg-relationship-length
    
    ;; How likely the person is to join a couple. (doesn't change)
    set coupling-tendency random-near avg-coupling-tendency
    
    ;; How likely the person is to make a friend. (doesn't change)
    set friendship-tendency random-near avg-friendship-tendency
    
    
    ;; Note: Gender must be set before this is called!
    ;; Assign initial attitude towards safe sex based on gender
    ;; Attitude can change during the simulation through talking to peers
    ;; and being aware of contracting an STI
    ifelse (is-female? self)
    [ set attitude random-near avg-female-condom-intention ]
    [ set attitude random-near avg-male-condom-intention ]
    
    ;; Assign initial certainty based on mesosystem encouragement
    ;; Certainty increases whenever an agent repeats their attitude to others
    ;; Currently, certainty does not decrease in this model
    set certainty random-near avg-mesosystem-condom-encouragement
    
    ;; Assign initial justification based on sex ed agent received
    ;; Justification can decrease if agent thinks they "got away with" having unsafe sex
    ;; or increase if they contract an STI themselves
    ;; Note: in this model, the justification is not justification for
    ;; the attitude itself, but rather a justification for having safe sex
    assign-sex-ed-level
end 

;;
;; Assign a level of accurate knowledge of safe sex
;; normally distributed around a high or low value
;; based on type of sex ed the agent received.
;; Used to initialize the agent's justification.
;;

to assign-sex-ed-level ;; turtle procedure
  
  ;; Note: The condom-sex-ed level and no-condom-sex-ed-level are
  ;; static global values in this model for convenience. Since
  ;; they are only used here, they could be set locally instead.
  
  ifelse (random 100 <= %-receive-condom-sex-ed)
  [
    ;; If agent received sex ed including condom usage,
    ;; assume knowledge randomly distributed around HIGH value
    ;; (static global value)
    set justification random-near condom-sex-ed-level
  ]
  [
    ;; If agent received sex ed without condom usage,
    ;; Assume knowledge randomly distributed around LOW value
    set justification random-near no-condom-sex-ed-level
  ]
end 


;;; --------------------------------------------------------------------- ;;;
;;;
;;; Set color/shape of agents/links
;;;
;;; --------------------------------------------------------------------- ;;;

;;
;; Set shape based on gender (male or female)
;; and whether or not infected (includes a dot)
;;

to assign-shape ;; turtle procedure
  ifelse infected?
  [
    ifelse is-male? self
    [
      ifelse known?
      [ set shape "male sick" ]
      [ set shape "male sick unknown" ]
    ]
    [
      ifelse known?
      [ set shape "female sick" ]
      [ set shape "female sick unknown" ]
    ]
  ]
  ;; otherwise, the turtle is not infected
  [
    ifelse is-male? self
    [set shape "male"]
    [set shape "female"]
  ]
end 


;;
;; Color of the agent reflects their individual 
;; likelihood of practicing safe sex
;;

to assign-turtle-color ;; turtle procedure
  
  ;; call this just in case a variable went out of accepted range
  cap-member-variables 
 
  ;06C106 green - 100% likely to engage in safe sex (using a condom)
  ;FFFFFF white - 50% likely of having safe sex 
  ;C10606   red  - 0% likely to use a condom (100% likely to have unsafe sex)
 
  ;; If there was a switch statement for NetLogo,
  ;; this would be where you'd use it
  if (safe-sex-likelihood >= 0) [ set color [ 193   6   6 ] ] ;; 0-5 % - red
  if (safe-sex-likelihood > 5)  [ set color [ 198  26  26 ] ] ;; 5-10 %
  if (safe-sex-likelihood > 10) [ set color [ 204  51  51 ] ] ;; 10-15 %
  if (safe-sex-likelihood > 15) [ set color [ 210  77  77 ] ] ;; 15-20 %
  if (safe-sex-likelihood > 20) [ set color [ 217 102 102 ] ] ;; 20-25 %
  if (safe-sex-likelihood > 25) [ set color [ 223 127 127 ] ] ;; 25-30 %
  if (safe-sex-likelihood > 30) [ set color [ 229 153 153 ] ] ;; 30-35 %
  if (safe-sex-likelihood > 35) [ set color [ 236 178 178 ] ] ;; 35-40 %
  if (safe-sex-likelihood > 40) [ set color [ 242 204 204 ] ] ;; 40-45 %
  if (safe-sex-likelihood > 45) [ set color [ 248 229 229 ] ] ;; 45-50 %
  if (safe-sex-likelihood = 50) [ set color [ 255 255 255 ] ] ;; 50% - white
  if (safe-sex-likelihood > 50) [ set color [ 229 248 229 ] ] ;; 50-55 %
  if (safe-sex-likelihood > 55) [ set color [ 204 242 204 ] ] ;; 55-60 %
  if (safe-sex-likelihood > 60) [ set color [ 178 236 178 ] ] ;; 60-65 %
  if (safe-sex-likelihood > 65) [ set color [ 153 229 153 ] ] ;; 65-70 %
  if (safe-sex-likelihood > 70) [ set color [ 127 223 127 ] ] ;; 70-75 %
  if (safe-sex-likelihood > 75) [ set color [ 102 217 102 ] ] ;; 75-80 %
  if (safe-sex-likelihood > 80) [ set color [  77 210  77 ] ] ;; 80-85 %
  if (safe-sex-likelihood > 85) [ set color [  51 204  51 ] ] ;; 85-90 %
  if (safe-sex-likelihood > 90) [ set color [  26 198  26 ] ] ;; 90-95 %
  if (safe-sex-likelihood > 95) [ set color [   6 193   6 ] ] ;; 95-100 % - green
  
  
  ;; The label is just redundant information of the color
  ;; but it is more precise (displays actual value)
  ;; since assign-turtle-color is updated on every tick
  ;; this can be called from within this function
  ifelse (show-labels?)
  [ set label (round safe-sex-likelihood) ]
  [ set label "" ]
end 


;;
;; Color of link indicates type of relationship between the two agents
;; blue is a friendship, magenta is a sexual partnership
;;

to assign-link-color ;; link procedure
  
  ifelse is-friend? self
    [ set color blue]
    [ set color magenta]
    
  set thickness .16 ; make the link a bit easier to see
end 



;;; --------------------------------------------------------------------- ;;;
;;;
;;; GO/RUNTIME PROCEDURES
;;;
;;; --------------------------------------------------------------------- ;;;

;;
;; Run the simulation
;;

to go
  
  ;;; ----- Check for STOP conditions ----- ;;
  
  ;; Stop if every single turtle is infected
  if all? turtles [infected?] [ stop ]
  
  ;; If all agents reach a polarized safe-sex-likelihood,
  ;; or all agents are certain of their attitude (will not change any more)
  ;; the model has reached a stable state, so stop
  if all? turtles [
    safe-sex-likelihood < 0.1 or
    safe-sex-likelihood > 99.9 or
    certainty > 99.9
    ] [stop]
 
 
  ;; record each agent's likelihood before interacting with others,
  ;; and potentially getting/realizing they are infected 
  ask turtles [ set old-safe-sex-likelihood safe-sex-likelihood ]
  
  ask turtles
  [
    ;; Agents talk to their friends and sexual partner (if any), which
    ;; might impact his/her personal likelihood of practicing safe sex
    talk-to-peers
    
    ;; If already coupled with a sexual partner,
    ;; just increase length of relationship
    ;; (agents are monogamous in this simulation)
    ifelse coupled? [ set couple-length couple-length + 1 ]
    
    ;; If they are NOT coupled, agent tries to find a mate
 
    ;; Any agent can initiate mating if they are not coupled
    ;; (and random chance permits)
    [ if (random-float max-coupling-factor < coupling-tendency) [ couple ] ]
  ]
  
  ;; give everyone (coupled or not) a chance to make a friend
  ask turtles
  [
    ;; Everyone should attempt to make friends because otherwise,
    ;; the sexual partner links break and agents end up 
    ;; only being friends with agents of the same sex
    
    ;; If this agent has not reached their maximum limit of friends,
    ;; try to make a friend / create a friend link
    if ( (count friend-neighbors < num-friends) and
         random-float max-friendship-factor < friendship-tendency )
    [ make-friends ]
    
    ;; If this agent already has reached their maximum limit of friends,
    ;; don't try to create any more friend links
  ]
  
  ;; Agents will uncouple if the length of the relationship reaches
  ;; the commitment threshold for one of the partners
  ;; Call uncouple after make-friends and couple, 
  ;; because you wouldn't want exes immediately friending each other again,
  ;; and this model doesn't simulate instant rebounds
  ask turtles [ uncouple ]
  
  ;; If turtles are coupled (have a sexual partner), 
  ;; they will have sex on each tick, and have the potential
  ;; of spreading an STI if they have unprotected sex.
  ask turtles [ have-sex ]
  
  ;; In order to best simulate that STIs may not present symptoms immediately,
  ;; don't check if infected (known determined by being symptomatic)
  ;; until after talking to friends about attitude and having sex
  ask turtles [ check-infected ]
  
  ask turtles
  [ 
    update-safe-sex-likelihood
    assign-turtle-color ;; based on safe-sex-likelihood
  ]

  tick
end 


;;; --------------------------------------------------------------------- ;;;
;;
;; Update the likelihood (out of 100) that an agent
;; will practice safe sex (use a condom).
;;

to update-safe-sex-likelihood
  
  ;; The likelihood of an agent engaging in safe sex behaviors (using a condom)
  ;; is determined by a combination of the agent's:
  ;;   - attitude (desire)
  ;;   - justification (knowledgeable background/logical reasoning for safe sex attitude)
  
  ;; Certainty is assumed to be independent of attitude value itself,
  ;; even when the attitude is polarized (close to 100 or close to 0)
  ;; Certainty impacts how resistant an agent is to change their attitude
  ;; when talking to others, and how many others the agent interacts with,
  ;; but doesn't directly impact likelihood calculation.

  ;; cap variables just in case
  cap-member-variables ; make sure no variables got set to < 0 or > 100
  
  ;; Likelihood is strongly weighted by attitude
  let attitude-weight .75
  let justification-weight .25
  
  set safe-sex-likelihood (attitude * attitude-weight + justification * justification-weight)
end 


;;
;; Make sure the member variables don't exceed 100
;;

to cap-member-variables ;; turtle procedure
  if (safe-sex-likelihood > 100) [set safe-sex-likelihood 100]
  if (safe-sex-likelihood < 0) [set safe-sex-likelihood 0]
  if (attitude > 100) [set attitude 100]
  if (attitude < 0) [set attitude 0]
  if (certainty > 100) [set certainty 100]
  if (certainty < 0) [set certainty 0]
  if (justification > 100) [set justification 100]
  if (justification < 0) [set justification 0]
end   


;;; --------------------------------------------------------------------- ;;;
;;;
;;; SPREAD ATTITUDES
;;;
;;; --------------------------------------------------------------------- ;;;

;;
;; Agent interacts with its friends (and sexual partner, if any)
;; and potentially alters its personal likelihood of practicing safe sex
;;

to talk-to-peers ;; turtle procedure
  
  ;; Use certainty to determine how many links this agent talks to per tick
  ;; The more certain a person is in their attitude,
  ;; the more likely they are to discuss it with their peers/links.
  
  let convoCount 0
  
  ;; NOTE: These "conversations"/"interactions" are one-directional in this model.
  ;; Additionally, an agent is not guaranteed to talk to their sexual partner
  while [ convoCount < ( certainty / 100 ) * ( count my-links ) ] 
  [
      
      let peer one-of link-neighbors ;; friends or sexual partner, if any
      if (peer != nobody)
      [
        ;; An agent grows more certain of their attitude
        ;; (regardless of what that attitude actually is)
        ;; every time they express it to someone else (repeated expression)
          
        set certainty certainty + certainty-delta
        
        
        ;; A person's certainty impacts how likely they are to change their attitude.
        ;; An agent with higher certainty is more resistant to changing their attitude.
        ;; (100 - certainty) is how likely an agent is to adjust their attitude.
        
        let attitude-change-chance ( (100 - certainty) / 100 )
        

        ;; However, an agent doesn't care about how confident their peer
        ;; feels about his/her attitude (their certainty), s/he only cares about
        ;; what reasoning they have to back up their attitude (justification).
        ;; So if the peer has strong justification of their attitude, 
        ;; the agent is more likely to be swayed
        
        let peer-persuasion-chance ( [justification] of peer / 100 )
        
        
        ;; Constants for dampening and getting desired reactions
        ;; calculated through tinkering with Excel formulas
        let scale-factor 10 
        let c 0.5
        
          
        ;; In order to account for polarity/extremity of attitude
        ;; subtract 50 from it to aid in the calculations
        ;; So "your" (this agent's) attitude scaled down to be between
            ;; -50 (very anti safe sex)
            ;; to 0 (neutral)
            ;; to 50 (very pro safe sex)   
            
        let my-attitude-scaled ( (attitude - 50) / scale-factor )
        let peer-attitude-scaled ( ([attitude] of peer - 50) / scale-factor )
        let temp-var ( my-attitude-scaled * my-attitude-scaled * peer-attitude-scaled / (scale-factor ^ 3) ) 
        
        let attitude-change ( c * attitude-change-chance * peer-persuasion-chance * temp-var)
        
        set attitude attitude + attitude-change
      ]
      
      set convoCount convoCount + 1
  ]
  
    ;; update personal likelihood based on talking to peers
    update-safe-sex-likelihood 
end 


;;; --------------------------------------------------------------------- ;;;
;;;
;;; SPREAD STI (potentially) / HAVE SEX
;;;
;;; --------------------------------------------------------------------- ;;;

;;
;; Only agents with sexual partners (coupled) can spread an STI
;;
;;

to have-sex ;; turtle procedure (only for coupled turtles)
  
  
  ask turtles with [coupled?]
  [
    ;; Infection can occur if either person is infected, but the infection is unknown.
    ;; This model assumes that people with known infections will continue to couple,
    ;; but will always practice safe sex.

    ;; This model simulates sexual relations between a male and a female,
    ;; so I decided that only one of the partner's desire to use a condom
    ;; must be strong enough to make sure the couple has safe sex.
    
    ;; Extensions/modifications may choose to change this so that
    ;; for condom use to occur, BOTH people must want to use one.
    ;; This can be done by changing the primitive after the
    ;; second grouped condition of the ifelse statement from AND to OR

    ifelse ( (not known? and [not known?] of partner) and
             (random-float 100 > safe-sex-likelihood) AND   ;; Optional: change this to or for both people to have to want to use a condom
             (random-float 100 > ([safe-sex-likelihood] of partner))
           ) 
    [
      ;; If got past the above conditional, that means the couple had unprotected sex
      set had-unsafe-sex? true
      ask partner [ set had-unsafe-sex? true ]
      
      ;; They had unprotected sex, so infection is possible...
      if (random-float 100 < infection-chance)
      [
        ;; Spread virus between an infected and non-infected coupled partner duo
        if (infected?) [ ask partner [ become-infected ] ]
        if ([infected?] of partner) [ become-infected ]
      ]
    ]
    [
      set had-unsafe-sex? false
      ask partner [set had-unsafe-sex? false]
      
      ;; This model assumes that safe sex (using a condom) is always 
      ;; 100% effective in preventing the spread of infection - 
      ;; thus there is no random chance of the infection spreading if a condom is used.
      ;; This could be modified in extensions to be more realistic and
      ;; account for factors like incorrect/inconsistent condom usage,
      ;; condom failure, or STIs passed through other means.
    ]
  ]
end 


;;; --------------------------------------------------------------------- ;;;
;;;
;;; MAKE FRIENDS (Potential attitude influencers)
;;;
;;; --------------------------------------------------------------------- ;;;

;;
;; Try to make friend links with other turtles
;; (will only be called if the turtle has not reached their maximum friend limit)
;; Uses similar approach as coupling, but gender doesn't matter
;;

to make-friends ;; turtle procedure
  
  ;; This agent's clique (social/friend group) id
  let groupID group-membership
  
  ;; Probability that friendship link will form
  ;; (arbitrary number to overwrite)
  let friending-probability 1.0
  
  ;; Probability of successful coupling decreases if the
  ;; potential friend is not part of the agent's clique
  ;; Note: these are arbitrary numbers that could be adjusted for more realistic modeling
  let in-group-probability 0.8
  let out-group-probability 0.2
  
  ;; No need to check for gender compatibility,
  ;; everyone can be friends with each other, yay!
  ;; However, the potential-friend must not have maxed out their friend count
  
  ;; A valid potential friend must not have reached his/her friend limit
  ;; (but gender is irrelevant).
  
  ;; First, try to find someone in their clique who is not a current link
  let potential-friend ( one-of other turtles with [not link-neighbor? myself
               and group-membership = groupID
               and (count friend-neighbors < num-friends)] )
  ifelse (potential-friend != nobody)
  [
    set friending-probability in-group-probability
  ]
  ;; If they couldn't find a potential friend within their friend group,
  ;; try finding the closest nearby agent
  [
    set potential-friend ( min-one-of (other turtles with [not link-neighbor? myself
                 and (count friend-neighbors < num-friends)]) [distance myself])
    set friending-probability out-group-probability
  ]
  
  if (potential-friend != nobody)
  [
     ;; Use friending-probability to impact chance of successfully becoming friends
     ;; Higher likelihood if they are in the same friend group, lower if they are not
     if ( (random-float 1.0 < friending-probability) and   
          (random-float max-friendship-factor < [friendship-tendency] of potential-friend) )
      [ create-friend-with potential-friend [ assign-link-color] ]
  ]
end 


;;; --------------------------------------------------------------------- ;;;
;;;
;;; COUPLING/UNCOUPLING PROCEDURES
;;;
;;; --------------------------------------------------------------------- ;;;

;;
;; Agents might couple depending on their gender, their tendency to couple,
;; and if they are already friends/in same clique/nearby a potential single mate
;;
;; ----- Try to find a valid partner ----- ;;
;; 1) try existing friend link of opposite sex
;; 2) try opposite sex within friend group, but not a current link
;; 3) try a nearby opposite sex person as a last resort
;; (probability of successful coupling decreases for last 2 options)
;;

to couple ;; turtle procedure (single turtles only)
  ;; all my single turtles, now put your hands UP
  
  ;; This agent's clique (social/friend group) id
  let groupID group-membership
  
  ;; Probability that sexual partnership link will form
  ;; (arbitrary number to overwrite)
  let coupling-probability 1.0 
  
  ;; Probability of successful coupling decreases if the
  ;; potential friend is not part of the agent's clique
  ;; Note: these are arbitrary numbers that
  ;; could be adjusted for more realistic modeling
  let friend-probability 0.8
  let in-group-probability 0.6 ;.8
  let out-group-probability 0.3
 
  
  ;; Create variable that we will overwrite
  let potential-partner one-of friend-neighbors
  
  ;; For simplicity, only dealing with straight people (male + female pairs).
  
  ;; Try to find a valid potential sexual partner.
  ;; A valid potential sexual partner must be the opposite gender and not coupled.
  
  ;; Male agent - wants to find a female potential partner
  ifelse is-male? self
  [
    ;; First check out existing female friends
    set potential-partner (one-of females with [friend-neighbor? myself and not coupled?])
    set coupling-probability friend-probability
    
    ;; If that wasn't successful,
    ;; try to find a female within his clique that is not a current friend/link
    if (potential-partner = nobody)
    [
      set potential-partner
      (one-of females with [not link-neighbor? myself and not coupled? and group-membership = groupID])
      set coupling-probability in-group-probability
    ]
    
    ;; As a last resort,
    ;; look for the closest female that is not a link, even if they aren't in your clique
    if (potential-partner = nobody)
    [
      set potential-partner (min-one-of (females with [not link-neighbor? myself and not coupled?]) [distance myself])
      set coupling-probability out-group-probability
    ]
  ]
  
  ;; Female agent - wants to find a male potential partner
  [
    ;; First check out existing male friends
    set potential-partner (one-of males with [friend-neighbor? myself and not coupled?])
    set coupling-probability friend-probability
    
    ;; If that wasn't successful,
    ;; try to find a male within her clique that is not a current friend/link
    if (potential-partner = nobody)
    [
      set potential-partner
      (one-of males with [not link-neighbor? myself and not coupled? and group-membership = groupID])
      set coupling-probability in-group-probability
    ]
    
    ;; As a last resort,
    ;; look for the closest male that is not a link, even if they aren't in your clique
    if (potential-partner = nobody)
    [
      set potential-partner
      (min-one-of (males with [not link-neighbor? myself and not coupled?]) [distance myself])
      set coupling-probability out-group-probability
    ]
  ]
  
  ;; Finally, if they found a person who meets the above criteria,
  ;; Determine if potential partner is willing to couple with them
  if potential-partner != nobody
    [
      ;; Use coupling-probability to impact chance of successfully forming relationship
      ;; Highest likelihood if agents were already friends, lowest likelihood if agents weren't from same clique
      
       if ( (random-float 1.0 < coupling-probability) and   
          (random-float max-coupling-factor < [coupling-tendency] of potential-partner) )
        [
          set partner potential-partner
          set coupled? true
          ask partner
          [
            set partner myself
            set coupled? true
          ]
          
          ;; Change breed of link if friends,
          ;; and create link for sexual relationship regardless
          if (friend-neighbor? partner) [ask friend-with partner [die] ]
          create-sexual-partner-with partner [ assign-link-color]
        ]
    ]
end 


;;
;; If two persons are together for longer than either person's
;; commitment variable allows, the couple breaks up.
;;

to uncouple ;; turtle procedure (coupled turtles only)
  if coupled?
  [
    if (couple-length > commitment) or
      ([couple-length] of partner) > ([commitment] of partner)
      [
        ;; Break the link between these two turtles
        ;; assume they don't go back to being friends
        ask sexual-partner-with partner [die]
        
        ;; but if you wanted them to "just be friends"... uncomment line below
        ;create-friend-with partner [ assign-link-color]
        
        set coupled? false
        set couple-length 0
        ask partner
        [
          set couple-length 0
          set partner nobody
          set coupled? false
        ]
        set partner nobody
      ]
  ]
end 


;;; --------------------------------------------------------------------- ;;;
;;;
;;; INFECTING PROCEDURES 
;;;
;;; --------------------------------------------------------------------- ;;;

;;
;; Turtle becomes infected
;;

to become-infected ;; turtle procedure
  set infected? true
  assign-shape ;; infected turtles have a dot on their shape
  
  ; Note that the turtle will not "know" they are infected
  ; (and set the known? variable) until check-infected is called
end 


;;---------------------------------------------------------------------

;; In the next two procedures, users can infect an agent in the model
;; infect-random will choose a random agent, while select allows the 
;; user to choose an agent to infect with the mouse.
;; At least one function should be used at the beginning of the model run,
;; but they can be called at any time during the simulation

;; Note that in both of these procedures, the infected agent 
;; will not "know" they are infected until check-infected is called,
;; and even then, they will only be aware of their infected state
;; if his/her gender is symptomatic.

;; By doing it this way, the agents have a chance to spread the STI
;; before they realize they are infected

;;
;; Infect a random turtle (can do multiple times, if user wishes)
;;

to infect-random
  infect-random-female
  infect-random-male
  ;if (count turtles > 1)
  ;[
  ;  ask n-of 1 turtles with [not infected?]
  ;  [ become-infected ]
  ;]
end 

to infect-random-female
  if (count females > 1)
  [
    ask n-of 1 females with [not infected?]
    [ become-infected ]
  ]
end 

to infect-random-male
  if (count males > 1)
  [
    ask n-of 1 males with [not infected?]
    [ become-infected ]
  ]
end 

;;
;; User selects an agent in the model to infect with the mouse
;;

to select
  let picked? false
  if mouse-down?
  [
    let candidate min-one-of turtles [distancexy mouse-xcor mouse-ycor]
    if [distancexy mouse-xcor mouse-ycor] of candidate < 1
    [
        ask candidate
        [
          become-infected
          set picked? true
        ]
    ]
  ]
  if picked? [stop]
end 


;;; --------------------------------------------------------------------- ;;;
;;;
;;; CHECK-INFECTED PROCEDURE
;;;
;;; --------------------------------------------------------------------- ;;;

;;---------------------------------------------------------------------
;;
;; Turtle checks for signs of infection (symptoms)
;; Ideally don't want check-infect and become-infected happening on same tick
;; --> not realistic, std symptoms don't instantly show up
;; Otherwise, if not symptomatic, don't change their known? variable
;;

to check-infected
 
  ;; Justification decreases when an agent thinks they had unsafe sex 
  ;; and observes no negative consequences (i.e. didn't contract an STI,
  ;; or doesn't feel symptoms, regardless of whether s/he is actually infected).
  
  if ( had-unsafe-sex? and ( not infected? or
     (is-male? self and not males-symptomatic?) or
     (is-female? self and not females-symptomatic?) )
     )
  [ set justification (justification - justification-delta) ]

    
  ;; If an agent is infected and realizes it (due to being symptomatic)
  ;; Their likelihood of practicing safe sex increases significantly,
  ;; since we assume that agents are not malicious and intentionally infecting others
  
  if ((infected? and not known?) and
    ((is-male? self and males-symptomatic?) or
    (is-female? self and females-symptomatic?)))
  [
    set known? true
    set justification 100 ;; after getting an std, turtles always want to have safe sex - logical reason
    ;; direct experience is always more powerful at changing attitude than just talking about it
    set attitude 100 ;; also set their attitude towards safe sex to 100% positive
  ]
  
  update-safe-sex-likelihood 
  assign-turtle-color
  assign-shape ;; color of dot changes based on whether the agent knows they are infected
end 


;;; --------------------------------------------------------------------- ;;;
;;;
;;; REPORTER / MONITOR PROCEDURES
;;;
;;; --------------------------------------------------------------------- ;;;

to-report num-infected
  report count turtles with [infected?]
end 

to-report %infected
  ifelse any? turtles
    [ report 100 * num-infected / count turtles ]
    [ report 0 ]
end 

to-report %F-infected
  ifelse any? females
  [ report 100 * count females with [infected?] / count females]
  [ report 0 ]
end 

to-report %M-infected
  ifelse any? males
  [ report 100 * count males with [infected?] / count males]
  [ report 0 ]
end 


;; ----- Reporters for safe-sex-attitude measures ----- ;;

;; --------------- Safe sex likelihood  --------------- ;;
;; ------------- (condom use probability) ------------- ;;

to-report avg-safe-sex-likelihood
  report mean [safe-sex-likelihood] of turtles
end 

to-report avg-male-safe-sex-likelihood
  report mean [safe-sex-likelihood] of males
end 

to-report avg-female-safe-sex-likelihood
  report mean [safe-sex-likelihood] of females
end 

  ;; Determine how much this agent's likelihood of practicing safe sex
  ;; has changed since last tick.
  ;; (If likelihoods of all agents stop changing significantly,
  ;; the simulation will stop.)

;; --------------- Attitude --------------- ;;

to-report avg-attitude
  report mean [attitude] of turtles
end 

to-report avg-male-attitude
  report mean [attitude] of males
end 

to-report avg-female-attitude
  report mean [attitude] of females
end 

;; --------------- Certainty --------------- ;;

to-report avg-certainty
  report mean [certainty] of turtles
end 

to-report avg-male-certainty
  report mean [certainty] of males
end 

to-report avg-female-certainty
  report mean [certainty] of females
end 

;; --------------- Justification --------------- ;;

to-report avg-justification
  report mean [justification] of turtles
end 

to-report avg-male-justification
  report mean [justification] of males
end 

to-report avg-female-justification
  report mean [justification] of females
end 

;;
;; Not all reporters need be displayed in the model (to avoid information overload),
;; but readily available if the user wishes to add monitors
;; to view additional demographic information
;;

;; Begin somewhat unnecessary reporters that were at one point used for debugging-ish


;; --------------- Change in likelihood between ticks --------------- ;;

;; Note: take absolute value, otherwise if some turtles are
;; very positively increasing and others are very negatively decreasing,
;; could result in calculating like there is no change occurring

to-report avg-likelihood-change
  report mean [ abs (safe-sex-likelihood - old-safe-sex-likelihood)] of turtles
end 

to-report avg-male-likelihood-change
  report mean [abs (safe-sex-likelihood - old-safe-sex-likelihood)] of males
end 

to-report avg-female-likelihood-change
  report mean [abs (safe-sex-likelihood - old-safe-sex-likelihood)] of females
end 

;; originally used above measures for a plot,
;; but it wasn't very interesting given the space it took up

to-report avg-friends-per-turtle
  report mean [count friend-neighbors] of turtles
end 

to-report avg-partners-per-turtle
  report mean [count sexual-partner-neighbors] of turtles
end 

to-report num-in-group-friends
  report count friends with [
    ([group-membership] of end1 = [group-membership] of end2 )]
end 

to-report num-out-group-friends
  report count friends with [
    ([group-membership] of end1 != [group-membership] of end2 )]
end 

to-report num-in-group-partners
  report count sexual-partners with [
    ([group-membership] of end1 = [group-membership] of end2 )]
end 

to-report num-out-group-partners
  report count sexual-partners with [
    ([group-membership] of end1 != [group-membership] of end2 )]
end 

There are 5 versions of this model.

Uploaded by When Description Download
Lizz B over 11 years ago Finalized version Download this version
Lizz B over 11 years ago documentation is not fully complete, but functionality works as intended Download this version
Lizz B over 11 years ago week 3 update Download this version
Lizz B over 11 years ago Information and next steps included in info tab, currently not much beyond Virus or AIDS model behaviors. Download this version
Lizz B over 11 years ago Initial upload Download this version

Attached files

File Type Description Last updated
bartos 372 final proposal.docx word Initial final project proposal over 11 years ago, by Lizz B Download
bartos-eecs372-poster-slides.pptx powerpoint Poster slides over 11 years ago, by Lizz B Download
bartos_eecs372_safe-sex-attitudes-and-behaviors_final-paper-dblspce.docx word Final paper for eecs372 spring 13 - same as other one, but this one is double space instead of 1.5 spacing over 11 years ago, by Lizz B Download
bartos_eecs372_safe-sex-attitudes-and-behaviors_final-paper.docx word Final paper for eecs372 spring 13 over 11 years ago, by Lizz B Download
bartos_lizz_slam.pptx powerpoint Poster slam slides - has been revised considerably since this interface, though over 11 years ago, by Lizz B Download
lizzBartos_May13.docx word Progress report - may 13 over 11 years ago, by Lizz B Download
lizzBartos_May20.docx word Progress report - May 20 over 11 years ago, by Lizz B Download
Safe Sex Attitudes and Behaviors.png preview Preview for 'Safe Sex Attitudes and Behaviors' over 11 years ago, by Lizz B Download
Safe Sex Attitudes and Behaviors.png preview attempt to replace that black box with an image over 11 years ago, by Lizz B Download
Safe Sex Attitudes and Behaviors.png preview another attempt at replacing that black preview box over 11 years ago, by Lizz B Download

This model does not have any ancestors.

This model does not have any descendants.