#******************************************************************************* # Source file name "BR.r" # Function returns the fishing mortality vector (by age) # when the target condition is met # Function takes the following arguments: # - v the variance of the estimated mean # - mu is the estimated mean stock size # - f is the fishing mortality # - A_vec is an age vector fishing mortalities # - m is natural mortality # - pred_abund is predator abundance # - N is actual total population # - type_ is target type (N or F) # - target is target value #******************************************************************************* A_error <- 0.21 # Expressed as coefficent of variance (CV) A_bias <- 0.2 # Expressed as a proportion of A get_F_BQ <- function(v,mu,m,pred_abund,N,type_,target){ # error_lim_F/N is the allowed error error_lim_F <- target/10000 error_lim_N <- target/10000 A <- 1 # Fishing mortality multiplier. Used for a whole year it gives F A_vec <- rep(A,nofageclasses) * selectivity A_hat <- rnorm(1,mean=A*(1+A_bias), sd=A_error*(A*(1+A_bias))) # Error expressed as CV alpha <- 1 + (m/A_hat) betha <- function(t1){ return ((1-(exp(-(m+A_hat)*t1)))/(1-(exp(-A_hat*t1))))} # Get the catch from OPMOD with t1 effort g_ <- function(t1) { return (get_hypo_catch_N(t1,A_vec,pred_abund)) } # Here we use the actual A_vec to generate catch. r <- function(t1){ return ((mu-betha(t1)*g_(t1)*(1-(v/mu))) /((exp(alpha*A_hat*t1)-1)*(v/mu)+1)) } # Whereas here an estimated A (A_hat) is used. if(type_ == "NMSY"){ # Initial test if fishing should occur t1 <- 1e-4 # Remove the natural mortality that occurs after fishing to the end of year assessed_target <- r(t1)*exp((t1-1)*m) if(assessed_target < target) return(A_vec*0) # Test if target can be obtained within one year t1 <- 1 assessed_target <- r(t1)*exp((t1-1)*m) if(assessed_target > target){ return (A_vec*t1) } # Find t t1 <- timestep <- 1 # Initial value of assessed_target prepared for the first step in the loop assessed_target <- target + 4*error_lim_N while(abs(target - assessed_target) > error_lim_N){ assessed_target <- r(t1)*exp((t1-1)*m) if(assessed_target == target){ return (A_vec*t1) } # Returns the actual F if(assessed_target > target){ t1 <- t1 + timestep/2 } if(assessed_target < target){ t1 <- t1 - timestep/2 } timestep <- timestep/2 } } if(type_ == "FMSY"){ # Modify target to match non-yearly F target <- 1-exp(-target) # If target cannot be obtained within one year t1 <- 1 assessed_target <- g_(t1)/(alpha*g_(t1)+r(t1)) if(assessed_target < target){ return (A_vec*t1) } # Find t t1 <- timestep <- 1 # Initial value of assessed_target prepared for the first step in the loop assessed_target <- target + 4*error_lim_F while(abs(target - assessed_target) > error_lim_F){ assessed_target <- g_(t1)/(alpha*g_(t1)+r(t1)) if(assessed_target == target){ return (A_vec*t1) } # Returns the actual F if(assessed_target > target){ t1 <- t1 - timestep/2 } if(assessed_target < target){ t1 <- t1 + timestep/2 } timestep <- timestep/2 } } if(type_ == "0"){ print(paste("mu",mu,sep=" ")) print(paste("assessed target",assessed_target,sep=" ")) print(paste("target",target,sep=" ")) } return(A_vec*t1) } #*******************************************************************************