Mercurial > repos > greg > insect_phenology_model
comparison insect_phenology_model.R @ 63:c5df0777fa31 draft
Uploaded
author | greg |
---|---|
date | Fri, 08 Nov 2019 13:01:48 -0500 |
parents | 3116ddd4c26d |
children | 883d812611b3 |
comparison
equal
deleted
inserted
replaced
62:3116ddd4c26d | 63:c5df0777fa31 |
---|---|
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 (adj == 0) { | 254 # If no input from adjustment, default |
255 # If no input from adjustment, default | 255 # value is 0 (data from Nielsen, 2008). |
256 # value is 0 (data from Nielsen, 2008). | 256 T.mortality = c(15, 17, 20, 25, 27, 30, 33, 35); |
257 T.mortality = c(15, 17, 20, 25, 27, 30, 33, 35); | 257 egg.mortality = c(50, 2, 1, 0, 0, 0, 5, 100); |
258 egg.mortality = c(50, 2, 1, 0, 0, 0, 5, 100); | 258 # Calculates slopes and intercepts for lines. |
259 # Calculates slopes and intercepts for lines. | 259 slopes = NULL; |
260 slopes = NULL; | 260 intercepts = NULL; |
261 intercepts = NULL; | 261 for (i in 1:length(T.mortality)) { |
262 for (i in 1:length(T.mortality)) { | 262 slopes[i] = (egg.mortality[i+1] - egg.mortality[i]) / (T.mortality[i+1] - T.mortality[i]); |
263 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]; |
264 intercepts[i] = -slopes[i] * T.mortality[i] + egg.mortality[i]; | 264 } |
265 } | 265 # Calculates mortality based on temperature. |
266 # Calculates mortality based on temperature. | 266 mortality.probability = NULL; |
267 mortality.probability = NULL; | 267 for (j in 1:length(temperature)) { |
268 for (j in 1:length(temperature)) { | 268 mortality.probability[j] = if(temperature[j] <= T.mortality[2]) { |
269 mortality.probability[j] = if(temperature[j] <= T.mortality[2]) { | 269 temperature[j] * slopes[1] + intercepts[1]; |
270 temperature[j] * slopes[1] + intercepts[1]; | 270 } else if (temperature[j] > T.mortality[2] && temperature[j] <= T.mortality[3]) { |
271 } else if (temperature[j] > T.mortality[2] && temperature[j] <= T.mortality[3]) { | 271 temperature[j] * slopes[2] + intercepts[2]; |
272 temperature[j] * slopes[2] + intercepts[2]; | 272 } else if (temperature[j] > T.mortality[3] && temperature[j] <= T.mortality[4]) { |
273 } else if (temperature[j] > T.mortality[3] && temperature[j] <= T.mortality[4]) { | 273 temperature[j] * slopes[3] + intercepts[3]; |
274 temperature[j] * slopes[3] + intercepts[3]; | 274 } else if (temperature[j] > T.mortality[4] && temperature[j] <= T.mortality[5]) { |
275 } else if (temperature[j] > T.mortality[4] && temperature[j] <= T.mortality[5]) { | 275 temperature[j] * slopes[4] + intercepts[4]; |
276 temperature[j] * slopes[4] + intercepts[4]; | 276 } else if (temperature[j] > T.mortality[5] && temperature[j] <= T.mortality[6]) { |
277 } else if (temperature[j] > T.mortality[5] && temperature[j] <= T.mortality[6]) { | 277 temperature[j] * slopes[5] + intercepts[5]; |
278 temperature[j] * slopes[5] + intercepts[5]; | 278 } else if (temperature[j] > T.mortality[6] && temperature[j] <= T.mortality[7]) { |
279 } else if (temperature[j] > T.mortality[6] && temperature[j] <= T.mortality[7]) { | 279 temperature[j] * slopes[6] + intercepts[6]; |
280 temperature[j] * slopes[6] + intercepts[6]; | 280 } else if (temperature[j] > T.mortality[7]) { |
281 } else if (temperature[j] > T.mortality[7]) { | 281 temperature[j] * slopes[7] + intercepts[7]; |
282 temperature[j] * slopes[7] + intercepts[7]; | 282 } |
283 } | 283 # If mortality > 100, make it equal to 100. |
284 # If mortality > 100, make it equal to 100. | |
285 mortality.probability[mortality.probability>100] = 100; | |
286 # If mortality <0, make equal to 0. | |
287 mortality.probability[mortality.probability<0] = 0; | |
288 } | |
289 } else { | |
290 # Make mortality adjustments based on adj parameter. | |
291 mortality.probability = (100 - mortality.probability) * adj + mortality.probability; | |
292 # if mortality > 100, make it equal to 100. | |
293 mortality.probability[mortality.probability>100] = 100; | 284 mortality.probability[mortality.probability>100] = 100; |
294 # If mortality <0, make equal to 0. | 285 # If mortality <0, make equal to 0. |
295 mortality.probability[mortality.probability<0] = 0; | 286 mortality.probability[mortality.probability<0] = 0; |
296 # Change percent to proportion. | 287 } |
297 mortality.probability = mortality.probability / 100; | 288 # Make mortality adjustments based on adj parameter. |
298 } | 289 mortality.probability = (100 - mortality.probability) * adj + mortality.probability; |
290 # if mortality > 100, make it equal to 100. | |
291 mortality.probability[mortality.probability>100] = 100; | |
292 # If mortality <0, make equal to 0. | |
293 mortality.probability[mortality.probability<0] = 0; | |
294 # Change percent to proportion. | |
295 mortality.probability = mortality.probability / 100; | |
296 } | |
299 return(mortality.probability) | 297 return(mortality.probability) |
300 } | 298 } |
301 | 299 |
302 mortality.nymph = function(temperature) { | 300 mortality.nymph = function(temperature) { |
303 if (temperature < 12.7) { | 301 if (temperature < 12.7) { |