comparison insect_phenology_model.R @ 31:ef6aa8c21729 draft

Uploaded
author greg
date Mon, 19 Mar 2018 10:30:30 -0400
parents afe6d8bac0c0
children 7aa848b0e55c
comparison
equal deleted inserted replaced
30:0e49e1d1c5a1 31:ef6aa8c21729
16 make_option(c("--min_clutch_size"), action="store", dest="min_clutch_size", type="integer", help="Adjustment of minimum clutch size"), 16 make_option(c("--min_clutch_size"), action="store", dest="min_clutch_size", type="integer", help="Adjustment of minimum clutch size"),
17 make_option(c("--max_clutch_size"), action="store", dest="max_clutch_size", type="integer", help="Adjustment of maximum clutch size"), 17 make_option(c("--max_clutch_size"), action="store", dest="max_clutch_size", type="integer", help="Adjustment of maximum clutch size"),
18 make_option(c("--num_days"), action="store", dest="num_days", type="integer", help="Total number of days in the temperature dataset"), 18 make_option(c("--num_days"), action="store", dest="num_days", type="integer", help="Total number of days in the temperature dataset"),
19 make_option(c("--nymph_mortality"), action="store", dest="nymph_mortality", type="integer", help="Adjustment rate for nymph mortality"), 19 make_option(c("--nymph_mortality"), action="store", dest="nymph_mortality", type="integer", help="Adjustment rate for nymph mortality"),
20 make_option(c("--old_nymph_accumulation"), action="store", dest="old_nymph_accumulation", type="integer", help="Adjustment of degree-days accumulation (young nymph->old nymph)"), 20 make_option(c("--old_nymph_accumulation"), action="store", dest="old_nymph_accumulation", type="integer", help="Adjustment of degree-days accumulation (young nymph->old nymph)"),
21 make_option(c("--output"), action="store", dest="output", help="Dataset containing analyzed data"), 21 make_option(c("--output_combined"), action="store", dest="output_combined", help="Dataset containing analyzed data for combined generations"),
22 make_option(c("--output_f1"), action="store", dest="output_f1", default=NULL, help="Dataset containing analyzed data for generation F1"),
23 make_option(c("--output_f2"), action="store", dest="output_f2", default=NULL, help="Dataset containing analyzed data for generation F2"),
24 make_option(c("--output_p"), action="store", dest="output_p", default=NULL, help="Dataset containing analyzed data for generation P"),
22 make_option(c("--oviposition"), action="store", dest="oviposition", type="integer", help="Adjustment for oviposition rate"), 25 make_option(c("--oviposition"), action="store", dest="oviposition", type="integer", help="Adjustment for oviposition rate"),
23 make_option(c("--photoperiod"), action="store", dest="photoperiod", type="double", help="Critical photoperiod for diapause induction/termination"), 26 make_option(c("--photoperiod"), action="store", dest="photoperiod", type="double", help="Critical photoperiod for diapause induction/termination"),
24 make_option(c("--plot_generations_separately"), action="store", dest="plot_generations_separately", help="Plot Plot P, F1 and F2 as separate lines or pool across them"), 27 make_option(c("--plot_generations_separately"), action="store", dest="plot_generations_separately", help="Plot Plot P, F1 and F2 as separate lines or pool across them"),
25 make_option(c("--plot_std_error"), action="store", dest="plot_std_error", help="Plot Standard error"), 28 make_option(c("--plot_std_error"), action="store", dest="plot_std_error", help="Plot Standard error"),
26 make_option(c("--replications"), action="store", dest="replications", type="integer", help="Number of replications"), 29 make_option(c("--replications"), action="store", dest="replications", type="integer", help="Number of replications"),
352 } else { 355 } else {
353 plot_generations_separately = FALSE; 356 plot_generations_separately = FALSE;
354 } 357 }
355 # Read the temperature data into a data frame. 358 # Read the temperature data into a data frame.
356 temperature_data_frame = parse_input_data(opt$input, opt$num_days); 359 temperature_data_frame = parse_input_data(opt$input, opt$num_days);
360 # Create copies of the temperature data for generations P, F1 and F2 if we're plotting generations separately.
361 if (plot_generations_separately) {
362 temperature_data_frame_P = data.frame(temperature_data_frame);
363 temperature_data_frame_F1 = data.frame(temperature_data_frame);
364 temperature_data_frame_F2 = data.frame(temperature_data_frame);
365 }
357 # Get the date labels for plots. 366 # Get the date labels for plots.
358 date_labels = get_date_labels(temperature_data_frame, opt$num_days); 367 date_labels = get_date_labels(temperature_data_frame, opt$num_days);
359 # All latitude values are the same, so get the value for plots from the first row. 368 # All latitude values are the same, so get the value for plots from the first row.
360 latitude = temperature_data_frame$LATITUDE[1]; 369 latitude = temperature_data_frame$LATITUDE[1];
361 # Determine the specified life stages for processing. 370 # Determine the specified life stages for processing.
1126 F2.std_error = m_se[[6]]; 1135 F2.std_error = m_se[[6]];
1127 if (process_eggs) { 1136 if (process_eggs) {
1128 m_se = get_mean_and_std_error(P_eggs.replications, F1_eggs.replications, F2_eggs.replications); 1137 m_se = get_mean_and_std_error(P_eggs.replications, F1_eggs.replications, F2_eggs.replications);
1129 P_eggs = m_se[[1]]; 1138 P_eggs = m_se[[1]];
1130 P_eggs.std_error = m_se[[2]]; 1139 P_eggs.std_error = m_se[[2]];
1140 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_eggs, "EGG-P");
1141 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_eggs.std_error, "EGG-P-SE");
1131 F1_eggs = m_se[[3]]; 1142 F1_eggs = m_se[[3]];
1132 F1_eggs.std_error = m_se[[4]]; 1143 F1_eggs.std_error = m_se[[4]];
1144 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_eggs, "EGG-F1");
1145 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_eggs.std_error, "EGG-F1-SE");
1133 F2_eggs = m_se[[5]]; 1146 F2_eggs = m_se[[5]];
1134 F2_eggs.std_error = m_se[[6]]; 1147 F2_eggs.std_error = m_se[[6]];
1148 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_eggs, "EGG-F2");
1149 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_eggs.std_error, "EGG-F2-SE");
1135 } 1150 }
1136 if (process_young_nymphs) { 1151 if (process_young_nymphs) {
1137 m_se = get_mean_and_std_error(P_young_nymphs.replications, F1_young_nymphs.replications, F2_young_nymphs.replications); 1152 m_se = get_mean_and_std_error(P_young_nymphs.replications, F1_young_nymphs.replications, F2_young_nymphs.replications);
1138 P_young_nymphs = m_se[[1]]; 1153 P_young_nymphs = m_se[[1]];
1139 P_young_nymphs.std_error = m_se[[2]]; 1154 P_young_nymphs.std_error = m_se[[2]];
1155 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_young_nymphs, "YOUNGNYMPH-P");
1156 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_young_nymphs.std_error, "YOUNGNYMPH-P-SE");
1140 F1_young_nymphs = m_se[[3]]; 1157 F1_young_nymphs = m_se[[3]];
1141 F1_young_nymphs.std_error = m_se[[4]]; 1158 F1_young_nymphs.std_error = m_se[[4]];
1159 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_young_nymphs, "YOUNGNYMPH-F1");
1160 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_young_nymphs.std_error, "YOUNGNYMPH-F1-SE");
1142 F2_young_nymphs = m_se[[5]]; 1161 F2_young_nymphs = m_se[[5]];
1143 F2_young_nymphs.std_error = m_se[[6]]; 1162 F2_young_nymphs.std_error = m_se[[6]];
1163 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_young_nymphs, "YOUNGNYMPH-F2");
1164 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_young_nymphs.std_error, "YOUNGNYMPH-F2-SE");
1144 } 1165 }
1145 if (process_old_nymphs) { 1166 if (process_old_nymphs) {
1146 m_se = get_mean_and_std_error(P_old_nymphs.replications, F1_old_nymphs.replications, F2_old_nymphs.replications); 1167 m_se = get_mean_and_std_error(P_old_nymphs.replications, F1_old_nymphs.replications, F2_old_nymphs.replications);
1147 P_old_nymphs = m_se[[1]]; 1168 P_old_nymphs = m_se[[1]];
1148 P_old_nymphs.std_error = m_se[[2]]; 1169 P_old_nymphs.std_error = m_se[[2]];
1170 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_old_nymphs, "OLDNYMPH-P");
1171 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_old_nymphs.std_error, "OLDNYMPH-P-SE");
1149 F1_old_nymphs = m_se[[3]]; 1172 F1_old_nymphs = m_se[[3]];
1150 F1_old_nymphs.std_error = m_se[[4]]; 1173 F1_old_nymphs.std_error = m_se[[4]];
1174 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_old_nymphs, "OLDNYMPH-F1");
1175 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_old_nymphs.std_error, "OLDNYMPH-F1-SE");
1151 F2_old_nymphs = m_se[[5]]; 1176 F2_old_nymphs = m_se[[5]];
1152 F2_old_nymphs.std_error = m_se[[6]]; 1177 F2_old_nymphs.std_error = m_se[[6]];
1178 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_old_nymphs, "OLDNYMPH-F2");
1179 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_old_nymphs.std_error, "OLDNYMPH-F2-SE");
1153 } 1180 }
1154 if (process_total_nymphs) { 1181 if (process_total_nymphs) {
1155 m_se = get_mean_and_std_error(P_total_nymphs.replications, F1_total_nymphs.replications, F2_total_nymphs.replications); 1182 m_se = get_mean_and_std_error(P_total_nymphs.replications, F1_total_nymphs.replications, F2_total_nymphs.replications);
1156 P_total_nymphs = m_se[[1]]; 1183 P_total_nymphs = m_se[[1]];
1157 P_total_nymphs.std_error = m_se[[2]]; 1184 P_total_nymphs.std_error = m_se[[2]];
1185 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_total_nymphs, "TOTALNYMPH-P");
1186 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_total_nymphs.std_error, "TOTALNYMPH-P-SE");
1158 F1_total_nymphs = m_se[[3]]; 1187 F1_total_nymphs = m_se[[3]];
1159 F1_total_nymphs.std_error = m_se[[4]]; 1188 F1_total_nymphs.std_error = m_se[[4]];
1189 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_total_nymphs, "TOTALNYMPH-F1");
1190 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_total_nymphs.std_error, "TOTALNYMPH-F1-SE");
1160 F2_total_nymphs = m_se[[5]]; 1191 F2_total_nymphs = m_se[[5]];
1161 F2_total_nymphs.std_error = m_se[[6]]; 1192 F2_total_nymphs.std_error = m_se[[6]];
1193 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_total_nymphs, "TOTALNYMPH-F2");
1194 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_total_nymphs.std_error, "TOTALNYMPH-F2-SE");
1162 } 1195 }
1163 if (process_previttelogenic_adults) { 1196 if (process_previttelogenic_adults) {
1164 m_se = get_mean_and_std_error(P_previttelogenic_adults.replications, F1_previttelogenic_adults.replications, F2_previttelogenic_adults.replications); 1197 m_se = get_mean_and_std_error(P_previttelogenic_adults.replications, F1_previttelogenic_adults.replications, F2_previttelogenic_adults.replications);
1165 P_previttelogenic_adults = m_se[[1]]; 1198 P_previttelogenic_adults = m_se[[1]];
1166 P_previttelogenic_adults.std_error = m_se[[2]]; 1199 P_previttelogenic_adults.std_error = m_se[[2]];
1200 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_previttelogenic_adults, "PRE-VITADULT-P");
1201 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_previttelogenic_adults.std_error, "PRE-VITADULT-P-SE");
1167 F1_previttelogenic_adults = m_se[[3]]; 1202 F1_previttelogenic_adults = m_se[[3]];
1168 F1_previttelogenic_adults.std_error = m_se[[4]]; 1203 F1_previttelogenic_adults.std_error = m_se[[4]];
1204 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_previttelogenic_adults, "PRE-VITADULT-F1");
1205 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_previttelogenic_adults.std_error, "PRE-VITADULT-F1-SE");
1169 F2_previttelogenic_adults = m_se[[5]]; 1206 F2_previttelogenic_adults = m_se[[5]];
1170 F2_previttelogenic_adults.std_error = m_se[[6]]; 1207 F2_previttelogenic_adults.std_error = m_se[[6]];
1208 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_previttelogenic_adults, "PRE-VITADULT-F2");
1209 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_previttelogenic_adults.std_error, "PRE-VITADULT-F2-SE");
1171 } 1210 }
1172 if (process_vittelogenic_adults) { 1211 if (process_vittelogenic_adults) {
1173 m_se = get_mean_and_std_error(P_vittelogenic_adults.replications, F1_vittelogenic_adults.replications, F2_vittelogenic_adults.replications); 1212 m_se = get_mean_and_std_error(P_vittelogenic_adults.replications, F1_vittelogenic_adults.replications, F2_vittelogenic_adults.replications);
1174 P_vittelogenic_adults = m_se[[1]]; 1213 P_vittelogenic_adults = m_se[[1]];
1175 P_vittelogenic_adults.std_error = m_se[[2]]; 1214 P_vittelogenic_adults.std_error = m_se[[2]];
1215 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_vittelogenic_adults, "VITADULT-P");
1216 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_vittelogenic_adults.std_error, "VITADULT-P-SE");
1176 F1_vittelogenic_adults = m_se[[3]]; 1217 F1_vittelogenic_adults = m_se[[3]];
1177 F1_vittelogenic_adults.std_error = m_se[[4]]; 1218 F1_vittelogenic_adults.std_error = m_se[[4]];
1219 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_vittelogenic_adults, "VITADULT-F1");
1220 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_vittelogenic_adults.std_error, "VITADULT-F1-SE");
1178 F2_vittelogenic_adults = m_se[[5]]; 1221 F2_vittelogenic_adults = m_se[[5]];
1179 F2_vittelogenic_adults.std_error = m_se[[6]]; 1222 F2_vittelogenic_adults.std_error = m_se[[6]];
1223 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_vittelogenic_adults, "VITADULT-F2");
1224 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_vittelogenic_adults.std_error, "VITADULT-F2-SE");
1180 } 1225 }
1181 if (process_diapausing_adults) { 1226 if (process_diapausing_adults) {
1182 m_se = get_mean_and_std_error(P_diapausing_adults.replications, F1_diapausing_adults.replications, F2_diapausing_adults.replications); 1227 m_se = get_mean_and_std_error(P_diapausing_adults.replications, F1_diapausing_adults.replications, F2_diapausing_adults.replications);
1183 P_diapausing_adults = m_se[[1]]; 1228 P_diapausing_adults = m_se[[1]];
1184 P_diapausing_adults.std_error = m_se[[2]]; 1229 P_diapausing_adults.std_error = m_se[[2]];
1230 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_diapausing_adults, "DIAPAUSINGADULT-P");
1231 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_diapausing_adults.std_error, "DIAPAUSINGADULT-P-SE");
1185 F1_diapausing_adults = m_se[[3]]; 1232 F1_diapausing_adults = m_se[[3]];
1186 F1_diapausing_adults.std_error = m_se[[4]]; 1233 F1_diapausing_adults.std_error = m_se[[4]];
1234 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_diapausing_adults, "DIAPAUSINGADULT-F1");
1235 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_diapausing_adults.std_error, "DIAPAUSINGADULT-F1-SE");
1187 F2_diapausing_adults = m_se[[5]]; 1236 F2_diapausing_adults = m_se[[5]];
1188 F2_diapausing_adults.std_error = m_se[[6]]; 1237 F2_diapausing_adults.std_error = m_se[[6]];
1238 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_diapausing_adults, "DIAPAUSINGADULT-F2");
1239 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_diapausing_adults.std_error, "DIAPAUSINGADULT-F2-SE");
1189 } 1240 }
1190 if (process_total_adults) { 1241 if (process_total_adults) {
1191 m_se = get_mean_and_std_error(P_total_adults.replications, F1_total_adults.replications, F2_total_adults.replications); 1242 m_se = get_mean_and_std_error(P_total_adults.replications, F1_total_adults.replications, F2_total_adults.replications);
1192 P_total_adults = m_se[[1]]; 1243 P_total_adults = m_se[[1]];
1193 P_total_adults.std_error = m_se[[2]]; 1244 P_total_adults.std_error = m_se[[2]];
1245 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_total_adults, "TOTALADULT-P");
1246 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_total_adults.std_error, "TOTALADULT-P-SE");
1194 F1_total_adults = m_se[[3]]; 1247 F1_total_adults = m_se[[3]];
1195 F1_total_adults.std_error = m_se[[4]]; 1248 F1_total_adults.std_error = m_se[[4]];
1249 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_total_adults, "TOTALADULT-F1");
1250 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_total_adults.std_error, "TOTALADULT-F1-SE");
1196 F2_total_adults = m_se[[5]]; 1251 F2_total_adults = m_se[[5]];
1197 F2_total_adults.std_error = m_se[[6]]; 1252 F2_total_adults.std_error = m_se[[6]];
1198 } 1253 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_total_adults, "TOTALADULT-F2");
1199 } 1254 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_total_adults.std_error, "TOTALADULT-F2-SE");
1200 1255 }
1201 # Save the analyzed data. 1256 }
1202 write.csv(temperature_data_frame, file=opt$output, row.names=F); 1257
1258 # Save the analyzed data for combined generations.
1259 write.csv(temperature_data_frame, file=opt$output_combined, row.names=F);
1260 if (plot_generations_separately) {
1261 # Save the analyzed data for generation P.
1262 write.csv(temperature_data_frame_P, file=opt$output_p, row.names=F);
1263 # Save the analyzed data for generation F1.
1264 write.csv(temperature_data_frame_F1, file=opt$output_f1, row.names=F);
1265 # Save the analyzed data for generation F2.
1266 write.csv(temperature_data_frame_F2, file=opt$output_f2, row.names=F);
1267 }
1203 # Display the total number of days in the Galaxy history item blurb. 1268 # Display the total number of days in the Galaxy history item blurb.
1204 cat("Number of days: ", opt$num_days, "\n"); 1269 cat("Number of days: ", opt$num_days, "\n");
1205 # Information needed for plots plots. 1270 # Information needed for plots plots.
1206 days = c(1:opt$num_days); 1271 days = c(1:opt$num_days);
1207 start_date = temperature_data_frame$DATE[1]; 1272 start_date = temperature_data_frame$DATE[1];