Mercurial > repos > greg > insect_phenology_model
comparison insect_phenology_model.R @ 23:36d7bb034285 draft
Uploaded
author | greg |
---|---|
date | Thu, 08 Mar 2018 13:29:02 -0500 |
parents | 6349699fc9fa |
children | b90f9b781a77 |
comparison
equal
deleted
inserted
replaced
22:58255c06d24b | 23:36d7bb034285 |
---|---|
359 process_nymphs = FALSE; | 359 process_nymphs = FALSE; |
360 process_young_nymphs = FALSE; | 360 process_young_nymphs = FALSE; |
361 process_old_nymphs = FALSE; | 361 process_old_nymphs = FALSE; |
362 process_total_nymphs = FALSE; | 362 process_total_nymphs = FALSE; |
363 process_adults = FALSE; | 363 process_adults = FALSE; |
364 process_previtellogenic_adults = FALSE; | 364 process_previttelogenic_adults = FALSE; |
365 process_vitellogenic_adults = FALSE; | 365 process_vittelogenic_adults = FALSE; |
366 process_diapausing_adults = FALSE; | 366 process_diapausing_adults = FALSE; |
367 process_total_adults = FALSE; | 367 process_total_adults = FALSE; |
368 for (life_stage in life_stages) { | 368 for (life_stage in life_stages) { |
369 if (life_stage=="Total") { | 369 if (life_stage=="Total") { |
370 process_eggs = TRUE; | 370 process_eggs = TRUE; |
380 } | 380 } |
381 if (process_nymphs) { | 381 if (process_nymphs) { |
382 # Split life_stages_nymph into a list of strings for plots. | 382 # Split life_stages_nymph into a list of strings for plots. |
383 life_stages_nymph_str = as.character(opt$life_stages_nymph); | 383 life_stages_nymph_str = as.character(opt$life_stages_nymph); |
384 life_stages_nymph = strsplit(life_stages_nymph_str, ",")[[1]]; | 384 life_stages_nymph = strsplit(life_stages_nymph_str, ",")[[1]]; |
385 for (life_stage_nymph in opt$life_stages_nymph) { | 385 for (life_stage_nymph in life_stages_nymph) { |
386 if (life_stage_nymph=="Young") { | 386 if (life_stage_nymph=="Young") { |
387 process_young_nymphs = TRUE; | 387 process_young_nymphs = TRUE; |
388 } else if (life_stage_nymph=="Old") { | 388 } else if (life_stage_nymph=="Old") { |
389 process_old_nymphs = TRUE; | 389 process_old_nymphs = TRUE; |
390 } else if (life_stage_nymph=="Total") { | 390 } else if (life_stage_nymph=="Total") { |
394 } | 394 } |
395 if (process_adults) { | 395 if (process_adults) { |
396 # Split life_stages_adult into a list of strings for plots. | 396 # Split life_stages_adult into a list of strings for plots. |
397 life_stages_adult_str = as.character(opt$life_stages_adult); | 397 life_stages_adult_str = as.character(opt$life_stages_adult); |
398 life_stages_adult = strsplit(life_stages_adult_str, ",")[[1]]; | 398 life_stages_adult = strsplit(life_stages_adult_str, ",")[[1]]; |
399 for (life_stage_adult in opt$life_stages_adult) { | 399 for (life_stage_adult in life_stages_adult) { |
400 if (life_stage_adult=="Previtellogenic") { | 400 if (life_stage_adult=="Pre-vittelogenic") { |
401 process_previtellogenic_adults = TRUE; | 401 process_previttelogenic_adults = TRUE; |
402 } else if (life_stage_adult=="Vitellogenic") { | 402 } else if (life_stage_adult=="Vitelogenic") { |
403 process_vitellogenic_adults = TRUE; | 403 process_vittelogenic_adults = TRUE; |
404 } else if (life_stage_adult=="Diapausing") { | 404 } else if (life_stage_adult=="Diapausing") { |
405 process_diapausing_adults = TRUE; | 405 process_diapausing_adults = TRUE; |
406 } else if (life_stage_adult=="Total") { | 406 } else if (life_stage_adult=="Total") { |
407 process_total_adults = TRUE; | 407 process_total_adults = TRUE; |
408 } | 408 } |
409 } | 409 } |
410 } | 410 } |
411 | |
412 # Initialize matrices. | 411 # Initialize matrices. |
413 if (process_eggs) { | 412 if (process_eggs) { |
414 Eggs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); | 413 Eggs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); |
415 } | 414 } |
416 if (process_young_nymphs==TRUE | process_total_nymphs==TRUE) { | 415 if (process_young_nymphs | process_total_nymphs) { |
417 YoungNymphs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); | 416 YoungNymphs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); |
418 } | 417 } |
419 if (process_old_nymphs==TRUE | process_total_nymphs==TRUE) { | 418 if (process_old_nymphs | process_total_nymphs) { |
420 OldNymphs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); | 419 OldNymphs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); |
421 } | 420 } |
422 if (process_adults) { | 421 if (process_previttelogenic_adults | process_total_adults) { |
423 Previtellogenic.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); | 422 Previttelogenic.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); |
424 Vitellogenic.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); | 423 } |
424 if (process_vittelogenic_adults | process_total_adults) { | |
425 Vitelogenic.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); | |
426 } | |
427 if (process_diapausing_adults | process_total_adults) { | |
425 Diapausing.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); | 428 Diapausing.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); |
426 } | 429 } |
427 newborn.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); | 430 newborn.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); |
428 adult.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); | 431 adult.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); |
429 death.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); | 432 death.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); |
452 if (process_total_nymphs) { | 455 if (process_total_nymphs) { |
453 P_total_nymphs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); | 456 P_total_nymphs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); |
454 F1_total_nymphs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); | 457 F1_total_nymphs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); |
455 F2_total_nymphs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); | 458 F2_total_nymphs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); |
456 } | 459 } |
457 if (process_adults) { | 460 if (process_previttelogenic_adults) { |
458 P_adults.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); | 461 P_previttelogenic_adults.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); |
459 F1_adults.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); | 462 F1_previttelogenic_adults.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); |
460 F2_adults.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); | 463 F2_previttelogenic_adults.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); |
464 } | |
465 if (process_vittelogenic_adults) { | |
466 P_vittelogenic_adults.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); | |
467 F1_vittelogenic_adults = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); | |
468 F2_vittelogenic_adults.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); | |
469 } | |
470 if (process_diapausing_adults) { | |
471 P_diapausing_adults.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); | |
472 F1_diapausing_adults.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); | |
473 F2_diapausing_adults.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); | |
474 } | |
475 if (process_total_adults) { | |
476 P_total_adults.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); | |
477 F1_total_adults.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); | |
478 F2_total_adults.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); | |
461 } | 479 } |
462 } | 480 } |
463 # Total population. | 481 # Total population. |
464 population.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); | 482 population.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); |
465 | 483 |
478 vector.matrix = base::t(matrix(vector.matrix, nrow=5)); | 496 vector.matrix = base::t(matrix(vector.matrix, nrow=5)); |
479 # Time series of population size. | 497 # Time series of population size. |
480 if (process_eggs) { | 498 if (process_eggs) { |
481 Eggs = rep(0, opt$num_days); | 499 Eggs = rep(0, opt$num_days); |
482 } | 500 } |
483 if (process_nymphs) { | 501 if (process_young_nymphs | process_total_nymphs) { |
484 YoungNymphs = rep(0, opt$num_days); | 502 YoungNymphs = rep(0, opt$num_days); |
503 } | |
504 if (process_old_nymphs | process_total_nymphs) { | |
485 OldNymphs = rep(0, opt$num_days); | 505 OldNymphs = rep(0, opt$num_days); |
486 } | 506 } |
487 if (process_adults) { | 507 if (process_previttelogenic_adults | process_total_adults) { |
488 Previtellogenic = rep(0, opt$num_days); | 508 Previttelogenic = rep(0, opt$num_days); |
489 Vitellogenic = rep(0, opt$num_days); | 509 } |
510 if (process_vittelogenic_adults | process_total_adults) { | |
511 Vitelogenic = rep(0, opt$num_days); | |
512 } | |
513 if (process_diapausing_adults | process_total_adults) { | |
490 Diapausing = rep(0, opt$num_days); | 514 Diapausing = rep(0, opt$num_days); |
491 } | 515 } |
492 N.newborn = rep(0, opt$num_days); | 516 N.newborn = rep(0, opt$num_days); |
493 N.adult = rep(0, opt$num_days); | 517 N.adult = rep(0, opt$num_days); |
494 N.death = rep(0, opt$num_days); | 518 N.death = rep(0, opt$num_days); |
517 if (process_total_nymphs) { | 541 if (process_total_nymphs) { |
518 P.total_nymph = rep(0, opt$num_days); | 542 P.total_nymph = rep(0, opt$num_days); |
519 F1.total_nymph = rep(0, opt$num_days); | 543 F1.total_nymph = rep(0, opt$num_days); |
520 F2.total_nymph = rep(0, opt$num_days); | 544 F2.total_nymph = rep(0, opt$num_days); |
521 } | 545 } |
522 if (process_adults) { | 546 if (process_previttelogenic_adults) { |
523 P.adult = rep(0, opt$num_days); | 547 P.previttelogenic_adult = rep(0, opt$num_days); |
524 F1.adult = rep(0, opt$num_days); | 548 F1.previttelogenic_adult = rep(0, opt$num_days); |
525 F2.adult = rep(0, opt$num_days); | 549 F2.previttelogenic_adult = rep(0, opt$num_days); |
550 } | |
551 if (process_vittelogenic_adults) { | |
552 P.vittelogenic_adult = rep(0, opt$num_days); | |
553 F1.vittelogenic_adult = rep(0, opt$num_days); | |
554 F2.vittelogenic_adult = rep(0, opt$num_days); | |
555 } | |
556 if (process_diapausing_adults) { | |
557 P.diapausing_adult = rep(0, opt$num_days); | |
558 F1.diapausing_adult = rep(0, opt$num_days); | |
559 F2.diapausing_adult = rep(0, opt$num_days); | |
560 } | |
561 if (process_total_adults) { | |
562 P.total_adult = rep(0, opt$num_days); | |
563 F1.total_adult = rep(0, opt$num_days); | |
564 F2.total_adult = rep(0, opt$num_days); | |
526 } | 565 } |
527 } | 566 } |
528 total.population = NULL; | 567 total.population = NULL; |
529 averages.day = rep(0, opt$num_days); | 568 averages.day = rep(0, opt$num_days); |
530 # All the days included in the input temperature dataset. | 569 # All the days included in the input temperature dataset. |
759 # are now Generation, Stage, degree-days, T, Diapause, | 798 # are now Generation, Stage, degree-days, T, Diapause, |
760 if (process_eggs) { | 799 if (process_eggs) { |
761 # For egg population size, column 2 (Stage), must be 0. | 800 # For egg population size, column 2 (Stage), must be 0. |
762 Eggs[row] = sum(vector.matrix[,2]==0); | 801 Eggs[row] = sum(vector.matrix[,2]==0); |
763 } | 802 } |
764 if (process_young_nymphs) { | 803 if (process_young_nymphs | process_total_nymphs) { |
765 # For young nymph population size, column 2 (Stage) must be 1. | 804 # For young nymph population size, column 2 (Stage) must be 1. |
766 YoungNymphs[row] = sum(vector.matrix[,2]==1); | 805 YoungNymphs[row] = sum(vector.matrix[,2]==1); |
767 } | 806 } |
768 if (process_old_nymphs) { | 807 if (process_old_nymphs | process_total_nymphs) { |
769 # For old nymph population size, column 2 (Stage) must be 2. | 808 # For old nymph population size, column 2 (Stage) must be 2. |
770 OldNymphs[row] = sum(vector.matrix[,2]==2); | 809 OldNymphs[row] = sum(vector.matrix[,2]==2); |
771 } | 810 } |
772 if (process_adults) { | 811 if (process_previttelogenic_adults | process_total_adults) { |
773 # For pre-vitellogenic population size, column 2 (Stage) must be 3. | 812 # For pre-vittelogenic population size, column 2 (Stage) must be 3. |
774 Previtellogenic[row] = sum(vector.matrix[,2]==3); | 813 Previttelogenic[row] = sum(vector.matrix[,2]==3); |
775 # For vitellogenic population size, column 2 (Stage) must be 4. | 814 } |
776 Vitellogenic[row] = sum(vector.matrix[,2]==4); | 815 if (process_vittelogenic_adults | process_total_adults) { |
816 # For vittelogenic population size, column 2 (Stage) must be 4. | |
817 Vitelogenic[row] = sum(vector.matrix[,2]==4); | |
818 } | |
819 if (process_diapausing_adults | process_total_adults) { | |
777 # For diapausing population size, column 2 (Stage) must be 5. | 820 # For diapausing population size, column 2 (Stage) must be 5. |
778 Diapausing[row] = sum(vector.matrix[,2]==5); | 821 Diapausing[row] = sum(vector.matrix[,2]==5); |
779 } | 822 } |
780 | 823 |
781 # Newborn population size. | 824 # Newborn population size. |
852 # size, one of the following combinations is required: | 895 # size, one of the following combinations is required: |
853 # - column 1 (Generation) is 2 and column 2 (Stage) is 1 (Young nymph) | 896 # - column 1 (Generation) is 2 and column 2 (Stage) is 1 (Young nymph) |
854 # - column 1 (Generation) is 2 and column 2 (Stage) is 2 (Old nymph) | 897 # - column 1 (Generation) is 2 and column 2 (Stage) is 2 (Old nymph) |
855 F2.total_nymph[row] = sum((vector.matrix[,1]==2 & vector.matrix[,2]==1) | (vector.matrix[,1]==2 & vector.matrix[,2]==2)); | 898 F2.total_nymph[row] = sum((vector.matrix[,1]==2 & vector.matrix[,2]==1) | (vector.matrix[,1]==2 & vector.matrix[,2]==2)); |
856 } | 899 } |
857 if (process_adults) { | 900 if (process_previttelogenic_adults) { |
858 # For adult life stage of generation P population | 901 # For previttelogenic adult life stage of generation P population |
902 # size, the following combination is required: | |
903 # - column 1 (Generation) is 0 and column 2 (Stage) is 3 (Pre-vittelogenic) | |
904 P.previttelogenic_adult[row] = sum(vector.matrix[,1]==0 & vector.matrix[,2]==3); | |
905 # For previttelogenic adult life stage of generation F1 population | |
906 # size, the following combination is required: | |
907 # - column 1 (Generation) is 1 and column 2 (Stage) is 3 (Pre-vittelogenic) | |
908 F1.previttelogenic_adult[row] = sum(vector.matrix[,1]==1 & vector.matrix[,2]==3); | |
909 # For previttelogenic adult life stage of generation F2 population | |
910 # size, the following combination is required: | |
911 # - column 1 (Generation) is 2 and column 2 (Stage) is 3 (Pre-vittelogenic) | |
912 F2.previttelogenic_adult[row] = sum(vector.matrix[,1]==2 & vector.matrix[,2]==3); | |
913 } | |
914 if (process_vittelogenic_adults) { | |
915 # For vittelogenic adult life stage of generation P population | |
916 # size, the following combination is required: | |
917 # - column 1 (Generation) is 0 and column 2 (Stage) is 4 (Vitelogenic) | |
918 P.vittelogenic_adult[row] = sum(vector.matrix[,1]==0 & vector.matrix[,2]==4); | |
919 # For vittelogenic adult life stage of generation F1 population | |
920 # size, the following combination is required: | |
921 # - column 1 (Generation) is 1 and column 2 (Stage) is 4 (Vitelogenic) | |
922 F1.vittelogenic_adult[row] = sum(vector.matrix[,1]==1 & vector.matrix[,2]==4); | |
923 # For vittelogenic adult life stage of generation F2 population | |
924 # size, the following combination is required: | |
925 # - column 1 (Generation) is 2 and column 2 (Stage) is 4 (Vitelogenic) | |
926 F2.vittelogenic_adult[row] = sum(vector.matrix[,1]==2 & vector.matrix[,2]==4); | |
927 } | |
928 if (process_diapausing_adults) { | |
929 # For diapausing adult life stage of generation P population | |
930 # size, the following combination is required: | |
931 # - column 1 (Generation) is 0 and column 2 (Stage) is 5 (Diapausing) | |
932 P.diapausing_adult[row] = sum(vector.matrix[,1]==0 & vector.matrix[,2]==5); | |
933 # For diapausing adult life stage of generation F1 population | |
934 # size, the following combination is required: | |
935 # - column 1 (Generation) is 1 and column 2 (Stage) is 5 (Diapausing) | |
936 F1.diapausing_adult[row] = sum(vector.matrix[,1]==1 & vector.matrix[,2]==5); | |
937 # For diapausing adult life stage of generation F2 population | |
938 # size, the following combination is required: | |
939 # - column 1 (Generation) is 2 and column 2 (Stage) is 5 (Diapausing) | |
940 F2.diapausing_adult[row] = sum(vector.matrix[,1]==2 & vector.matrix[,2]==5); | |
941 } | |
942 if (process_total_adults) { | |
943 # For total adult life stage of generation P population | |
859 # size, one of the following combinations is required: | 944 # size, one of the following combinations is required: |
860 # - column 1 (Generation) is 0 and column 2 (Stage) is 3 (Pre-vitellogenic) | 945 # - column 1 (Generation) is 0 and column 2 (Stage) is 3 (Pre-vittelogenic) |
861 # - column 1 (Generation) is 0 and column 2 (Stage) is 4 (Vitellogenic) | 946 # - column 1 (Generation) is 0 and column 2 (Stage) is 4 (Vitelogenic) |
862 # - column 1 (Generation) is 0 and column 2 (Stage) is 5 (Diapausing) | 947 # - column 1 (Generation) is 0 and column 2 (Stage) is 5 (Diapausing) |
863 P.adult[row] = sum((vector.matrix[,1]==0 & vector.matrix[,2]==3) | (vector.matrix[,1]==0 & vector.matrix[,2]==4) | (vector.matrix[,1]==0 & vector.matrix[,2]==5)); | 948 P.total_adult[row] = sum((vector.matrix[,1]==0 & vector.matrix[,2]==3) | (vector.matrix[,1]==0 & vector.matrix[,2]==4) | (vector.matrix[,1]==0 & vector.matrix[,2]==5)); |
864 # For adult life stage of generation F1 population | 949 # For total adult life stage of generation F1 population |
865 # size, one of the following combinations is required: | 950 # size, one of the following combinations is required: |
866 # - column 1 (Generation) is 1 and column 2 (Stage) is 3 (Pre-vitellogenic) | 951 # - column 1 (Generation) is 1 and column 2 (Stage) is 3 (Pre-vittelogenic) |
867 # - column 1 (Generation) is 1 and column 2 (Stage) is 4 (Vitellogenic) | 952 # - column 1 (Generation) is 1 and column 2 (Stage) is 4 (Vitelogenic) |
868 # - column 1 (Generation) is 1 and column 2 (Stage) is 5 (Diapausing) | 953 # - column 1 (Generation) is 1 and column 2 (Stage) is 5 (Diapausing) |
869 F1.adult[row] = sum((vector.matrix[,1]==1 & vector.matrix[,2]==3) | (vector.matrix[,1]==1 & vector.matrix[,2]==4) | (vector.matrix[,1]==1 & vector.matrix[,2]==5)); | 954 F1.total_adult[row] = sum((vector.matrix[,1]==1 & vector.matrix[,2]==3) | (vector.matrix[,1]==1 & vector.matrix[,2]==4) | (vector.matrix[,1]==1 & vector.matrix[,2]==5)); |
870 # For adult life stage of generation F2 population | 955 # For total adult life stage of generation F2 population |
871 # size, one of the following combinations is required: | 956 # size, one of the following combinations is required: |
872 # - column 1 (Generation) is 2 and column 2 (Stage) is 3 (Pre-vitellogenic) | 957 # - column 1 (Generation) is 2 and column 2 (Stage) is 3 (Pre-vittelogenic) |
873 # - column 1 (Generation) is 2 and column 2 (Stage) is 4 (Vitellogenic) | 958 # - column 1 (Generation) is 2 and column 2 (Stage) is 4 (Vitelogenic) |
874 # - column 1 (Generation) is 2 and column 2 (Stage) is 5 (Diapausing) | 959 # - column 1 (Generation) is 2 and column 2 (Stage) is 5 (Diapausing) |
875 F2.adult[row] = sum((vector.matrix[,1]==2 & vector.matrix[,2]==3) | (vector.matrix[,1]==2 & vector.matrix[,2]==4) | (vector.matrix[,1]==2 & vector.matrix[,2]==5)); | 960 F2.total_adult[row] = sum((vector.matrix[,1]==2 & vector.matrix[,2]==3) | (vector.matrix[,1]==2 & vector.matrix[,2]==4) | (vector.matrix[,1]==2 & vector.matrix[,2]==5)); |
876 } | 961 } |
877 } | 962 } |
878 } # End of days specified in the input temperature data. | 963 } # End of days specified in the input temperature data. |
879 | 964 |
880 averages.cum = cumsum(averages.day); | 965 averages.cum = cumsum(averages.day); |
881 | 966 |
882 # Define the output values. | 967 # Define the output values. |
883 if (process_eggs) { | 968 if (process_eggs) { |
884 Eggs.replications[,current_replication] = Eggs; | 969 Eggs.replications[,current_replication] = Eggs; |
885 } | 970 } |
886 if (process_young_nymphs==TRUE | process_total_nymphs==TRUE) { | 971 if (process_young_nymphs | process_total_nymphs) { |
887 YoungNymphs.replications[,current_replication] = YoungNymphs; | 972 YoungNymphs.replications[,current_replication] = YoungNymphs; |
888 } | 973 } |
889 if (process_old_nymphs==TRUE | process_total_nymphs==TRUE) { | 974 if (process_old_nymphs | process_total_nymphs) { |
890 OldNymphs.replications[,current_replication] = OldNymphs; | 975 OldNymphs.replications[,current_replication] = OldNymphs; |
891 } | 976 } |
892 if (process_adults) { | 977 if (process_previttelogenic_adults | process_total_adults) { |
893 Previtellogenic.replications[,current_replication] = Previtellogenic; | 978 Previttelogenic.replications[,current_replication] = Previttelogenic; |
894 Vitellogenic.replications[,current_replication] = Vitellogenic; | 979 } |
980 if (process_vittelogenic_adults | process_total_adults) { | |
981 Vitelogenic.replications[,current_replication] = Vitelogenic; | |
982 } | |
983 if (process_diapausing_adults | process_total_adults) { | |
895 Diapausing.replications[,current_replication] = Diapausing; | 984 Diapausing.replications[,current_replication] = Diapausing; |
896 } | 985 } |
897 newborn.replications[,current_replication] = N.newborn; | 986 newborn.replications[,current_replication] = N.newborn; |
898 adult.replications[,current_replication] = N.adult; | 987 adult.replications[,current_replication] = N.adult; |
899 death.replications[,current_replication] = N.death; | 988 death.replications[,current_replication] = N.death; |
922 if (process_total_nymphs) { | 1011 if (process_total_nymphs) { |
923 P_total_nymphs.replications[,current_replication] = P.total_nymph; | 1012 P_total_nymphs.replications[,current_replication] = P.total_nymph; |
924 F1_total_nymphs.replications[,current_replication] = F1.total_nymph; | 1013 F1_total_nymphs.replications[,current_replication] = F1.total_nymph; |
925 F2_total_nymphs.replications[,current_replication] = F2.total_nymph; | 1014 F2_total_nymphs.replications[,current_replication] = F2.total_nymph; |
926 } | 1015 } |
927 if (process_adults) { | 1016 if (process_previttelogenic_adults) { |
928 P_adults.replications[,current_replication] = P.adult; | 1017 P_previttelogenic_adults.replications[,current_replication] = P.previttelogenic_adult; |
929 F1_adults.replications[,current_replication] = F1.adult; | 1018 F1_previttelogenic_adults.replications[,current_replication] = F1.previttelogenic_adult; |
930 F2_adults.replications[,current_replication] = F2.adult; | 1019 F2_previttelogenic_adults.replications[,current_replication] = F2.previttelogenic_adult; |
1020 } | |
1021 if (process_vittelogenic_adults) { | |
1022 P_vittelogenic_adults.replications[,current_replication] = P.vittelogenic_adult; | |
1023 F1_vittelogenic_adults.replications[,current_replication] = F1.vittelogenic_adult; | |
1024 F2_vittelogenic_adults.replications[,current_replication] = F2.vittelogenic_adult; | |
1025 } | |
1026 if (process_diapausing_adults) { | |
1027 P_diapausing_adults.replications[,current_replication] = P.diapausing_adult; | |
1028 F1_diapausing_adults.replications[,current_replication] = F1.diapausing_adult; | |
1029 F2_diapausing_adults.replications[,current_replication] = F2.diapausing_adult; | |
1030 } | |
1031 if (process_total_adults) { | |
1032 P_total_adults.replications[,current_replication] = P.total_adult; | |
1033 F1_total_adults.replications[,current_replication] = F1.total_adult; | |
1034 F2_total_adults.replications[,current_replication] = F2.total_adult; | |
931 } | 1035 } |
932 } | 1036 } |
933 population.replications[,current_replication] = total.population; | 1037 population.replications[,current_replication] = total.population; |
934 # End processing replications. | 1038 # End processing replications. |
935 } | 1039 } |
964 if (process_adults) { | 1068 if (process_adults) { |
965 # Calculate adult populations for selected life stage. | 1069 # Calculate adult populations for selected life stage. |
966 for (life_stage_adult in life_stages_adult) { | 1070 for (life_stage_adult in life_stages_adult) { |
967 if (life_stage_adult=="Total") { | 1071 if (life_stage_adult=="Total") { |
968 # Mean value for all adults. | 1072 # Mean value for all adults. |
969 total_adults = apply((Previtellogenic.replications+Vitellogenic.replications+Diapausing.replications), 1, mean); | 1073 total_adults = apply((Previttelogenic.replications+Vitelogenic.replications+Diapausing.replications), 1, mean); |
970 # Standard error for all adults. | 1074 # Standard error for all adults. |
971 total_adults.std_error = apply((Previtellogenic.replications+Vitellogenic.replications+Diapausing.replications), 1, sd) / sqrt(opt$replications); | 1075 total_adults.std_error = apply((Previttelogenic.replications+Vitelogenic.replications+Diapausing.replications), 1, sd) / sqrt(opt$replications); |
972 } else if (life_stage_adult == "Pre-vittelogenic") { | 1076 } else if (life_stage_adult == "Pre-vittelogenic") { |
973 # Mean value for previtellogenic adults. | 1077 # Mean value for previttelogenic adults. |
974 previttelogenic_adults = apply(Previtellogenic.replications, 1, mean); | 1078 previttelogenic_adults = apply(Previttelogenic.replications, 1, mean); |
975 # Standard error for previtellogenic adults. | 1079 # Standard error for previttelogenic adults. |
976 previttelogenic_adults.std_error = apply(Previtellogenic.replications, 1, sd) / sqrt(opt$replications); | 1080 previttelogenic_adults.std_error = apply(Previttelogenic.replications, 1, sd) / sqrt(opt$replications); |
977 } else if (life_stage_adult == "Vittelogenic") { | 1081 } else if (life_stage_adult == "Vittelogenic") { |
978 # Mean value for vitellogenic adults. | 1082 # Mean value for vittelogenic adults. |
979 vittelogenic_adults = apply(Vitellogenic.replications, 1, mean); | 1083 vittelogenic_adults = apply(Vitelogenic.replications, 1, mean); |
980 # Standard error for vitellogenic adults. | 1084 # Standard error for vittelogenic adults. |
981 vittelogenic_adults.std_error = apply(Vitellogenic.replications, 1, sd) / sqrt(opt$replications); | 1085 vittelogenic_adults.std_error = apply(Vitelogenic.replications, 1, sd) / sqrt(opt$replications); |
982 } else if (life_stage_adult == "Diapausing") { | 1086 } else if (life_stage_adult == "Diapausing") { |
983 # Mean value for vitellogenic adults. | 1087 # Mean value for vittelogenic adults. |
984 diapausing_adults = apply(Diapausing.replications, 1, mean); | 1088 diapausing_adults = apply(Diapausing.replications, 1, mean); |
985 # Standard error for vitellogenic adults. | 1089 # Standard error for vittelogenic adults. |
986 diapausing_adults.std_error = apply(Diapausing.replications, 1, sd) / sqrt(opt$replications); | 1090 diapausing_adults.std_error = apply(Diapausing.replications, 1, sd) / sqrt(opt$replications); |
987 } | 1091 } |
988 } | 1092 } |
989 } | 1093 } |
990 | 1094 |
1030 F1_total_nymphs = m_se[[3]]; | 1134 F1_total_nymphs = m_se[[3]]; |
1031 F1_total_nymphs.std_error = m_se[[4]]; | 1135 F1_total_nymphs.std_error = m_se[[4]]; |
1032 F2_total_nymphs = m_se[[5]]; | 1136 F2_total_nymphs = m_se[[5]]; |
1033 F2_total_nymphs.std_error = m_se[[6]]; | 1137 F2_total_nymphs.std_error = m_se[[6]]; |
1034 } | 1138 } |
1035 if (process_adults) { | 1139 if (process_previttelogenic_adults) { |
1036 # Mean value for P_adults. | 1140 m_se = get_mean_and_std_error(P_previttelogenic_adults.replications, F1_previttelogenic_adults.replications, F2_previttelogenic_adults.replications); |
1037 P_adults = apply(P_adults.replications, 1, mean); | 1141 P_previttelogenic_adults = m_se[[1]]; |
1038 # Standard error for P_adults. | 1142 P_previttelogenic_adults.std_error = m_se[[2]]; |
1039 P_adults.std_error = apply(P_adults.replications, 1, sd) / sqrt(opt$replications); | 1143 F1_previttelogenic_adults = m_se[[3]]; |
1040 # Mean value for F1 adults. | 1144 F1_previttelogenic_adults.std_error = m_se[[4]]; |
1041 F1_adults = apply(F1_adults.replications, 1, mean); | 1145 F2_previttelogenic_adults = m_se[[5]]; |
1042 # Standard error for F1_adults. | 1146 F2_previttelogenic_adults.std_error = m_se[[6]]; |
1043 F1_adults.std_error = apply(F1_adults.replications, 1, sd) / sqrt(opt$replications); | 1147 } |
1044 # Mean value for F2_adults. | 1148 if (process_vittelogenic_adults) { |
1045 F2_adults = apply(F2_adults.replications, 1, mean); | 1149 m_se = get_mean_and_std_error(P_vittelogenic_adults.replications, F1_vittelogenic_adults.replications, F2_vittelogenic_adults.replications); |
1046 # Standard error for F2_adults. | 1150 P_vittelogenic_adults = m_se[[1]]; |
1047 F2_adults.std_error = apply(F2_adults.replications, 1, sd) / sqrt(opt$replications); | 1151 P_vittelogenic_adults.std_error = m_se[[2]]; |
1152 F1_vittelogenic_adults = m_se[[3]]; | |
1153 F1_vittelogenic_adults.std_error = m_se[[4]]; | |
1154 F2_vittelogenic_adults = m_se[[5]]; | |
1155 F2_vittelogenic_adults.std_error = m_se[[6]]; | |
1156 } | |
1157 if (process_diapausing_adults) { | |
1158 m_se = get_mean_and_std_error(P_diapausing_adults.replications, F1_diapausing_adults.replications, F2_diapausing_adults.replications); | |
1159 P_diapausing_adults = m_se[[1]]; | |
1160 P_diapausing_adults.std_error = m_se[[2]]; | |
1161 F1_diapausing_adults = m_se[[3]]; | |
1162 F1_diapausing_adults.std_error = m_se[[4]]; | |
1163 F2_diapausing_adults = m_se[[5]]; | |
1164 F2_diapausing_adults.std_error = m_se[[6]]; | |
1165 } | |
1166 if (process_total_adults) { | |
1167 m_se = get_mean_and_std_error(P_total_adults.replications, F1_total_adults.replications, F2_total_adults.replications); | |
1168 P_total_adults = m_se[[1]]; | |
1169 P_total_adults.std_error = m_se[[2]]; | |
1170 F1_total_adults = m_se[[3]]; | |
1171 F1_total_adults.std_error = m_se[[4]]; | |
1172 F2_total_adults = m_se[[5]]; | |
1173 F2_total_adults.std_error = m_se[[6]]; | |
1048 } | 1174 } |
1049 } | 1175 } |
1050 | 1176 |
1051 # Display the total number of days in the Galaxy history item blurb. | 1177 # Display the total number of days in the Galaxy history item blurb. |
1052 cat("Number of days: ", opt$num_days, "\n"); | 1178 cat("Number of days: ", opt$num_days, "\n"); |
1117 # Start PDF device driver. | 1243 # Start PDF device driver. |
1118 dev.new(width=20, height=30); | 1244 dev.new(width=20, height=30); |
1119 file_path = get_file_path(life_stage, "adult_pop_by_generation.pdf", life_stage_adult=life_stage_adult) | 1245 file_path = get_file_path(life_stage, "adult_pop_by_generation.pdf", life_stage_adult=life_stage_adult) |
1120 pdf(file=file_path, width=20, height=30, bg="white"); | 1246 pdf(file=file_path, width=20, height=30, bg="white"); |
1121 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1)); | 1247 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1)); |
1122 # Adult population size by generation. | 1248 if (life_stage_adult=="Pre-vittelogenic") { |
1123 maxval = max(P_adults+F1_adults+F2_adults) + 100; | 1249 # Pre-vittelogenic adult population size by generation. |
1250 maxval = max(P_previttelogenic_adults+F1_previttelogenic_adults+F2_previttelogenic_adults) + 100; | |
1251 group = P_previttelogenic_adults; | |
1252 group_std_error = P_previttelogenic_adults.std_error; | |
1253 group2 = F1_previttelogenic_adults; | |
1254 group2_std_error = F1_previttelogenic_adults.std_error; | |
1255 group3 = F2_previttelogenic_adults; | |
1256 group3_std_error = F2_previttelogenic_adults.std_error; | |
1257 } else if (life_stage_adult=="Vittelogenic") { | |
1258 # Vittelogenic adult population size by generation. | |
1259 maxval = max(P_vittelogenic_adults+F1_vittelogenic_adults+F2_vittelogenic_adults) + 100; | |
1260 group = P_vittelogenic_adults; | |
1261 group_std_error = P_vittelogenic_adults.std_error; | |
1262 group2 = F1_vittelogenic_adults; | |
1263 group2_std_error = F1_vittelogenic_adults.std_error; | |
1264 group3 = F2_vittelogenic_adults; | |
1265 group3_std_error = F2_vittelogenic_adults.std_error; | |
1266 } else if (life_stage_adult=="Diapausing") { | |
1267 # Diapausing adult population size by generation. | |
1268 maxval = max(P_diapausing_adults+F1_diapausing_adults+F2_diapausing_adults) + 100; | |
1269 group = P_diapausing_adults; | |
1270 group_std_error = P_diapausing_adults.std_error; | |
1271 group2 = F1_diapausing_adults; | |
1272 group2_std_error = F1_diapausing_adults.std_error; | |
1273 group3 = F2_diapausing_adults; | |
1274 group3_std_error = F2_diapausing_adults.std_error; | |
1275 } else if (life_stage_adult=="Total") { | |
1276 # Total adult population size by generation. | |
1277 maxval = max(P_total_adults+F1_total_adults+F2_total_adults) + 100; | |
1278 group = P_total_adults; | |
1279 group_std_error = P_total_adults.std_error; | |
1280 group2 = F1_total_adults; | |
1281 group2_std_error = F1_total_adults.std_error; | |
1282 group3 = F2_total_adults; | |
1283 group3_std_error = F2_total_adults.std_error; | |
1284 } | |
1124 render_chart(date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval, | 1285 render_chart(date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval, |
1125 opt$replications, life_stage, group=P_adults, group_std_error=P_adults.std_error, group2=F1_adults, group2_std_error=F1_adults.std_error, | 1286 opt$replications, life_stage, group=group, group_std_error=group_std_error, group2=group2, group2_std_error=group2_std_error, |
1126 group3=F2_adults, group3_std_error=F2_adults.std_error, life_stages_adult=life_stage_adult); | 1287 group3=group3, group3_std_error=group3_std_error, life_stages_adult=life_stage_adult); |
1127 # Turn off device driver to flush output. | 1288 # Turn off device driver to flush output. |
1128 dev.off(); | 1289 dev.off(); |
1129 } | 1290 } |
1130 } else if (life_stage == "Total") { | 1291 } else if (life_stage == "Total") { |
1131 # Start PDF device driver. | 1292 # Start PDF device driver. |