comparison insect_phenology_model.R @ 61:734f8e4dfbe5 draft

Uploaded
author greg
date Wed, 06 Nov 2019 08:30:47 -0500
parents 393085589438
children 3116ddd4c26d
comparison
equal deleted inserted replaced
60:393085589438 61:734f8e4dfbe5
248 mortality.probability = temperature * 0.0005 + 0.02; 248 mortality.probability = temperature * 0.0005 + 0.02;
249 } 249 }
250 return(mortality.probability) 250 return(mortality.probability)
251 } 251 }
252 252
253 #mortality.egg = function(temperature, adj=0) { 253 mortality.egg = function(temperature, adj=0) {
254 # # If no input from adjustment, default 254 # If no input from adjustment, default
255 # # value is 0 (data from Nielsen, 2008). 255 # value is 0 (data from Nielsen, 2008).
256 # T.mortality = c(15, 17, 20, 25, 27, 30, 33, 35); 256 T.mortality = c(15, 17, 20, 25, 27, 30, 33, 35);
257 # egg.mortality = c(50, 2, 1, 0, 0, 0, 5, 100); 257 egg.mortality = c(50, 2, 1, 0, 0, 0, 5, 100);
258 # # Calculates slopes and intercepts for lines. 258 # Calculates slopes and intercepts for lines.
259 # slopes = NULL; 259 slopes = NULL;
260 # intercepts = NULL; 260 intercepts = NULL;
261 # for (i in 1:length(T.mortality)) { 261 for (i in 1:length(T.mortality)) {
262 # slopes[i] = (egg.mortality[i+1] - egg.mortality[i]) / (T.mortality[i+1] - T.mortality[i]); 262 slopes[i] = (egg.mortality[i+1] - egg.mortality[i]) / (T.mortality[i+1] - T.mortality[i]);
263 # intercepts[i] = -slopes[i] * T.mortality[i] + egg.mortality[i]; 263 intercepts[i] = -slopes[i] * T.mortality[i] + egg.mortality[i];
264 # } 264 }
265 # # Calculates mortality based on temperature. 265 # Calculates mortality based on temperature.
266 # mortality.probability = NULL; 266 mortality.probability = NULL;
267 # for (j in 1:length(temperature)) { 267 for (j in 1:length(temperature)) {
268 # mortality.probability[j] = if(temperature[j] <= T.mortality[2]) { 268 mortality.probability[j] = if(temperature[j] <= T.mortality[2]) {
269 # temperature[j] * slopes[1] + intercepts[1]; 269 temperature[j] * slopes[1] + intercepts[1];
270 # } else if (temperature[j] > T.mortality[2] && temperature[j] <= T.mortality[3]) { 270 } else if (temperature[j] > T.mortality[2] && temperature[j] <= T.mortality[3]) {
271 # temperature[j] * slopes[2] + intercepts[2]; 271 temperature[j] * slopes[2] + intercepts[2];
272 # } else if (temperature[j] > T.mortality[3] && temperature[j] <= T.mortality[4]) { 272 } else if (temperature[j] > T.mortality[3] && temperature[j] <= T.mortality[4]) {
273 # temperature[j] * slopes[3] + intercepts[3]; 273 temperature[j] * slopes[3] + intercepts[3];
274 # } else if (temperature[j] > T.mortality[4] && temperature[j] <= T.mortality[5]) { 274 } else if (temperature[j] > T.mortality[4] && temperature[j] <= T.mortality[5]) {
275 # temperature[j] * slopes[4] + intercepts[4]; 275 temperature[j] * slopes[4] + intercepts[4];
276 # } else if (temperature[j] > T.mortality[5] && temperature[j] <= T.mortality[6]) { 276 } else if (temperature[j] > T.mortality[5] && temperature[j] <= T.mortality[6]) {
277 # temperature[j] * slopes[5] + intercepts[5]; 277 temperature[j] * slopes[5] + intercepts[5];
278 # } else if (temperature[j] > T.mortality[6] && temperature[j] <= T.mortality[7]) { 278 } else if (temperature[j] > T.mortality[6] && temperature[j] <= T.mortality[7]) {
279 # temperature[j] * slopes[6] + intercepts[6]; 279 temperature[j] * slopes[6] + intercepts[6];
280 # } else if (temperature[j] > T.mortality[7]) { 280 } else if (temperature[j] > T.mortality[7]) {
281 # temperature[j] * slopes[7] + intercepts[7]; 281 temperature[j] * slopes[7] + intercepts[7];
282 # } 282 }
283 # # If mortality > 100, make it equal to 100. 283 # If mortality > 100, make it equal to 100.
284 # mortality.probability[mortality.probability>100] = 100; 284 mortality.probability[mortality.probability>100] = 100;
285 # # If mortality <0, make equal to 0. 285 # If mortality <0, make equal to 0.
286 # mortality.probability[mortality.probability<0] = 0; 286 mortality.probability[mortality.probability<0] = 0;
287 # } 287 }
288 # # Make mortality adjustments based on adj parameter. 288 # Make mortality adjustments based on adj parameter.
289 # mortality.probability = (100 - mortality.probability) * adj + mortality.probability; 289 mortality.probability = (100 - mortality.probability) * adj + mortality.probability;
290 # # if mortality > 100, make it equal to 100. 290 # if mortality > 100, make it equal to 100.
291 # mortality.probability[mortality.probability>100] = 100; 291 mortality.probability[mortality.probability>100] = 100;
292 # # If mortality <0, make equal to 0. 292 # If mortality <0, make equal to 0.
293 # mortality.probability[mortality.probability<0] = 0; 293 mortality.probability[mortality.probability<0] = 0;
294 # # Change percent to proportion. 294 # Change percent to proportion.
295 # mortality.probability = mortality.probability / 100; 295 mortality.probability = mortality.probability / 100;
296 # return(mortality.probability) 296 return(mortality.probability)
297 #}
298
299 mortality.egg = function(temperature) {
300 if (temperature < 12.7) {
301 mortality.probability = 0.8;
302 } else {
303 mortality.probability = 0.8 - temperature / 40.0;
304 if (mortality.probability < 0) {
305 mortality.probability = 0.01;
306 }
307 }
308 return (mortality.probability);
309 } 297 }
310 298
311 mortality.nymph = function(temperature) { 299 mortality.nymph = function(temperature) {
312 if (temperature < 12.7) { 300 if (temperature < 12.7) {
313 mortality.probability = 0.03; 301 mortality.probability = 0.03;