mercredi 25 juillet 2018

Using nested if or ifelse in Netlogo to specify probabilities

I am having trouble using nested ifs in Netlogo to specify deer reproductive probabilities. Here is what I have come up with so far:

to reproduce-adult
let chance-fawn random-float 1.001
let chance-to-reproduce .9 
let chance-for-one .3 
let chance-for-two .4 
let chance-for-three .02
  if any? femadults [
    ask femadults [
  if random-float 1.001 < chance-to-reproduce [
    if chance-fawn < chance-for-three
    [set births (births + 3)
      let new-offspring nobody
      hatch-infants 3
      [set new-offspring self set color red - 1 set size 1]
      set offspring new-offspring]
    if chance-fawn > chance-for-two
    [set births (births + 2)
      let new-offspring nobody
      hatch-infants 2
      [set new-offspring self set color red - 1 set size 1]
      set offspring new-offspring]
    if (chance-fawn > .02) and (chance-fawn < chance-for-one)
    [set births (births + 1)
      let new-offspring nobody
      hatch-infants 1
      [set new-offspring self set color red - 1 set size 1]
      set offspring new-offspring]
     ]]]
   end

Basically, the chance of a doe getting pregnant is 90%. So I want that if the doe gets pregnant, she either has 1, 2 or 3 fawns. The chance of having 1 fawn is 28%. The chance of having 2 fawns is 60%. The chance of having 3 fawns is 2%. The problem with my current code is that if "chance-fawn" is between .3 and .4, it is not accounted for in the if statements, when it should be part of the 60% of having 2 fawns. Is there a better way to do this, using either if statements or something else? Thank you!

Aucun commentaire:

Enregistrer un commentaire