1

I have a model where the male turtles get classified according to a threshold as follows:

    ifelse(condition > threshold)  [set status 0 ] [set status 1] 

I want to count the potential male mates of each of the females in the population who meet this threshold. I've coded it so the females are limited to having a 10-patch radius of detection. If there are no males that meet this threshold then FR should be 0 otherwise it should be a proportion.

      ask turtles with [sex = "female"] [if any? turtles with [sex = "male"] 
      in-radius 10 [ set potentialMates turtles with [sex = "male"] in-radius 10]
        ifelse any?  potentialMates with [anadromousM = 1] 
        [set FR count potentialMates with [anadromousM = 1] / count potentialMates ]
        [set FR 0]]

When I run this I get the error for the second any?

ANY? expected input to be an agentset but got the number 0 instead.

Where am I going wrong? Hope you can help.

adkane
  • 1,429
  • 14
  • 29

1 Answers1

3

This is easier to see with different indenting. The following is your code (wrapped in a procedure name).

to find-mate
  ask turtles with [sex = "female"]
  [ if any? turtles with [sex = "male"] in-radius 10
    [ set potentialMates turtles with [sex = "male"] in-radius 10
    ]
    ifelse any? potentialMates with [anadromousM = 1] 
    [ set FR count potentialMates with [anadromousM = 1] / count potentialMates ]
    [ set FR 0]
  ]
end

As you can see, the ifelse is tested (for each female turtle) regardless of the outcome of if any? turtles with [sex = "male"] in-radius 10. Imagine this first if is false, then the potentialMates agentset never gets created with the male turtles. Hence the error. You haven't shown us the code where pontentialMates is first instantiated - assuming it is a global variable, then it will have the value 0.

I think you want FR to be 0 in the case where there are no males in the radius at all. In that case, try this.

to find-mate
  ask turtles with [sex = "female"]
  [ ifelse any? turtles with [sex = "male"] in-radius 10
    [ set potentialMates turtles with [sex = "male"] in-radius 10
      set FR count potentialMates with [anadromousM = 1] / count potentialMates
    ]
    [ set FR 0]
  ]
end

If there's no potentialMates with anadromousM = 1 then the numerator is 0 anyway, and 0/N is 0.

JenB
  • 17,620
  • 2
  • 17
  • 45
  • Hi, thanks for your response. `potentialMates` is a `turtles-own` variable – adkane May 30 '18 at 14:47
  • In that case, it is created when the turtle is created and is given the value 0 (which is NetLogo's default variable value). I will update the answer. – JenB May 30 '18 at 15:30