Mercurial > repos > greg > insect_phenology_model
comparison insect_phenology_model.R @ 92:fdc148a9695a draft
Uploaded
author | greg |
---|---|
date | Fri, 01 Dec 2017 09:38:04 -0500 |
parents | b6b42e12e173 |
children | 06acadd38824 |
comparison
equal
deleted
inserted
replaced
91:b6b42e12e173 | 92:fdc148a9695a |
---|---|
211 # TODO: user definable as well? | 211 # TODO: user definable as well? |
212 num_insects <- 1000 | 212 num_insects <- 1000 |
213 # Generation, Stage, degree-days, T, Diapause. | 213 # Generation, Stage, degree-days, T, Diapause. |
214 vec.ini <- c(0, 3, 0, 0, 0) | 214 vec.ini <- c(0, 3, 0, 0, 0) |
215 # Overwintering, previttelogenic, degree-days=0, T=0, no-diapause. | 215 # Overwintering, previttelogenic, degree-days=0, T=0, no-diapause. |
216 vec.mat <- rep(vec.ini, n) | 216 vec.mat <- rep(vec.ini, num_insects) |
217 # Complete matrix for the population. | 217 # Complete matrix for the population. |
218 vec.mat <- base::t(matrix(vec.mat, nrow=5)) | 218 vec.mat <- base::t(matrix(vec.mat, nrow=5)) |
219 # Time series of population size. | 219 # Time series of population size. |
220 tot.pop <- NULL | 220 tot.pop <- NULL |
221 gen0.pop <- rep(0, opt$num_days) | 221 gen0.pop <- rep(0, opt$num_days) |
238 # Trash bin for death. | 238 # Trash bin for death. |
239 death.vec <- NULL | 239 death.vec <- NULL |
240 # Newborn. | 240 # Newborn. |
241 birth.vec <- NULL | 241 birth.vec <- NULL |
242 # All individuals. | 242 # All individuals. |
243 for (i in 1:n) { | 243 for (i in 1:num_insects) { |
244 # Find individual record. | 244 # Find individual record. |
245 vec.ind <- vec.mat[i,] | 245 vec.ind <- vec.mat[i,] |
246 # First of all, still alive? | 246 # First of all, still alive? |
247 # Adjustment for late season mortality rate. | 247 # Adjustment for late season mortality rate. |
248 if (latitude < 40.0) { | 248 if (latitude < 40.0) { |
455 vec.mat <- rbind(vec.mat, birth.vec) | 455 vec.mat <- rbind(vec.mat, birth.vec) |
456 # Update population size for the next day. | 456 # Update population size for the next day. |
457 num_insects <- num_insects - num_insects.death + num_insects.newborn | 457 num_insects <- num_insects - num_insects.death + num_insects.newborn |
458 | 458 |
459 # Aggregate results by day. | 459 # Aggregate results by day. |
460 tot.pop <- c(tot.pop, n) | 460 tot.pop <- c(tot.pop, num_insects) |
461 # Egg. | 461 # Egg. |
462 s0 <- sum(vec.mat[,2] == 0) | 462 s0 <- sum(vec.mat[,2] == 0) |
463 # Young nymph. | 463 # Young nymph. |
464 s1 <- sum(vec.mat[,2] == 1) | 464 s1 <- sum(vec.mat[,2] == 1) |
465 # Old nymph. | 465 # Old nymph. |