-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmoth.R
More file actions
29 lines (26 loc) · 1.12 KB
/
moth.R
File metadata and controls
29 lines (26 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
mothGeneration <- function(reproductiveFemales, fecundity, femaleProb, hatchProb, pupateProb, ecloseProb, repProb){
eggs <- sum(rpois(reproductiveFemales, fecundity))
femaleEggs <- rbinom(n=1, size=eggs, prob=femaleProb)
femaleLarvae <- rbinom(n=1, size=femaleEggs, prob=hatchProb)
femalePupae <- rbinom(n=1, size=femaleLarvae, prob=pupateProb)
femaleAdults <- rbinom(n=1, size=femalePupae, prob=ecloseProb)
newReproductiveFemales <- rbinom(n=1, size=femaleAdults, prob=repProb)
return(c(reproductiveFemales=reproductiveFemales
, eggs=eggs
, femaleEggs=femaleEggs
, femaleLarvae=femaleLarvae
, femalePupae=femalePupae
, femaleAdults=femaleAdults
, newReproductiveFemales=newReproductiveFemales
))
}
mothSimulation <- function(reproductiveFemales, fecundity, femaleProb, hatchProb, pupateProb, ecloseProb, repProb, numYears){
years <- 1:numYears
for (y in years){
sim <- mothGeneration(reproductiveFemales[[y]], fecundity,
femaleProb, hatchProb, pupateProb, ecloseProb, repProb)
reproductiveFemales <- c(reproductiveFemales,
sim[["newReproductiveFemales"]])
}
plot(c(0, years), reproductiveFemales, type="b")
}