Mercurial > repos > greg > insect_phenology_model
comparison insect_phenology_model.R @ 24:b90f9b781a77 draft
Uploaded
author | greg |
---|---|
date | Thu, 08 Mar 2018 13:37:50 -0500 |
parents | 36d7bb034285 |
children | 390d89243074 |
comparison
equal
deleted
inserted
replaced
23:36d7bb034285 | 24:b90f9b781a77 |
---|---|
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 life_stages_adult) { | 399 for (life_stage_adult in life_stages_adult) { |
400 if (life_stage_adult=="Pre-vittelogenic") { | 400 if (life_stage_adult=="Pre-vittelogenic") { |
401 process_previttelogenic_adults = TRUE; | 401 process_previttelogenic_adults = TRUE; |
402 } else if (life_stage_adult=="Vitelogenic") { | 402 } else if (life_stage_adult=="Vittelogenic") { |
403 process_vittelogenic_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; |
420 } | 420 } |
421 if (process_previttelogenic_adults | process_total_adults) { | 421 if (process_previttelogenic_adults | process_total_adults) { |
422 Previttelogenic.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); |
423 } | 423 } |
424 if (process_vittelogenic_adults | process_total_adults) { | 424 if (process_vittelogenic_adults | process_total_adults) { |
425 Vitelogenic.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); | 425 Vittelogenic.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); |
426 } | 426 } |
427 if (process_diapausing_adults | process_total_adults) { | 427 if (process_diapausing_adults | process_total_adults) { |
428 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); |
429 } | 429 } |
430 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); |
506 } | 506 } |
507 if (process_previttelogenic_adults | process_total_adults) { | 507 if (process_previttelogenic_adults | process_total_adults) { |
508 Previttelogenic = rep(0, opt$num_days); | 508 Previttelogenic = rep(0, opt$num_days); |
509 } | 509 } |
510 if (process_vittelogenic_adults | process_total_adults) { | 510 if (process_vittelogenic_adults | process_total_adults) { |
511 Vitelogenic = rep(0, opt$num_days); | 511 Vittelogenic = rep(0, opt$num_days); |
512 } | 512 } |
513 if (process_diapausing_adults | process_total_adults) { | 513 if (process_diapausing_adults | process_total_adults) { |
514 Diapausing = rep(0, opt$num_days); | 514 Diapausing = rep(0, opt$num_days); |
515 } | 515 } |
516 N.newborn = rep(0, opt$num_days); | 516 N.newborn = rep(0, opt$num_days); |
812 # For pre-vittelogenic population size, column 2 (Stage) must be 3. | 812 # For pre-vittelogenic population size, column 2 (Stage) must be 3. |
813 Previttelogenic[row] = sum(vector.matrix[,2]==3); | 813 Previttelogenic[row] = sum(vector.matrix[,2]==3); |
814 } | 814 } |
815 if (process_vittelogenic_adults | process_total_adults) { | 815 if (process_vittelogenic_adults | process_total_adults) { |
816 # For vittelogenic population size, column 2 (Stage) must be 4. | 816 # For vittelogenic population size, column 2 (Stage) must be 4. |
817 Vitelogenic[row] = sum(vector.matrix[,2]==4); | 817 Vittelogenic[row] = sum(vector.matrix[,2]==4); |
818 } | 818 } |
819 if (process_diapausing_adults | process_total_adults) { | 819 if (process_diapausing_adults | process_total_adults) { |
820 # For diapausing population size, column 2 (Stage) must be 5. | 820 # For diapausing population size, column 2 (Stage) must be 5. |
821 Diapausing[row] = sum(vector.matrix[,2]==5); | 821 Diapausing[row] = sum(vector.matrix[,2]==5); |
822 } | 822 } |
912 F2.previttelogenic_adult[row] = sum(vector.matrix[,1]==2 & vector.matrix[,2]==3); | 912 F2.previttelogenic_adult[row] = sum(vector.matrix[,1]==2 & vector.matrix[,2]==3); |
913 } | 913 } |
914 if (process_vittelogenic_adults) { | 914 if (process_vittelogenic_adults) { |
915 # For vittelogenic adult life stage of generation P population | 915 # For vittelogenic adult life stage of generation P population |
916 # size, the following combination is required: | 916 # size, the following combination is required: |
917 # - column 1 (Generation) is 0 and column 2 (Stage) is 4 (Vitelogenic) | 917 # - column 1 (Generation) is 0 and column 2 (Stage) is 4 (Vittelogenic) |
918 P.vittelogenic_adult[row] = sum(vector.matrix[,1]==0 & vector.matrix[,2]==4); | 918 P.vittelogenic_adult[row] = sum(vector.matrix[,1]==0 & vector.matrix[,2]==4); |
919 # For vittelogenic adult life stage of generation F1 population | 919 # For vittelogenic adult life stage of generation F1 population |
920 # size, the following combination is required: | 920 # size, the following combination is required: |
921 # - column 1 (Generation) is 1 and column 2 (Stage) is 4 (Vitelogenic) | 921 # - column 1 (Generation) is 1 and column 2 (Stage) is 4 (Vittelogenic) |
922 F1.vittelogenic_adult[row] = sum(vector.matrix[,1]==1 & vector.matrix[,2]==4); | 922 F1.vittelogenic_adult[row] = sum(vector.matrix[,1]==1 & vector.matrix[,2]==4); |
923 # For vittelogenic adult life stage of generation F2 population | 923 # For vittelogenic adult life stage of generation F2 population |
924 # size, the following combination is required: | 924 # size, the following combination is required: |
925 # - column 1 (Generation) is 2 and column 2 (Stage) is 4 (Vitelogenic) | 925 # - column 1 (Generation) is 2 and column 2 (Stage) is 4 (Vittelogenic) |
926 F2.vittelogenic_adult[row] = sum(vector.matrix[,1]==2 & vector.matrix[,2]==4); | 926 F2.vittelogenic_adult[row] = sum(vector.matrix[,1]==2 & vector.matrix[,2]==4); |
927 } | 927 } |
928 if (process_diapausing_adults) { | 928 if (process_diapausing_adults) { |
929 # For diapausing adult life stage of generation P population | 929 # For diapausing adult life stage of generation P population |
930 # size, the following combination is required: | 930 # size, the following combination is required: |
941 } | 941 } |
942 if (process_total_adults) { | 942 if (process_total_adults) { |
943 # For total adult life stage of generation P population | 943 # For total adult life stage of generation P population |
944 # size, one of the following combinations is required: | 944 # size, one of the following combinations is required: |
945 # - column 1 (Generation) is 0 and column 2 (Stage) is 3 (Pre-vittelogenic) | 945 # - column 1 (Generation) is 0 and column 2 (Stage) is 3 (Pre-vittelogenic) |
946 # - column 1 (Generation) is 0 and column 2 (Stage) is 4 (Vitelogenic) | 946 # - column 1 (Generation) is 0 and column 2 (Stage) is 4 (Vittelogenic) |
947 # - 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) |
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)); | 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)); |
949 # For total adult life stage of generation F1 population | 949 # For total adult life stage of generation F1 population |
950 # size, one of the following combinations is required: | 950 # size, one of the following combinations is required: |
951 # - column 1 (Generation) is 1 and column 2 (Stage) is 3 (Pre-vittelogenic) | 951 # - column 1 (Generation) is 1 and column 2 (Stage) is 3 (Pre-vittelogenic) |
952 # - column 1 (Generation) is 1 and column 2 (Stage) is 4 (Vitelogenic) | 952 # - column 1 (Generation) is 1 and column 2 (Stage) is 4 (Vittelogenic) |
953 # - 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) |
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)); | 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)); |
955 # For total adult life stage of generation F2 population | 955 # For total adult life stage of generation F2 population |
956 # size, one of the following combinations is required: | 956 # size, one of the following combinations is required: |
957 # - column 1 (Generation) is 2 and column 2 (Stage) is 3 (Pre-vittelogenic) | 957 # - column 1 (Generation) is 2 and column 2 (Stage) is 3 (Pre-vittelogenic) |
958 # - column 1 (Generation) is 2 and column 2 (Stage) is 4 (Vitelogenic) | 958 # - column 1 (Generation) is 2 and column 2 (Stage) is 4 (Vittelogenic) |
959 # - 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) |
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)); | 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)); |
961 } | 961 } |
962 } | 962 } |
963 } # End of days specified in the input temperature data. | 963 } # End of days specified in the input temperature data. |
976 } | 976 } |
977 if (process_previttelogenic_adults | process_total_adults) { | 977 if (process_previttelogenic_adults | process_total_adults) { |
978 Previttelogenic.replications[,current_replication] = Previttelogenic; | 978 Previttelogenic.replications[,current_replication] = Previttelogenic; |
979 } | 979 } |
980 if (process_vittelogenic_adults | process_total_adults) { | 980 if (process_vittelogenic_adults | process_total_adults) { |
981 Vitelogenic.replications[,current_replication] = Vitelogenic; | 981 Vittelogenic.replications[,current_replication] = Vittelogenic; |
982 } | 982 } |
983 if (process_diapausing_adults | process_total_adults) { | 983 if (process_diapausing_adults | process_total_adults) { |
984 Diapausing.replications[,current_replication] = Diapausing; | 984 Diapausing.replications[,current_replication] = Diapausing; |
985 } | 985 } |
986 newborn.replications[,current_replication] = N.newborn; | 986 newborn.replications[,current_replication] = N.newborn; |
1068 if (process_adults) { | 1068 if (process_adults) { |
1069 # Calculate adult populations for selected life stage. | 1069 # Calculate adult populations for selected life stage. |
1070 for (life_stage_adult in life_stages_adult) { | 1070 for (life_stage_adult in life_stages_adult) { |
1071 if (life_stage_adult=="Total") { | 1071 if (life_stage_adult=="Total") { |
1072 # Mean value for all adults. | 1072 # Mean value for all adults. |
1073 total_adults = apply((Previttelogenic.replications+Vitelogenic.replications+Diapausing.replications), 1, mean); | 1073 total_adults = apply((Previttelogenic.replications+Vittelogenic.replications+Diapausing.replications), 1, mean); |
1074 # Standard error for all adults. | 1074 # Standard error for all adults. |
1075 total_adults.std_error = apply((Previttelogenic.replications+Vitelogenic.replications+Diapausing.replications), 1, sd) / sqrt(opt$replications); | 1075 total_adults.std_error = apply((Previttelogenic.replications+Vittelogenic.replications+Diapausing.replications), 1, sd) / sqrt(opt$replications); |
1076 } else if (life_stage_adult == "Pre-vittelogenic") { | 1076 } else if (life_stage_adult == "Pre-vittelogenic") { |
1077 # Mean value for previttelogenic adults. | 1077 # Mean value for previttelogenic adults. |
1078 previttelogenic_adults = apply(Previttelogenic.replications, 1, mean); | 1078 previttelogenic_adults = apply(Previttelogenic.replications, 1, mean); |
1079 # Standard error for previttelogenic adults. | 1079 # Standard error for previttelogenic adults. |
1080 previttelogenic_adults.std_error = apply(Previttelogenic.replications, 1, sd) / sqrt(opt$replications); | 1080 previttelogenic_adults.std_error = apply(Previttelogenic.replications, 1, sd) / sqrt(opt$replications); |
1081 } else if (life_stage_adult == "Vittelogenic") { | 1081 } else if (life_stage_adult == "Vittelogenic") { |
1082 # Mean value for vittelogenic adults. | 1082 # Mean value for vittelogenic adults. |
1083 vittelogenic_adults = apply(Vitelogenic.replications, 1, mean); | 1083 vittelogenic_adults = apply(Vittelogenic.replications, 1, mean); |
1084 # Standard error for vittelogenic adults. | 1084 # Standard error for vittelogenic adults. |
1085 vittelogenic_adults.std_error = apply(Vitelogenic.replications, 1, sd) / sqrt(opt$replications); | 1085 vittelogenic_adults.std_error = apply(Vittelogenic.replications, 1, sd) / sqrt(opt$replications); |
1086 } else if (life_stage_adult == "Diapausing") { | 1086 } else if (life_stage_adult == "Diapausing") { |
1087 # Mean value for vittelogenic adults. | 1087 # Mean value for vittelogenic adults. |
1088 diapausing_adults = apply(Diapausing.replications, 1, mean); | 1088 diapausing_adults = apply(Diapausing.replications, 1, mean); |
1089 # Standard error for vittelogenic adults. | 1089 # Standard error for vittelogenic adults. |
1090 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); |