|
| 1 | +# function to calculate the 5 outputs of certification measures |
| 2 | + |
| 3 | +certification_impact <- function(base_yield = prior_yield, |
| 4 | + base_market_price = prior_market_price, |
| 5 | + base_cost = prior_cost, |
| 6 | + cost_measure, |
| 7 | + # general yield benefit (without risk) |
| 8 | + yield_benefit, |
| 9 | + additional_benefits, |
| 10 | + event_risk, |
| 11 | + normal_damage, |
| 12 | + reduction_damage_measure, |
| 13 | + # second risk (risk caused by measure) |
| 14 | + negative_risk_event_measure, |
| 15 | + normal_damage_not_from_measure, |
| 16 | + increase_damage_by_measure, |
| 17 | + mitigation_factors, |
| 18 | + soil_quality, |
| 19 | + water_quality, |
| 20 | + biodiv_richness, |
| 21 | + var_CV, n_years) { |
| 22 | + |
| 23 | + # Positive effect of measure on a risk #### |
| 24 | + |
| 25 | + # create a vector of years with any risk events |
| 26 | + # these are independent of the measure, they just happen, like major weather events |
| 27 | + # (hurricane) |
| 28 | + event_years <- chance_event(event_risk, n = n_years) |
| 29 | + |
| 30 | + # calculate yield before intervention |
| 31 | + # i.e. what is the yield before the measure decreases that risk |
| 32 | + yield_no_measure <- ifelse(event_years, |
| 33 | + yes = 1 - normal_damage, |
| 34 | + no = 1) |
| 35 | + |
| 36 | + # calculate yield with intervention |
| 37 | + # i.e. what is the yield before the measure decreases that risk |
| 38 | + # 'reduction_damage_measure' is proportional to the total damage |
| 39 | + yield_measure <- ifelse(event_years, |
| 40 | + yes = 1 - (normal_damage * (1 - reduction_damage_measure)), |
| 41 | + no = 1) |
| 42 | + |
| 43 | + # relative mean annual yield with independent risk |
| 44 | + yield_positive_impact <- mean(yield_measure - yield_no_measure) |
| 45 | + |
| 46 | + # Negative effect of measure on risk #### |
| 47 | + |
| 48 | + #create a vector of years with risk events that the measure has a positive influence on |
| 49 | + #i.e. the measure will increase the risk (like waste water increases risk of salinity) |
| 50 | + negative_risk_event_measure_years <- chance_event(negative_risk_event_measure, |
| 51 | + n = n_years) |
| 52 | + |
| 53 | + # calculate yield before measure |
| 54 | + # i.e. what is the yield before the measure increases risk |
| 55 | + yield_no_negative_risk_event_measure <- ifelse(negative_risk_event_measure_years, |
| 56 | + yes = 1 - normal_damage_not_from_measure, |
| 57 | + no = 1) |
| 58 | + |
| 59 | + # calculate yield with measure |
| 60 | + # i.e. what is the yield after the measure when it increases risk |
| 61 | + yield_negative_risk_event_measure <- ifelse(negative_risk_event_measure_years, |
| 62 | + yes = 1 - (normal_damage_not_from_measure * |
| 63 | + (1 + increase_damage_by_measure)), |
| 64 | + no = 1) |
| 65 | + |
| 66 | + # relative mean annual yield with a risk that is increased by the measure |
| 67 | + # (i.e. waste water and salinity, competition with cover crops or buffer zones) |
| 68 | + yield_negative_impact <- mean(yield_negative_risk_event_measure - |
| 69 | + yield_no_negative_risk_event_measure) |
| 70 | + |
| 71 | + # estimate one unique proportional yield value given interactions of the measure |
| 72 | + # use the yield_negative_impact and yield_positive_impact from above |
| 73 | + # use the '+' because yield_negative_impact should always be negative |
| 74 | + proportional_yield_after_intervention <- yield_positive_impact + yield_negative_impact + |
| 75 | + # in the case that there is no risk event this is the yield benefit |
| 76 | + mean(vv(yield_benefit, var_CV, n_years)) |
| 77 | + |
| 78 | + # generate a value for the absolute yield (kg/ha/yr) after the measure |
| 79 | + # using the prior 'base_yield' from the input table |
| 80 | + yield <- base_yield * (1 + proportional_yield_after_intervention) |
| 81 | + |
| 82 | + # calculate the monetary value of bananas USD/ha/yr |
| 83 | + monetary_benefits_from_yield <- yield * base_market_price |
| 84 | + |
| 85 | + # use chance_event to calculate the relative mean risk reduction with measure |
| 86 | + risk_reduction <- mean( |
| 87 | + chance_event( |
| 88 | + event_risk, |
| 89 | + # normal damage vs. the percentage damage reduced by measure |
| 90 | + value_if = (normal_damage * (1 - reduction_damage_measure)), |
| 91 | + value_if_not = 0, |
| 92 | + CV_if = var_CV, |
| 93 | + CV_if_not = 0, |
| 94 | + n = n_years |
| 95 | + ) |
| 96 | + ) |
| 97 | + |
| 98 | + # use chance_event to calculate the relative mean risk increase from measure |
| 99 | + # the measure increases the risk |
| 100 | + risk_increase <- mean( |
| 101 | + chance_event( |
| 102 | + negative_risk_event_measure, |
| 103 | + # normal damage vs. the percentage damage reduced by measure |
| 104 | + value_if = (normal_damage_not_from_measure * (1 + increase_damage_by_measure)), |
| 105 | + value_if_not = 0, |
| 106 | + CV_if = var_CV, |
| 107 | + CV_if_not = 0, |
| 108 | + ) |
| 109 | + ) |
| 110 | + |
| 111 | + # relative mean benefits of measure |
| 112 | + # calculate yield to any additional benefits |
| 113 | + # can also be manipulated to be 'negative benefits' in case of disadvantages |
| 114 | + benefits <- monetary_benefits_from_yield + mean(vv(additional_benefits, var_CV, n_years)) |
| 115 | + |
| 116 | + # total costs over n_years |
| 117 | + # calculate the yield * base_cost to consider the economies of scale |
| 118 | + cost <- base_cost + mean(vv(cost_measure, var_CV, n_years)) |
| 119 | + |
| 120 | + # to eliminate the chance of negative costs |
| 121 | + if(cost < 0) cost <- 0 |
| 122 | + |
| 123 | + # relative mean adaptation impacts in USD per ha per yr |
| 124 | + adaptation <- benefits - cost |
| 125 | + |
| 126 | + # mitigation here is the mean of any reductions in parameters related to global |
| 127 | + # warming potential |
| 128 | + mitigation <- mean(vv(mitigation_factors, var_CV, n_years)) |
| 129 | + |
| 130 | + # simple ecological impact based on soil, water, biodiversity effects |
| 131 | + |
| 132 | + # how will ecological parameters change if measure is applied |
| 133 | + soil_impact <- mean(vv(soil_quality, var_CV, n_years)) |
| 134 | + |
| 135 | + water_impact <- mean(vv(water_quality, var_CV, n_years)) |
| 136 | + |
| 137 | + biodiv_richness_impact <- mean(vv(biodiv_richness, var_CV, n_years)) |
| 138 | + |
| 139 | + # sum all and divide by 100 because inputs are norm not t_norm_0_1 |
| 140 | + ecology <- sum(soil_impact, water_impact, biodiv_richness_impact)/100 |
| 141 | + |
| 142 | + # to reach proportional change in the final output for the model |
| 143 | + # we subtract the change from the prior and then divide it by the prior |
| 144 | + proportional_cost_after_intervention <- (cost - base_cost) / |
| 145 | + base_cost |
| 146 | + proportional_adaptation_after_intervention <- (adaptation - ((base_yield * base_market_price) - base_cost)) / |
| 147 | + ((base_yield * base_market_price) - base_cost) |
| 148 | + |
| 149 | + # define the outputs of the general function |
| 150 | + return(list(yield = proportional_yield_after_intervention, |
| 151 | + cost = proportional_cost_after_intervention, |
| 152 | + risk_increase = risk_increase, |
| 153 | + risk_reduction = risk_reduction, |
| 154 | + # adaptation is just the ratio of the intervention |
| 155 | + # income compare to base profit |
| 156 | + # use original base profit as baseline |
| 157 | + adaptation = proportional_adaptation_after_intervention, |
| 158 | + mitigation = mitigation, |
| 159 | + ecology = ecology |
| 160 | + )) |
| 161 | +} |
0 commit comments