tokami / TropFishR

Tropical Fisheries Analysis with R
24 stars 19 forks source link

predict_mod() error: Error in if (!is.na(curr.E)) { : argument is of length zero #46

Closed shaniAmare closed 1 year ago

shaniAmare commented 1 year ago

Hi @tokami ,

I have been playing around with TropFishR using some dummy data. Thank you for this package. At this point, I'm getting an error with the following.

> TB1 <- predict_mod(lfq_catch_vec, type = "ThompBell",
+                    FM_change = seq(0,1.5,0.05),
+                    stock_size_1 = 1,
+                    curr.E = lfq_catch_vec$par$E,
+                    s_list = selectivity_list,
+                    plot = FALSE, hide.progressbar = TRUE)

Error is:

Error in if (!is.na(curr.E)) { : argument is of length zero
In addition: Warning message:
In max(FM, na.rm = TRUE) : no non-missing arguments to max; returning -Inf

My lfq_catch_vec is below.

> lfq_catch_vec
$dates
[1] "2005-01-01" "2006-01-01" "2007-01-01"

$midLengths
[1] 11 13 15 17 19 21 23 25 27

$catch
   X2005 X2006 X2007
V1     5    11     2
V2    22    49    15
V3    66   139    22
V4   106   337    69
V5   166   477   133
V6   243   421   115
V7   209   308    68
V8   112   168    49
V9   105   145    19

$par
$par$Linf
[1] 27.18388

$par$K
[1] 0.7627744

$par$t_anchor
[1] 0.6635739

$par$C
[1] 0.5911645

$par$ts
[1] 0.6136335

$par$phiL
[1] 2.751019

$par$M
[1] 1.136

$par$FM
numeric(0)

$par$E
numeric(0)

$par$a
[1] 0.015

$par$b
[1] 3

$par$Lmat
[1] 35

$par$wmat
[1] 5

attr(,"class")
[1] "lfq"

My data has three years. So this now has three columns. Definitely above I can see that lfq_catch_vec$par$E is 0. But why is that? Have I done something suboptimal while generating this object? This is how I generated the lfq_catch_vec.

## define plus group as largest length class smaller than Linf
plus_group <- lfq_bin2$midLengths[max(which(lfq_bin2$midLengths < lfq_bin2$par$Linf))]

## summarise catch matrix into vector and add plus group
lfq_catch_vec <- lfqModify(lfq_bin2, vectorise_catch = TRUE, plus_group = plus_group)

And this is my lfq_bin2 object.

> lfq_bin2
$dates
 [1] "2005-04-15" "2005-05-15" "2005-07-15" "2005-08-15" "2005-09-15"
 [6] "2005-10-15" "2005-11-15" "2005-12-15" "2006-01-15" "2006-02-15"
[11] "2006-03-15" "2006-04-15" "2006-05-15" "2006-06-15" "2006-07-15"
[16] "2006-09-15" "2006-10-15" "2006-11-15" "2006-12-15" "2007-01-15"
[21] "2007-02-15" "2007-03-15"

$midLengths
 [1] 11 13 15 17 19 21 23 25 27 29 31

$catch
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
 [1,]    3    0    1    0    0    0    0    1    0     3     2     4     0
 [2,]    8    1    3    0    3    1    3    3    1     3     7    17     3
 [3,]   17    6    6    3    4    4   17    9    7     6    11    31     7
 [4,]   16   20   11    6   12   11   16   14   38    15    15    32    20
 [5,]   31   27   11   11   20   21   22   23   48    34    35    55    25
 [6,]   22   60   45   42   22   21   11   20   41    35    45    49    58
 [7,]   22   38   29   30   28   27   21   14   24    28    38    48    38
 [8,]   17   18   13    6   23   23    5    7   13    14    20    35    14
 [9,]    9   15   11    5   11   11    4    4    2    10    14    19    12
[10,]    6    7    4    2    3    3    1    1    0     5    11    10    12
[11,]    1    2    2    0    1    0    2    0    0     2     4     6     3
      [,14] [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22]
 [1,]     0     0     2     0     0     0     1     1     0
 [2,]     1     4     5     6     1     1     2     9     4
 [3,]     4    15    32    12    11     3     4     5    13
 [4,]     7    47    50    30    64    19    31    33     5
 [5,]     8    78    44    50    71    29    52    57    24
 [6,]    16    67    26    25    41    18    46    41    28
 [7,]    10    41    17    26    24    14    28    31     9
 [8,]     4    16     6    15    17    14    19    25     5
 [9,]     5     7     3     1     6     2     5     5     4
[10,]     3     2     1     0     2     0     2     1     1
[11,]     1     2     0     0     0     0     1     0     0

$par
$par$Linf
[1] 27.18388

$par$K
[1] 0.7627744

$par$t_anchor
[1] 0.6635739

$par$C
[1] 0.5911645

$par$ts
[1] 0.6136335

$par$phiL
[1] 2.751019

$par$M
[1] 1.136

attr(,"class")
[1] "lfq"

You feedback is very much appreciated.

Thanks, Shani.

shaniAmare commented 1 year ago

I realised that I have not been setting the par$FM and par$z values correctly. Once I did that, it worked fine. Thanks.