Mercurial > repos > greg > insect_phenology_model
changeset 61:734f8e4dfbe5 draft
Uploaded
author | greg |
---|---|
date | Wed, 06 Nov 2019 08:30:47 -0500 |
parents | 393085589438 |
children | 3116ddd4c26d |
files | insect_phenology_model.R |
diffstat | 1 files changed, 43 insertions(+), 55 deletions(-) [+] |
line wrap: on
line diff
--- a/insect_phenology_model.R Thu Dec 20 09:15:52 2018 -0500 +++ b/insect_phenology_model.R Wed Nov 06 08:30:47 2019 -0500 @@ -250,62 +250,50 @@ return(mortality.probability) } -#mortality.egg = function(temperature, adj=0) { -# # If no input from adjustment, default -# # value is 0 (data from Nielsen, 2008). -# T.mortality = c(15, 17, 20, 25, 27, 30, 33, 35); -# egg.mortality = c(50, 2, 1, 0, 0, 0, 5, 100); -# # Calculates slopes and intercepts for lines. -# slopes = NULL; -# intercepts = NULL; -# for (i in 1:length(T.mortality)) { -# slopes[i] = (egg.mortality[i+1] - egg.mortality[i]) / (T.mortality[i+1] - T.mortality[i]); -# intercepts[i] = -slopes[i] * T.mortality[i] + egg.mortality[i]; -# } -# # Calculates mortality based on temperature. -# mortality.probability = NULL; -# for (j in 1:length(temperature)) { -# mortality.probability[j] = if(temperature[j] <= T.mortality[2]) { -# temperature[j] * slopes[1] + intercepts[1]; -# } else if (temperature[j] > T.mortality[2] && temperature[j] <= T.mortality[3]) { -# temperature[j] * slopes[2] + intercepts[2]; -# } else if (temperature[j] > T.mortality[3] && temperature[j] <= T.mortality[4]) { -# temperature[j] * slopes[3] + intercepts[3]; -# } else if (temperature[j] > T.mortality[4] && temperature[j] <= T.mortality[5]) { -# temperature[j] * slopes[4] + intercepts[4]; -# } else if (temperature[j] > T.mortality[5] && temperature[j] <= T.mortality[6]) { -# temperature[j] * slopes[5] + intercepts[5]; -# } else if (temperature[j] > T.mortality[6] && temperature[j] <= T.mortality[7]) { -# temperature[j] * slopes[6] + intercepts[6]; -# } else if (temperature[j] > T.mortality[7]) { -# temperature[j] * slopes[7] + intercepts[7]; -# } -# # If mortality > 100, make it equal to 100. -# mortality.probability[mortality.probability>100] = 100; -# # If mortality <0, make equal to 0. -# mortality.probability[mortality.probability<0] = 0; -# } -# # Make mortality adjustments based on adj parameter. -# mortality.probability = (100 - mortality.probability) * adj + mortality.probability; -# # if mortality > 100, make it equal to 100. -# mortality.probability[mortality.probability>100] = 100; -# # If mortality <0, make equal to 0. -# mortality.probability[mortality.probability<0] = 0; -# # Change percent to proportion. -# mortality.probability = mortality.probability / 100; -# return(mortality.probability) -#} - -mortality.egg = function(temperature) { - if (temperature < 12.7) { - mortality.probability = 0.8; - } else { - mortality.probability = 0.8 - temperature / 40.0; - if (mortality.probability < 0) { - mortality.probability = 0.01; - } +mortality.egg = function(temperature, adj=0) { + # If no input from adjustment, default + # value is 0 (data from Nielsen, 2008). + T.mortality = c(15, 17, 20, 25, 27, 30, 33, 35); + egg.mortality = c(50, 2, 1, 0, 0, 0, 5, 100); + # Calculates slopes and intercepts for lines. + slopes = NULL; + intercepts = NULL; + for (i in 1:length(T.mortality)) { + slopes[i] = (egg.mortality[i+1] - egg.mortality[i]) / (T.mortality[i+1] - T.mortality[i]); + intercepts[i] = -slopes[i] * T.mortality[i] + egg.mortality[i]; } - return (mortality.probability); + # Calculates mortality based on temperature. + mortality.probability = NULL; + for (j in 1:length(temperature)) { + mortality.probability[j] = if(temperature[j] <= T.mortality[2]) { + temperature[j] * slopes[1] + intercepts[1]; + } else if (temperature[j] > T.mortality[2] && temperature[j] <= T.mortality[3]) { + temperature[j] * slopes[2] + intercepts[2]; + } else if (temperature[j] > T.mortality[3] && temperature[j] <= T.mortality[4]) { + temperature[j] * slopes[3] + intercepts[3]; + } else if (temperature[j] > T.mortality[4] && temperature[j] <= T.mortality[5]) { + temperature[j] * slopes[4] + intercepts[4]; + } else if (temperature[j] > T.mortality[5] && temperature[j] <= T.mortality[6]) { + temperature[j] * slopes[5] + intercepts[5]; + } else if (temperature[j] > T.mortality[6] && temperature[j] <= T.mortality[7]) { + temperature[j] * slopes[6] + intercepts[6]; + } else if (temperature[j] > T.mortality[7]) { + temperature[j] * slopes[7] + intercepts[7]; + } + # If mortality > 100, make it equal to 100. + mortality.probability[mortality.probability>100] = 100; + # If mortality <0, make equal to 0. + mortality.probability[mortality.probability<0] = 0; + } + # Make mortality adjustments based on adj parameter. + mortality.probability = (100 - mortality.probability) * adj + mortality.probability; + # if mortality > 100, make it equal to 100. + mortality.probability[mortality.probability>100] = 100; + # If mortality <0, make equal to 0. + mortality.probability[mortality.probability<0] = 0; + # Change percent to proportion. + mortality.probability = mortality.probability / 100; + return(mortality.probability) } mortality.nymph = function(temperature) {