0

this is related to my previous question

I have created a list for each turtle with three elements (opinion1 opinion2 opinion3). Each of these elements is in the [-1 ; +1] range (three random values for each turtles).

What I'd like now is to have a plot with 3 downward-sloping curves reflecting the amount of turtles that have at least a given opinion. That is to say, if I have 100 turtles then -1 has 100 occurences and +2 has zero. I have thus far managed to create a histogram of opinions with

set-current-plot "opinion distribution"
set-histogram-num-bars 10
histogram [sum opinions] of turtles

Which gives enter image description here but this is not really what I am after because (1) I put all three opinions together whereas I'd like them separate and (2) it is not the downward-sloping line I am after that reflects cumulative frequency instead of absolute.

Any help is appreciated as always!


After LukeC's comment, I add a picture to try and make my graph goal clearer

enter image description here

lomper
  • 379
  • 1
  • 12

1 Answers1

0

Can you provide more detail or an example of what your plot should look like? I'm not really sure what you're trying to tally here- are you trying to check the count of turtles that have one of those opinions as their lowest opinion? If so, this may approach what you're trying to do. With this setup and toy go procedure to modify turtle opinions:

turtles-own [ opinions ]

to setup
  ca
  crt 100 [
    set opinions n-values 3 [ random 3 - 1 ]
  ]
  reset-ticks
end


to go
  ask turtles [
    let i one-of [ 0 1 2 ] 
    let my-opinion item i opinions
    let greater one-of other turtles with [
      item i opinions > my-opinion 
    ] 
    if greater != nobody [
      set opinions replace-item i opinions [ item i opinions ] of greater
    ]
  ]  
  tick
end

You can make reporters to return whatever value you need. Here, I've made three binning reporters that just count the number of turtles with the three possible values as their minimum value of the opinions list:

to-report bin-1
  report count turtles with [ min opinions = -1  ]
end

to-report bin-2
  report count turtles with [ min opinions = 0 ]
end

to-report bin-3
  report count turtles with [ min opinions = 1 ]
end

If you plot those reporters (eg with a plot pen calling plot bin-1) you'll get something like:

enter image description here

Is that sort of on the right track? If not, could you flesh out a little more what you're expecting the plot to look like over time?

Luke C
  • 10,081
  • 1
  • 14
  • 21
  • Hi @Luke C, Yes, I realize it is not clear enough, but what I am trying is not to plot against time but against opinion. I have added a picture of what I am aiming for using your vector of opinions (each from -1 to + 2), not sure it'll be clearer. It is sort of a demand curve, where I plot all turtles with *at least* a given opinion (and so it goes from n (100) on the top left to zero on the bottom right... – lomper Apr 12 '19 at 07:53
  • @lomper - Great, thanks for the added detail. Just to clarify- my vector was meant to be like yours, from -1 to 1 inclusive but I doubt that affects the figure you uploaded. Also- you're still after 3 lines, is that correct? – Luke C Apr 12 '19 at 07:57
  • @lomper - Ok so I'm still having trouble wrapping my brain around this, sorry! If a turtle has anywhere within its `opinions` list, the opinion of -1, it should be counted in the -1 space? What does each line track? – Luke C Apr 12 '19 at 08:29
  • Actually each item on the opinions list is a continuous variable produced with ```random-float 2 - 1```. So the line that tracks the first item of the list will plot all turtles with ```item 1 opinions < x``` (x being the x-coordinate on the graph). Any clearer? – lomper Apr 12 '19 at 13:06
  • there's this model that does something related to what I am after, although unfortunately I do not get to see the plots when I run it on my computer (and it doesn't work at all on NetLogo web): http://ccl.northwestern.edu/netlogo/models/community/MinimumWages What they use is ```foreach sort-by [ [expectedExpense] of ?1 > [expectedExpense] of ?2 ] employers [ plot [expectedExpense] of ? ]```, where I guess ```expectetdExpense``` could be replaced by ```opinions```but it doesn't work on NetLogo 6.0.4. I don't know if you'd be able to tweak that but thanks at any rate! – lomper Apr 12 '19 at 15:53