# This file should be named Sensitivity_function.R # A function that returns the sensitivity of the annual surveys in 2000-2018 # for all the regions and Finland in one array, in which # dimension 1 = years, dimension 2 = regions (regions columns 1-15, Finland column 16), dimension 3 = iterations Sensitivity <- function(scenario, DP_wood, DP_Monochamus, DPr, site_wood, site_Monochamus, n_i){ ########## # CALLING FOR THE DATA NEEDED # The number of wood objects suitable for sampling per inspection site p_wood = p_wood_data(n_y,n_i) # The number of Monochamus adults per inspection site p_Monochamus = p_Monochamus_data(n_y,n_i) # The number of wood samples collected per inspection site n_wood <- round(rpert(n_i,1,2,5,1)) # The number of inspected sites in the wood sampling component of the survey N_wood = N_wood_data(n_y,n_i) # The number of Monochamus samples collected per inspection site n_Monochamus = n_Monochamus_data(n_y,n_i) # The number of inspected sites in the Monochamus trapping component of the survey N_Monochamus = N_Monochamus_data(n_y,n_i) # The relative probability of invasion in the regions RP = RP_data(n_y,n_i) # The effective probability of invasion for the import-export survey and # the regional-level design prevalence for the early detection survey DPr_adj = DPr_adj_data(scenario,n_y,n_i) ########## # CALCULATING INSPECTION SENSITIVITY ISe_wood = 1 - (1 - ((n_wood)/(p_wood - 0.5*(p_wood*DP_wood-1))))^(p_wood*DP_wood) ISe_Monochamus = 1 - (1 - ((n_Monochamus)/(p_Monochamus - 0.5*(p_Monochamus*DP_Monochamus-1))))^(p_Monochamus*DP_Monochamus) ##### # CALCULATING THE SENSITIVITY OF ANNUAL SURVEYS IN THE REGIONS # (separately for wood sampling and Monochamus trapping) GSe_wood = 1 - (1 - (DPr_adj*ISe_wood))^N_wood GSe_Monochamus = 1 - (1 - (DPr_adj*ISe_Monochamus))^N_Monochamus ##### # CALCULATING THE SENSITIVITY OF ANNUAL SURVEYS IN THE REGIONS AND IN FINLAND # (wood sampling and Monochamus trapping combined) # Arrays for storing the results # w = wood, m = Monochamus, wm = wood and Monochamus GSe_wm <- array(0,dim=c(n_y,15,n_i)) SSe_w_FI <- array(0,dim=c(n_y,n_i)) SSe_m_FI <- array(0,dim=c(n_y,n_i)) SSe_wm_FI <- array(0,dim=c(n_y,n_i)) for (k in 1:n_i){ for(t in 1:n_y){ # Regions GSe_wm[t,,k] = 1 - (1-GSe_wood[t,,k])*(1-GSe_Monochamus[t,,k]) # Finland # Import-export if(scenario == 1){ SSe_w_FI[t,k] = 1 - prod(1-GSe_wood[t,,k]) SSe_m_FI[t,k] = 1 - prod(1-GSe_Monochamus[t,,k]) SSe_wm_FI[t,k] = 1 - (1-SSe_w_FI[t,k])*(1-SSe_m_FI[t,k]) # Early detection }else{ SSe_wm_FI[t,k] = sum(GSe_wm[t,,k]*RP[t,,k]) } } } ##### # RETURN ALL THE RESULTS IN ONE ARRAY # Regions in columns 1-15, Finland in column 16 Sensitivity_all <- array(0,dim=c(n_y,16,n_i)) Sensitivity_all[,1:15,] = GSe_wm Sensitivity_all[,16,] = SSe_wm_FI return(Sensitivity_all)}