Mercurial > repos > greg > insect_phenology_model
comparison insect_phenology_model.R @ 103:4d9e40d8af0f draft
Uploaded
author | greg |
---|---|
date | Tue, 05 Dec 2017 11:01:23 -0500 |
parents | ce996e90f5a7 |
children | d6e37828b094 |
comparison
equal
deleted
inserted
replaced
102:ce996e90f5a7 | 103:4d9e40d8af0f |
---|---|
81 # Maximum temperature for current row. | 81 # Maximum temperature for current row. |
82 curr_max_temp <- temperature_data_frame$TMAX[row] | 82 curr_max_temp <- temperature_data_frame$TMAX[row] |
83 # Mean temperature for current row. | 83 # Mean temperature for current row. |
84 curr_mean_temp <- 0.5 * (curr_min_temp + curr_max_temp) | 84 curr_mean_temp <- 0.5 * (curr_min_temp + curr_max_temp) |
85 # Initialize degree day accumulation | 85 # Initialize degree day accumulation |
86 degree_days <- 0 | 86 averages <- 0 |
87 if (curr_max_temp < threshold) { | 87 if (curr_max_temp < threshold) { |
88 degree_days <- 0 | 88 averages <- 0 |
89 } | 89 } |
90 else { | 90 else { |
91 # Initialize hourly temperature. | 91 # Initialize hourly temperature. |
92 T <- NULL | 92 T <- NULL |
93 # Initialize degree hour vector. | 93 # Initialize degree hour vector. |
136 else { | 136 else { |
137 dh[i] <- T[i] - 8.4 | 137 dh[i] <- T[i] - 8.4 |
138 } | 138 } |
139 } | 139 } |
140 } | 140 } |
141 degree_days <- sum(dh) / 24 | 141 averages <- sum(dh) / 24 |
142 } | 142 } |
143 return(c(curr_mean_temp, degree_days)) | 143 return(c(curr_mean_temp, averages)) |
144 } | 144 } |
145 | 145 |
146 mortality.adult = function(temperature) { | 146 mortality.adult = function(temperature) { |
147 if (temperature < 12.7) { | 147 if (temperature < 12.7) { |
148 mortality.probability = 0.002 | 148 mortality.probability = 0.002 |
195 | 195 |
196 render_chart = function(chart_type, insect, location, latitude, start_date, end_date, days, maxval, plot_std_error, | 196 render_chart = function(chart_type, insect, location, latitude, start_date, end_date, days, maxval, plot_std_error, |
197 group1, group2, group3, group1_std_error, group2_std_error, group3_std_error) { | 197 group1, group2, group3, group1_std_error, group2_std_error, group3_std_error) { |
198 if (chart_type == "pop_size_by_life_stage") { | 198 if (chart_type == "pop_size_by_life_stage") { |
199 title <- paste(insect, ": Total pop. by life stage :", location, ": Lat:", latitude, ":", start_date, "-", end_date, sep=" ") | 199 title <- paste(insect, ": Total pop. by life stage :", location, ": Lat:", latitude, ":", start_date, "-", end_date, sep=" ") |
200 legend("topleft", c("Egg", "Nymph", "Adult"), lty=c(1, 1, 1), col=c(4, 2, 1), cex=3) | 200 legend_text <- c("Egg", "Nymph", "Adult") |
201 columns <- c(4, 2, 1) | |
201 } else if (chart_type == "pop_size_by_generation") { | 202 } else if (chart_type == "pop_size_by_generation") { |
202 title <- paste(insect, ": Total pop. by generation :", location, ": Lat:", latitude, ":", start_date, "-", end_date, sep=" ") | 203 title <- paste(insect, ": Total pop. by generation :", location, ": Lat:", latitude, ":", start_date, "-", end_date, sep=" ") |
203 legend("topleft", c("P", "F1", "F2"), lty=c(1, 1, 1), col=c(1, 2, 4), cex=3) | 204 legend_text <- c("P", "F1", "F2") |
205 columns <- col=c(1, 2, 4) | |
204 } else if (chart_type == "adult_pop_size_by_generation") { | 206 } else if (chart_type == "adult_pop_size_by_generation") { |
205 title <- paste(insect, ": Adult pop. by generation :", location, ": Lat:", latitude, ":", start_date, "-", end_date, sep=" ") | 207 title <- paste(insect, ": Adult pop. by generation :", location, ": Lat:", latitude, ":", start_date, "-", end_date, sep=" ") |
206 legend("topleft", c("P", "F1", "F2"), lty=c(1, 1, 1), col=c(1, 2, 4), cex=3) | 208 legend_text <- c("P", "F1", "F2") |
209 columns <- col=c(1, 2, 4) | |
207 } | 210 } |
208 plot(days, group1, main=title, type="l", ylim=c(0, maxval), axes=F, lwd=2, xlab="", ylab="", cex=3, cex.lab=3, cex.axis=3, cex.main=3) | 211 plot(days, group1, main=title, type="l", ylim=c(0, maxval), axes=F, lwd=2, xlab="", ylab="", cex=3, cex.lab=3, cex.axis=3, cex.main=3) |
212 legend("topleft", legend_text, lty=c(1, 1, 1), columns, cex=3) | |
209 lines(days, group2, lwd=2, lty=1, col=2) | 213 lines(days, group2, lwd=2, lty=1, col=2) |
210 lines(days, group3, lwd=2, lty=1, col=4) | 214 lines(days, group3, lwd=2, lty=1, col=4) |
211 axis(1, at=c(1:12) * 30 - 15, cex.axis=3, labels=c("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")) | 215 axis(1, at=c(1:12) * 30 - 15, cex.axis=3, labels=c("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")) |
212 axis(2, cex.axis=3) | 216 axis(2, cex.axis=3) |
213 if (plot_std_error==1) { | 217 if (plot_std_error==1) { |
235 YoungNymphs.replications <- matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications) | 239 YoungNymphs.replications <- matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications) |
236 OldNymphs.replications <- matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications) | 240 OldNymphs.replications <- matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications) |
237 Previtellogenic.replications <- matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications) | 241 Previtellogenic.replications <- matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications) |
238 Vitellogenic.replications <- matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications) | 242 Vitellogenic.replications <- matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications) |
239 Diapausing.replications <- matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications) | 243 Diapausing.replications <- matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications) |
244 | |
240 newborn.replications <- matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications) | 245 newborn.replications <- matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications) |
246 adult.replications <- matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications) | |
241 death.replications <- matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications) | 247 death.replications <- matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications) |
242 adult.replications <- matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications) | 248 |
249 P.replications <- matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications) | |
250 P_adults.replications <- matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications) | |
251 F1.replications <- matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications) | |
252 F1_adults.replications <- matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications) | |
253 F2.replications <- matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications) | |
254 F2_adults.replications <- matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications) | |
255 | |
243 population.replications <- matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications) | 256 population.replications <- matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications) |
244 P.replications <- matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications) | |
245 F1.replications <- matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications) | |
246 F2.replications <- matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications) | |
247 P_adults.replications <- matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications) | |
248 F1_adults.replications <- matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications) | |
249 F2_adults.replications <- matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications) | |
250 | 257 |
251 # Process replications. | 258 # Process replications. |
252 for (N.replications in 1:opt$replications) { | 259 for (N.replications in 1:opt$replications) { |
253 # During each replication start with 1000 individuals. | 260 # During each replication start with 1000 individuals. |
254 # TODO: user definable as well? | 261 # TODO: user definable as well? |
258 # Overwintering, previttelogenic, degree-days=0, T=0, no-diapause. | 265 # Overwintering, previttelogenic, degree-days=0, T=0, no-diapause. |
259 vector.matrix <- rep(vector.ini, num_insects) | 266 vector.matrix <- rep(vector.ini, num_insects) |
260 # Complete matrix for the population. | 267 # Complete matrix for the population. |
261 vector.matrix <- base::t(matrix(vector.matrix, nrow=5)) | 268 vector.matrix <- base::t(matrix(vector.matrix, nrow=5)) |
262 # Time series of population size. | 269 # Time series of population size. |
263 total.population <- NULL | |
264 overwintering_adult.population <- rep(0, opt$num_days) | |
265 first_generation.population <- rep(0, opt$num_days) | |
266 second_generation.population <- rep(0, opt$num_days) | |
267 Eggs <- rep(0, opt$num_days) | 270 Eggs <- rep(0, opt$num_days) |
268 YoungNymphs <- rep(0, opt$num_days) | 271 YoungNymphs <- rep(0, opt$num_days) |
269 OldNymphs <- rep(0, opt$num_days) | 272 OldNymphs <- rep(0, opt$num_days) |
270 Previtellogenic <- rep(0, opt$num_days) | 273 Previtellogenic <- rep(0, opt$num_days) |
271 Vitellogenic <- rep(0, opt$num_days) | 274 Vitellogenic <- rep(0, opt$num_days) |
272 Diapausing <- rep(0, opt$num_days) | 275 Diapausing <- rep(0, opt$num_days) |
276 | |
277 N.newborn <- rep(0, opt$num_days) | |
278 N.adult <- rep(0, opt$num_days) | |
279 N.death <- rep(0, opt$num_days) | |
280 | |
281 overwintering_adult.population <- rep(0, opt$num_days) | |
282 first_generation.population <- rep(0, opt$num_days) | |
283 second_generation.population <- rep(0, opt$num_days) | |
284 | |
273 P.adult <- rep(0, opt$num_days) | 285 P.adult <- rep(0, opt$num_days) |
274 F1.adult <- rep(0, opt$num_days) | 286 F1.adult <- rep(0, opt$num_days) |
275 F2.adult <- rep(0, opt$num_days) | 287 F2.adult <- rep(0, opt$num_days) |
276 N.newborn <- rep(0, opt$num_days) | 288 |
277 N.death <- rep(0, opt$num_days) | 289 total.population <- NULL |
278 N.adult <- rep(0, opt$num_days) | 290 |
279 degree_days.day <- rep(0, opt$num_days) | 291 averages.day <- rep(0, opt$num_days) |
280 # All the days included in the input temperature dataset. | 292 # All the days included in the input temperature dataset. |
281 for (row in 1:opt$num_days) { | 293 for (row in 1:opt$num_days) { |
282 # Get the integer day of the year for the current row. | 294 # Get the integer day of the year for the current row. |
283 doy <- temperature_data_frame$DOY[row] | 295 doy <- temperature_data_frame$DOY[row] |
284 # Photoperiod in the day. | 296 # Photoperiod in the day. |
285 photoperiod <- temperature_data_frame$DAYLEN[row] | 297 photoperiod <- temperature_data_frame$DAYLEN[row] |
286 temp.profile <- get_temperature_at_hour(latitude, temperature_data_frame, row, opt$num_days) | 298 temp.profile <- get_temperature_at_hour(latitude, temperature_data_frame, row, opt$num_days) |
287 mean.temp <- temp.profile[1] | 299 mean.temp <- temp.profile[1] |
288 degree_days.temp <- temp.profile[2] | 300 averages.temp <- temp.profile[2] |
289 degree_days.day[row] <- degree_days.temp | 301 averages.day[row] <- averages.temp |
290 # Trash bin for death. | 302 # Trash bin for death. |
291 death.vector <- NULL | 303 death.vector <- NULL |
292 # Newborn. | 304 # Newborn. |
293 birth.vector <- NULL | 305 birth.vector <- NULL |
294 # All individuals. | 306 # All individuals. |
295 for (i in 1:num_insects) { | 307 for (i in 1:num_insects) { |
296 # Find individual record. | 308 # Individual record. |
297 vector.individual <- vector.matrix[i,] | 309 vector.individual <- vector.matrix[i,] |
298 # First of all, still alive? | 310 # Adjustment for late season mortality rate (still alive?). |
299 # Adjustment for late season mortality rate. | |
300 if (latitude < 40.0) { | 311 if (latitude < 40.0) { |
301 post.mortality <- 1 | 312 post.mortality <- 1 |
302 day.kill <- 300 | 313 day.kill <- 300 |
303 } | 314 } |
304 else { | 315 else { |
311 } | 322 } |
312 else if (vector.individual[2] == 1 | vector.individual[2] == 2) { | 323 else if (vector.individual[2] == 1 | vector.individual[2] == 2) { |
313 death.probability = opt$nymph_mortality * mortality.nymph(mean.temp) | 324 death.probability = opt$nymph_mortality * mortality.nymph(mean.temp) |
314 } | 325 } |
315 else if (vector.individual[2] == 3 | vector.individual[2] == 4 | vector.individual[2] == 5) { | 326 else if (vector.individual[2] == 3 | vector.individual[2] == 4 | vector.individual[2] == 5) { |
316 # For adult. | 327 # Adult. |
317 if (doy < day.kill) { | 328 if (doy < day.kill) { |
318 death.probability = opt$adult_mortality * mortality.adult(mean.temp) | 329 death.probability = opt$adult_mortality * mortality.adult(mean.temp) |
319 } | 330 } |
320 else { | 331 else { |
321 # Increase adult mortality after fall equinox. | 332 # Increase adult mortality after fall equinox. |
322 death.probability = opt$adult_mortality * post.mortality * mortality.adult(mean.temp) | 333 death.probability = opt$adult_mortality * post.mortality * mortality.adult(mean.temp) |
323 } | 334 } |
324 } | 335 } |
325 # (or dependent on temperature and life stage?) | 336 # Dependent on temperature and life stage? |
326 u.d <- runif(1) | 337 u.d <- runif(1) |
327 if (u.d < death.probability) { | 338 if (u.d < death.probability) { |
328 death.vector <- c(death.vector, i) | 339 death.vector <- c(death.vector, i) |
329 } | 340 } |
330 else { | 341 else { |
331 # Aggregrate index of dead bug. | 342 # Aggregrate index of dead bug. |
332 # Event 1 end of diapause. | 343 # End of diapause. |
333 if (vector.individual[1] == 0 && vector.individual[2] == 3) { | 344 if (vector.individual[1] == 0 && vector.individual[2] == 3) { |
334 # Overwintering adult (previttelogenic). | 345 # Overwintering adult (previttelogenic). |
335 if (photoperiod > opt$photoperiod && vector.individual[3] > 68 && doy < 180) { | 346 if (photoperiod > opt$photoperiod && vector.individual[3] > 68 && doy < 180) { |
336 # Add 68C to become fully reproductively matured. | 347 # Add 68C to become fully reproductively matured. |
337 # Transfer to vittelogenic. | 348 # Transfer to vittelogenic. |
338 vector.individual <- c(0, 4, 0, 0, 0) | 349 vector.individual <- c(0, 4, 0, 0, 0) |
339 vector.matrix[i,] <- vector.individual | 350 vector.matrix[i,] <- vector.individual |
340 } | 351 } |
341 else { | 352 else { |
342 # Add to degree_days. | 353 # Add to # Add average temperature for current day.. |
343 vector.individual[3] <- vector.individual[3] + degree_days.temp | 354 vector.individual[3] <- vector.individual[3] + averages.temp |
344 # Add 1 day in current stage. | 355 # Add 1 day in current stage. |
345 vector.individual[4] <- vector.individual[4] + 1 | 356 vector.individual[4] <- vector.individual[4] + 1 |
346 vector.matrix[i,] <- vector.individual | 357 vector.matrix[i,] <- vector.individual |
347 } | 358 } |
348 } | 359 } |
354 # Transfer to vittelogenic. | 365 # Transfer to vittelogenic. |
355 vector.individual <- c(current.gen, 4, 0, 0, 0) | 366 vector.individual <- c(current.gen, 4, 0, 0, 0) |
356 vector.matrix[i,] <- vector.individual | 367 vector.matrix[i,] <- vector.individual |
357 } | 368 } |
358 else { | 369 else { |
359 # Add to degree_days. | 370 # Add average temperature for current day. |
360 vector.individual[3] <- vector.individual[3] + degree_days.temp | 371 vector.individual[3] <- vector.individual[3] + averages.temp |
361 # Add 1 day in current stage. | 372 # Add 1 day in current stage. |
362 vector.individual[4] <- vector.individual[4] + 1 | 373 vector.individual[4] <- vector.individual[4] + 1 |
363 vector.matrix[i,] <- vector.individual | 374 vector.matrix[i,] <- vector.individual |
364 } | 375 } |
365 } | 376 } |
376 u1 <- runif(1) | 387 u1 <- runif(1) |
377 if (u1 < p.birth) { | 388 if (u1 < p.birth) { |
378 num_insects.birth = round(runif(1, 2, 8)) | 389 num_insects.birth = round(runif(1, 2, 8)) |
379 } | 390 } |
380 } | 391 } |
381 # Add to degree_days. | 392 # Add average temperature for current day. |
382 vector.individual[3] <- vector.individual[3] + degree_days.temp | 393 vector.individual[3] <- vector.individual[3] + averages.temp |
383 # Add 1 day in current stage. | 394 # Add 1 day in current stage. |
384 vector.individual[4] <- vector.individual[4] + 1 | 395 vector.individual[4] <- vector.individual[4] + 1 |
385 vector.matrix[i,] <- vector.individual | 396 vector.matrix[i,] <- vector.individual |
386 if (num_insects.birth > 0) { | 397 if (num_insects.birth > 0) { |
387 # Add new birth -- might be in different generations. | 398 # Add new birth -- might be in different generations. |
408 u1 <- runif(1) | 419 u1 <- runif(1) |
409 if (u1 < p.birth) { | 420 if (u1 < p.birth) { |
410 num_insects.birth = round(runif(1, 2, 8)) | 421 num_insects.birth = round(runif(1, 2, 8)) |
411 } | 422 } |
412 } | 423 } |
413 # Add to degree_days. | 424 # Add average temperature for current day. |
414 vector.individual[3] <- vector.individual[3] + degree_days.temp | 425 vector.individual[3] <- vector.individual[3] + averages.temp |
415 # Add 1 day in current stage. | 426 # Add 1 day in current stage. |
416 vector.individual[4] <- vector.individual[4] + 1 | 427 vector.individual[4] <- vector.individual[4] + 1 |
417 vector.matrix[i,] <- vector.individual | 428 vector.matrix[i,] <- vector.individual |
418 if (num_insects.birth > 0) { | 429 if (num_insects.birth > 0) { |
419 # Add new birth -- might be in different generations. | 430 # Add new birth -- might be in different generations. |
429 } | 440 } |
430 # Event 3 development (with diapause determination). | 441 # Event 3 development (with diapause determination). |
431 # Event 3.1 egg development to young nymph (vector.individual[2]=0 -> egg). | 442 # Event 3.1 egg development to young nymph (vector.individual[2]=0 -> egg). |
432 if (vector.individual[2] == 0) { | 443 if (vector.individual[2] == 0) { |
433 # Egg stage. | 444 # Egg stage. |
434 # Add to degree_days. | 445 # Add average temperature for current day. |
435 vector.individual[3] <- vector.individual[3] + degree_days.temp | 446 vector.individual[3] <- vector.individual[3] + averages.temp |
436 if (vector.individual[3] >= (68+opt$young_nymph_accumulation)) { | 447 if (vector.individual[3] >= (68+opt$young_nymph_accumulation)) { |
437 # From egg to young nymph, degree-days requirement met. | 448 # From egg to young nymph, degree-days requirement met. |
438 current.gen <- vector.individual[1] | 449 current.gen <- vector.individual[1] |
439 # Transfer to young nymph stage. | 450 # Transfer to young nymph stage. |
440 vector.individual <- c(current.gen, 1, 0, 0, 0) | 451 vector.individual <- c(current.gen, 1, 0, 0, 0) |
446 vector.matrix[i,] <- vector.individual | 457 vector.matrix[i,] <- vector.individual |
447 } | 458 } |
448 # Event 3.2 young nymph to old nymph (vector.individual[2]=1 -> young nymph: determines diapause). | 459 # Event 3.2 young nymph to old nymph (vector.individual[2]=1 -> young nymph: determines diapause). |
449 if (vector.individual[2] == 1) { | 460 if (vector.individual[2] == 1) { |
450 # Young nymph stage. | 461 # Young nymph stage. |
451 # Add to degree_days. | 462 # Add average temperature for current day. |
452 vector.individual[3] <- vector.individual[3] + degree_days.temp | 463 vector.individual[3] <- vector.individual[3] + averages.temp |
453 if (vector.individual[3] >= (250+opt$old_nymph_accumulation)) { | 464 if (vector.individual[3] >= (250+opt$old_nymph_accumulation)) { |
454 # From young to old nymph, degree_days requirement met. | 465 # From young to old nymph, degree_days requirement met. |
455 current.gen <- vector.individual[1] | 466 current.gen <- vector.individual[1] |
456 # Transfer to old nym stage. | 467 # Transfer to old nym stage. |
457 vector.individual <- c(current.gen, 2, 0, 0, 0) | 468 vector.individual <- c(current.gen, 2, 0, 0, 0) |
466 vector.matrix[i,] <- vector.individual | 477 vector.matrix[i,] <- vector.individual |
467 } | 478 } |
468 # Event 3.3 old nymph to adult: previttelogenic or diapausing? | 479 # Event 3.3 old nymph to adult: previttelogenic or diapausing? |
469 if (vector.individual[2] == 2) { | 480 if (vector.individual[2] == 2) { |
470 # Old nymph stage. | 481 # Old nymph stage. |
471 # Add to degree_days. | 482 # Add average temperature for current day. |
472 vector.individual[3] <- vector.individual[3] + degree_days.temp | 483 vector.individual[3] <- vector.individual[3] + averages.temp |
473 if (vector.individual[3] >= (200+opt$adult_accumulation)) { | 484 if (vector.individual[3] >= (200+opt$adult_accumulation)) { |
474 # From old to adult, degree_days requirement met. | 485 # From old to adult, degree_days requirement met. |
475 current.gen <- vector.individual[1] | 486 current.gen <- vector.individual[1] |
476 if (vector.individual[5] == 0) { | 487 if (vector.individual[5] == 0) { |
477 # Non-diapausing adult -- previttelogenic. | 488 # Non-diapausing adult -- previttelogenic. |
488 } | 499 } |
489 vector.matrix[i,] <- vector.individual | 500 vector.matrix[i,] <- vector.individual |
490 } | 501 } |
491 # Event 4 growing of diapausing adult (unimportant, but still necessary). | 502 # Event 4 growing of diapausing adult (unimportant, but still necessary). |
492 if (vector.individual[2] == 5) { | 503 if (vector.individual[2] == 5) { |
493 vector.individual[3] <- vector.individual[3] + degree_days.temp | 504 vector.individual[3] <- vector.individual[3] + averages.temp |
494 vector.individual[4] <- vector.individual[4] + 1 | 505 vector.individual[4] <- vector.individual[4] + 1 |
495 vector.matrix[i,] <- vector.individual | 506 vector.matrix[i,] <- vector.individual |
496 } | 507 } |
497 } # Else if it is still alive. | 508 } # Else if it is still alive. |
498 } # End of the individual bug loop. | 509 } # End of the individual bug loop. |
542 N.death[row] <- num_insects.death | 553 N.death[row] <- num_insects.death |
543 # Adult population size. | 554 # Adult population size. |
544 N.adult[row] <- num_insects.adult | 555 N.adult[row] <- num_insects.adult |
545 } # End of days specified in the input temperature data. | 556 } # End of days specified in the input temperature data. |
546 | 557 |
547 degree_days.cum <- cumsum(degree_days.day) | 558 averages.cum <- cumsum(averages.day) |
548 | 559 |
549 # Define the output values. | 560 # Define the output values. |
550 Eggs.replications[,N.replications] <- Eggs | 561 Eggs.replications[,N.replications] <- Eggs |
551 YoungNymphs.replications[,N.replications] <- YoungNymphs | 562 YoungNymphs.replications[,N.replications] <- YoungNymphs |
552 OldNymphs.replications[,N.replications] <- OldNymphs | 563 OldNymphs.replications[,N.replications] <- OldNymphs |
563 P_adults.replications[,N.replications] <- P.adult | 574 P_adults.replications[,N.replications] <- P.adult |
564 F1_adults.replications[,N.replications] <- F1.adult | 575 F1_adults.replications[,N.replications] <- F1.adult |
565 F2_adults.replications[,N.replications] <- F2.adult | 576 F2_adults.replications[,N.replications] <- F2.adult |
566 } | 577 } |
567 | 578 |
579 # Mean value for eggs. | |
580 eggs <- apply(Eggs.replications, 1, mean) | |
581 # Standard error for eggs. | |
582 eggs.std_error <- apply(Eggs.replications, 1, sd) / sqrt(opt$replications) | |
583 | |
584 # Mean value for nymphs. | |
585 nymphs <- apply((YoungNymphs.replications+OldNymphs.replications), 1, mean) | |
586 # Standard error for nymphs. | |
587 nymphs.std_error <- apply((YoungNymphs.replications+OldNymphs.replications) / sqrt(opt$replications), 1, sd) | |
588 | |
568 # Mean value for adults. | 589 # Mean value for adults. |
569 adults <- apply((Previtellogenic.replications+Vitellogenic.replications+Diapausing.replications), 1, mean) | 590 adults <- apply((Previtellogenic.replications+Vitellogenic.replications+Diapausing.replications), 1, mean) |
570 # Mean value for nymphs. | 591 # Standard error for adults. |
571 nymphs <- apply((YoungNymphs.replications+OldNymphs.replications), 1, mean) | 592 adults.std_error <- apply((Previtellogenic.replications+Vitellogenic.replications+Diapausing.replications), 1, sd) / sqrt(opt$replications) |
572 # Mean value for eggs. | 593 |
573 eggs <- apply(Eggs.replications, 1, mean) | |
574 # Mean value for P. | 594 # Mean value for P. |
575 P <- apply(P.replications, 1, mean) | 595 P <- apply(P.replications, 1, mean) |
596 # Standard error for P. | |
597 P.std_error <- apply(P.replications, 1, sd) / sqrt(opt$replications) | |
598 | |
599 # Mean value for P adults. | |
600 P_adults <- apply(P_adults.replications, 1, mean) | |
601 # Standard error for P_adult. | |
602 P_adults.std_error <- apply(P_adults.replications, 1, sd) / sqrt(opt$replications) | |
603 | |
576 # Mean value for F1. | 604 # Mean value for F1. |
577 F1 <- apply(F1.replications, 1, mean) | 605 F1 <- apply(F1.replications, 1, mean) |
606 # Standard error for F1. | |
607 F1.std_error <- apply(F1.replications, 1, sd) / sqrt(opt$replications) | |
608 | |
609 # Mean value for F1 adults. | |
610 F1_adults <- apply(F1_adults.replications, 1, mean) | |
611 # Standard error for F1 adult. | |
612 F1_adults.std_error <- apply(F1_adults.replications, 1, sd) / sqrt(opt$replications) | |
613 | |
578 # Mean value for F2. | 614 # Mean value for F2. |
579 F2 <- apply(F2.replications, 1, mean) | 615 F2 <- apply(F2.replications, 1, mean) |
580 # Mean value for P adults. | 616 # Standard error for F2. |
581 P_adults <- apply(P_adults.replications, 1, mean) | 617 F2.std_error <- apply(F2.replications, 1, sd) / sqrt(opt$replications) |
582 # Mean value for F1 adults. | 618 |
583 F1_adults <- apply(F1_adults.replications, 1, mean) | |
584 # Mean value for F2 adults. | 619 # Mean value for F2 adults. |
585 F2_adults <- apply(F2_adults.replications, 1, mean) | 620 F2_adults <- apply(F2_adults.replications, 1, mean) |
586 # Standard error for adults. | |
587 adults.std_error <- apply((Previtellogenic.replications+Vitellogenic.replications+Diapausing.replications), 1, sd) / sqrt(opt$replications) | |
588 # Standard error for nymphs. | |
589 nymphs.std_error <- apply((YoungNymphs.replications+OldNymphs.replications) / sqrt(opt$replications), 1, sd) | |
590 # Standard error for eggs. | |
591 eggs.std_error <- apply(Eggs.replications, 1, sd) / sqrt(opt$replications) | |
592 # Standard error value for P. | |
593 P.std_error <- apply(P.replications, 1, sd) / sqrt(opt$replications) | |
594 # Standard error for F1. | |
595 F1.std_error <- apply(F1.replications, 1, sd) / sqrt(opt$replications) | |
596 # Standard error for F2. | |
597 F2.std_error <- apply(F2.replications, 1, sd) / sqrt(opt$replications) | |
598 # Standard error for P adult. | |
599 P_adults.std_error <- apply(P_adults.replications, 1, sd) / sqrt(opt$replications) | |
600 # Standard error for F1 adult. | |
601 F1_adults.std_error <- apply(F1_adults.replications, 1, sd) / sqrt(opt$replications) | |
602 # Standard error for F2 adult. | 621 # Standard error for F2 adult. |
603 F2_adults.std_error <- apply(F2_adults.replications, 1, sd) / sqrt(opt$replications) | 622 F2_adults.std_error <- apply(F2_adults.replications, 1, sd) / sqrt(opt$replications) |
604 | 623 |
605 dev.new(width=20, height=40) | 624 dev.new(width=20, height=40) |
606 | 625 |