predict.r

text/plain — 1.1 KB

File contents

# predict.r
# forward projection routine
# "few" true ages, a=1,...,A and a plus group
#  Data:  indices for each age group
#         and catch (yield)
#         w: vector of length A+1 - weight at age 
#  Parameters:
#   Recr, Fmort,
#   selpat: vector of length A+1 - selection pattern
#   Ninit : vector of length A+1 - initial pop size
#   M,q
# 
#  Dimensions:  A=#true ages
#               numyears= # years
predict<-function(Fmort,Recr){
  Rtemp<-Recr[1]
  Ninit<-Rtemp*exp(-(0:A)*M)  # First start-of-year stock size - equil.

  Nmat<-Ninit
  N0<-Ninit
  Yhat<-c()
  for(y in 1:(numyears-1)){
    Z<-Fmort[y]*selpat+M
    C<-((Fmort[y]*selpat)/Z)*(1-exp(-Z))*N0
    Yhat<-c(Yhat,sum(w*C))
    N1<-c(Recr[y+1],N0[1:(A-1)]*exp(-Fmort[y]*selpat[1:(A-1)]-M),
          N0[A]*exp(-Fmort[y]*selpat[A]-M)+
          N0[A+1]*exp(-Fmort[y]*selpat[A+1]-M))
    Nmat<-rbind(Nmat,N1)
    N0<-N1
  }
  Z<-Fmort[numyears]*selpat+M
  C<-((Fmort[numyears]*selpat)/Z)*(1-exp(-Z))*N0
  Yhat<-c(Yhat,sum(w*C))
  dimnames(Nmat)<-list(Years=1:(numyears),Ages=c(1:A,"+"))
  return(list(Yhat=Yhat,Nmat=Nmat))
}