# \donttest{
library(knobi)
data(knobi_dataset)
hake_n <- knobi_dataset$hake_n
# Then, create the data object.
data<-list()
data$SSB<-hake_n$SSB # We take the SSB in our data.
data$Catch<-hake_n$catches # We take the catch in our data.
data$F_input<-hake_n$F # We take the F in our data.
# Reference points estimates from ICES stock assessment model:
# ICES. 2021. Working Group for the Bay of Biscay and the Iberian Waters Ecoregion
# (WGBIE). ICES Scientific Reports. 3:48.1101 pp.
data$RP<-list(F_MSY=0.259, B_MSY=207398, MSY=75052, K=NA)
# In this case, B_MSY corresponds to SSB_MSY, since control$method<-"SSB"
# (see control list below).
data$years<-hake_n$Year # Years corresponding to the catch values
# (can be different than the years corresponding to SSB or biomass).
# Now we define the control.
control<-list(
pella = "TRUE") # Logical. TRUE for Pella-Tomlinson model.
# FALSE for Schaefer model.
# Finally, we can fit the model
knobi_results<-knobi_fit(data,control,plot_out=TRUE,plot_filename="results")
# Note that a warning is shown for the reduction of the SSB vector
# so that the length is the same as the catch length
knobi_results
knobi_results$BRPs # use the '$' to access to all the fit information
## Fitting multispecific KBPM
# Below, a multistock approximation aggregating the
# northern and southern stocks of sardine is performed.
# Firstly, read southern stock data
sardine1 <- knobi_dataset$sardine_s
# Secondly, read northern stock data
sardine2 <- knobi_dataset$sardine_n
# Extract common years of data in both stocks
index <- which(sardine1$Year %in% sardine2$Year)
sardine1 <- sardine1[index,]
# Create a data.frame where the SSB and the catch are
# the sum of such data in the two stocks
years<-sardine1$Year
sardine <- data.frame(years=years,SSB=sardine1$SSB+sardine2$SSB,
catch=sardine1$catches+sardine2$catches)
# Once the total SSB and catch are available
# we follow previous KBPM illustration
data<-list()
data$SSB<-sardine$SSB
data$Catch<-sardine$catch
data$years<-sardine$years
knobi_results2<-knobi_fit(data)
# In this case, in addition, a series of warnings are shown due to
# the SP being less than 0 for some year.
knobi_results2
# }
Run the code above in your browser using DataLab