comparison insect_phenology_model.R @ 54:5bb1d76c29ca draft

Uploaded
author greg
date Fri, 02 Nov 2018 11:16:46 -0400
parents b7c9837047d9
children 829518206949
comparison
equal deleted inserted replaced
53:b7c9837047d9 54:5bb1d76c29ca
227 mortality.probability = temperature * 0.0005 + 0.02; 227 mortality.probability = temperature * 0.0005 + 0.02;
228 } 228 }
229 return(mortality.probability) 229 return(mortality.probability)
230 } 230 }
231 231
232 mortality.egg = function(temperature) { 232 mortality.egg = function(temperature, adj=0) {
233 if (temperature < 12.7) { 233 # If no input from adjustment, default
234 mortality.probability = 0.8; 234 # value is 0 (data from Nielsen, 2008).
235 } 235 T.mortality = c(15, 17, 20, 25, 27, 30, 33, 35);
236 else { 236 egg.mortality = c(50, 2, 1, 0, 0, 0, 5, 100);
237 mortality.probability = 0.8 - temperature / 40.0; 237 # Calculates slopes and intercepts for lines.
238 if (mortality.probability < 0) { 238 slopes = NULL;
239 mortality.probability = 0.01; 239 intercepts = NULL;
240 } 240 for (i in 1:length(T.mortality)) {
241 } 241 slopes[i] = (egg.mortality[i+1] - egg.mortality[i]) / (T.mortality[i+1] - T.mortality[i]);
242 intercepts[i] = -slopes[i] * T.mortality[i] + egg.mortality[i];
243 }
244 # Calculates mortality based on temperature.
245 mortality.probability = NULL;
246 for (j in 1:length(temperature)) {
247 mortality.probability[j] = if(temperature[j] <= T.mortality[2]) {
248 temperature[j] * slopes[1] + intercepts[1];
249 } else if (temperature[j] > T.mortality[2] && temperature[j] <= T.mortality[3]) {
250 temperature[j] * slopes[2] + intercepts[2];
251 } else if (temperature[j] > T.mortality[3] && temperature[j] <= T.mortality[4]) {
252 temperature[j] * slopes[3] + intercepts[3];
253 } else if (temperature[j] > T.mortality[4] && temperature[j] <= T.mortality[5]) {
254 temperature[j] * slopes[4] + intercepts[4];
255 } else if (temperature[j] > T.mortality[5] && temperature[j] <= T.mortality[6]) {
256 temperature[j] * slopes[5] + intercepts[5];
257 } else if (temperature[j] > T.mortality[6] && temperature[j] <= T.mortality[7]) {
258 temperature[j] * slopes[6] + intercepts[6];
259 } else if (temperature[j] > T.mortality[7]) {
260 temperature[j] * slopes[7] + intercepts[7];
261 }
262 # If mortality > 100, make it equal to 100.
263 mortality.probability[mortality.probability>100] = 100;
264 # If mortality <0, make equal to 0.
265 mortality.probability[mortality.probability<0] = 0;
266 }
267 # Make mortality adjustments based on adj parameter.
268 mortality.probability = (100 - mortality.probability) * adj + mortality.probability;
269 # if mortality > 100, make it equal to 100.
270 mortality.probability[mortality.probability>100] = 100;
271 # If mortality <0, make equal to 0.
272 mortality.probability[mortality.probability<0] = 0;
273 # Change percent to proportion.
274 mortality.probability = mortality.probability / 100;
242 return(mortality.probability) 275 return(mortality.probability)
243 } 276 }
244 277
245 mortality.nymph = function(temperature) { 278 mortality.nymph = function(temperature) {
246 if (temperature < 12.7) { 279 if (temperature < 12.7) {
809 post.mortality = 2; 842 post.mortality = 2;
810 day.kill = 250; 843 day.kill = 250;
811 } 844 }
812 if (vector.individual[2] == 0) { 845 if (vector.individual[2] == 0) {
813 # Egg. 846 # Egg.
814 death.probability = opt$egg_mortality * mortality.egg(mean.temp); 847 death.probability = opt$egg_mortality * mortality.egg(mean.temp, adj=opt$egg_mortality);
815 } 848 }
816 else if (vector.individual[2] == 1 | vector.individual[2] == 2) { 849 else if (vector.individual[2] == 1 | vector.individual[2] == 2) {
817 # Nymph. 850 # Nymph.
818 death.probability = opt$nymph_mortality * mortality.nymph(mean.temp); 851 death.probability = opt$nymph_mortality * mortality.nymph(mean.temp);
819 } 852 }