Calculate the relative error (RE; \([EM - OM]/OM\)) of parameters and derived quantities stored in a scalar or time series data frame generated by get_results_all().

calculate_re(dat, add = TRUE, EM = "em")

Arguments

dat

An input data frame. Should be either a scalar or time series data frame as returned from get_results_all() or a related get_results_*(). Specifically, the data frame needs to have columns with _em and _om as names. If the data is provided in long rather than wide format, then convert_to_wide() will be used internally before calculating RE and a wide data frame will be returned.

add

Logical: should the relative error columns be added to dat or should the original EM and OM columns be dropped? If FALSE, then the returned data frame will have only the identifying columns and the new relative error columns. You could then merge selected columns back into dat if you wished. The default is to return all columns.

EM

A character value specifying the name of the EM to calculate the RE of when the results are provided in long format and there is the potential for multiple EMs. See the column model_run for options.

Value

The default is to return a data frame structured the same as the input data frame, i.e., dat, but with additional columns, where '_re' is appended to the base string of the column name. All NAN and Inf values are returned as NA values, typically because you cannot divide by zero. Irrelevant columns, i.e., columns of entirely zero of NA are removed prior to returning the data frame.

Author

Sean Anderson and Cole Monnahan

Examples

# Example with built in package data:
data("ts_dat", package = "ss3sim")
data("scalar_dat", package = "ss3sim")
head(calculate_re(ts_dat))
#> Warning: number of columns of result is not a multiple of vector length (arg 1)
#>   year iteration          scenario SpawnBio_om Recruit_0_om F._1_om SPRratio_om
#> 1    1         1      D0-E0-F0-cod  4084180000    166353000       0 1.11022e-16
#> 2    1         1      D0-E1-F0-cod  4084180000    166353000       0 1.11022e-16
#> 3    1         1      D1-E0-F0-cod  4084180000    166353000       0 1.11022e-16
#> 4    1         1      D1-E1-F0-cod  4084180000    166353000       0 1.11022e-16
#> 5    1         1    D1-E100-F0-cod  4084180000    132223000       0 1.11022e-16
#> 6    1         1 D1-E101-F0-M1-cod  4084180000    132223000       0 1.11022e-16
#>     rec_dev_om raw_rec_dev_om SpawnBio_em Recruit_0_em F._1_em SPRratio_em
#> 1  2.29622e-01       0.229622          NA           NA      NA          NA
#> 2  2.29622e-01       0.229622          NA           NA      NA          NA
#> 3  2.29622e-01       0.229622          NA           NA      NA          NA
#> 4  2.29622e-01       0.229622          NA           NA      NA          NA
#> 5 -1.11022e-16       0.000000          NA           NA      NA          NA
#> 6 -1.11022e-16       0.000000          NA           NA      NA          NA
#>   rec_dev_em raw_rec_dev_em                  ID  D    E  F   c species F._1_re
#> 1         NA             NA      D0-E0-F0-cod-1 D0   E0 F0 cod      D0      NA
#> 2         NA             NA      D0-E1-F0-cod-1 D0   E1 F0 cod      D0      NA
#> 3         NA             NA      D1-E0-F0-cod-1 D1   E0 F0 cod      D1      NA
#> 4         NA             NA      D1-E1-F0-cod-1 D1   E1 F0 cod      D1      NA
#> 5         NA             NA    D1-E100-F0-cod-1 D1 E100 F0 cod      D1      NA
#> 6         NA             NA D1-E101-F0-M1-cod-1 D1 E101 F0  M1     cod      NA
#>   Recruit_0_re SPRratio_re SpawnBio_re raw_rec_dev_re rec_dev_re
#> 1           NA          NA          NA             NA         NA
#> 2           NA          NA          NA             NA         NA
#> 3           NA          NA          NA             NA         NA
#> 4           NA          NA          NA             NA         NA
#> 5           NA          NA          NA             NA         NA
#> 6           NA          NA          NA             NA         NA
head(calculate_re(ts_dat, add = FALSE))
#> Warning: number of columns of result is not a multiple of vector length (arg 1)
#>   year iteration          scenario                  ID  D    E  F   c species
#> 1    1         1      D0-E0-F0-cod      D0-E0-F0-cod-1 D0   E0 F0 cod      D0
#> 2    1         1      D0-E1-F0-cod      D0-E1-F0-cod-1 D0   E1 F0 cod      D0
#> 3    1         1      D1-E0-F0-cod      D1-E0-F0-cod-1 D1   E0 F0 cod      D1
#> 4    1         1      D1-E1-F0-cod      D1-E1-F0-cod-1 D1   E1 F0 cod      D1
#> 5    1         1    D1-E100-F0-cod    D1-E100-F0-cod-1 D1 E100 F0 cod      D1
#> 6    1         1 D1-E101-F0-M1-cod D1-E101-F0-M1-cod-1 D1 E101 F0  M1     cod
#>   F._1_re Recruit_0_re SPRratio_re SpawnBio_re raw_rec_dev_re rec_dev_re
#> 1      NA           NA          NA          NA             NA         NA
#> 2      NA           NA          NA          NA             NA         NA
#> 3      NA           NA          NA          NA             NA         NA
#> 4      NA           NA          NA          NA             NA         NA
#> 5      NA           NA          NA          NA             NA         NA
#> 6      NA           NA          NA          NA             NA         NA
head(calculate_re(scalar_dat, add = FALSE))
#> Warning: number of columns of result is not a multiple of vector length (arg 1)
#>   iteration          scenario    max_grad
#> 1         1      D0-E0-F0-cod 7.67430e-05
#> 2         1      D0-E1-F0-cod 2.37825e-05
#> 3         1      D1-E0-F0-cod 1.95268e-05
#> 4         1      D1-E1-F0-cod 1.81203e-06
#> 5         1    D1-E100-F0-cod 1.16221e-03
#> 6         1 D1-E101-F0-M1-cod 5.24402e-04
#>                                                                                 version
#> 1 3.30.15.03-safe;_2020_04_23;_Stock_Synthesis_by_Richard_Methot_(NOAA)_using_ADMB_12.0
#> 2 3.30.15.03-safe;_2020_04_23;_Stock_Synthesis_by_Richard_Methot_(NOAA)_using_ADMB_12.0
#> 3 3.30.15.03-safe;_2020_04_23;_Stock_Synthesis_by_Richard_Methot_(NOAA)_using_ADMB_12.0
#> 4 3.30.15.03-safe;_2020_04_23;_Stock_Synthesis_by_Richard_Methot_(NOAA)_using_ADMB_12.0
#> 5 3.30.15.03-safe;_2020_04_23;_Stock_Synthesis_by_Richard_Methot_(NOAA)_using_ADMB_12.0
#> 6 3.30.15.03-safe;_2020_04_23;_Stock_Synthesis_by_Richard_Methot_(NOAA)_using_ADMB_12.0
#>    RunTime hessian Niterations                  ID  D    E  F   c species
#> 1 2.350000    TRUE         856      D0-E0-F0-cod-1 D0   E0 F0 cod      D0
#> 2 2.383333    TRUE         847      D0-E1-F0-cod-1 D0   E1 F0 cod      D0
#> 3 2.266667    TRUE         888      D1-E0-F0-cod-1 D1   E0 F0 cod      D1
#> 4 2.383333    TRUE         853      D1-E1-F0-cod-1 D1   E1 F0 cod      D1
#> 5 2.783333    TRUE        1038    D1-E100-F0-cod-1 D1 E100 F0 cod      D1
#> 6 3.066667    TRUE        1184 D1-E101-F0-M1-cod-1 D1 E101 F0  M1     cod
#>   CV_old_Fem_GP_1_re CV_young_Fem_GP_1_re    F_Btgt_re     F_MSY_re
#> 1          -0.030213              0.00639 -0.005866500 -0.006625248
#> 2          -0.040172              0.01017  0.045775844  0.045806350
#> 3          -0.031768              0.00671 -0.006018545 -0.006791976
#> 4          -0.040306              0.00997  0.039775667  0.039690061
#> 5          -0.034361              0.06341  0.008429841  0.009582478
#> 6          -0.047358              0.06778  0.053929147  0.055757384
#>       F_SPR_re ForeRecr_101_re L_at_Amax_Fem_GP_1_re L_at_Amin_Fem_GP_1_re
#> 1 -0.006018964              -1           0.011840909             -0.009695
#> 2  0.045501802              -1           0.014810606             -0.009720
#> 3 -0.006175300              -1           0.012151515             -0.009515
#> 4  0.039506289              -1           0.014727273             -0.009560
#> 5  0.008692322              NA          -0.009219697             -0.027900
#> 6  0.054084688              NA          -0.006181818             -0.027680
#>   NatM_p_1_Fem_GP_1_re Recr_Unfished_re Ret_Catch_MSY_re    SPR_MSY_re
#> 1             0.000000      -0.03589391     -0.027885388  4.734914e-04
#> 2             0.067805       0.10930776      0.024925079 -1.264176e-04
#> 3             0.000000      -0.05170054     -0.043722437  4.803869e-04
#> 4             0.060085       0.07695333      0.004872938 -4.597004e-05
#> 5             0.000000       0.08562050      0.082243013 -6.987446e-04
#> 6             0.059420       0.23094318      0.137861511 -1.156146e-03
#>    SR_LN_R0_re SR_sigmaR_re SSB_Btgt_re  SSB_MSY_re  SSB_SPR_re SSB_Unfished_re
#> 1 -0.001957219            0 -0.02189549 -0.02123443 -0.02190055     -0.02189913
#> 2  0.005545455            0 -0.02149149 -0.02167873 -0.02149336     -0.02149513
#> 3 -0.002839572            0 -0.03768815 -0.03702450 -0.03768523     -0.03768688
#> 4  0.003962567            0 -0.03489077 -0.03495818 -0.03489078     -0.03489317
#> 5  0.004395722          399  0.07303189  0.07194742  0.07303111      0.07303302
#> 6  0.011112299          399  0.07775132  0.07593901  0.07774974      0.07774878
#>   Size_DblN_ascend_se_Fishery_1_re Size_DblN_ascend_se_Survey_2_re
#> 1                     0.0074862745                      0.06768269
#> 2                     0.0089411765                      0.06543654
#> 3                     0.0079019608                      0.06758462
#> 4                     0.0091039216                      0.06545577
#> 5                    -0.0015039216                      0.13811154
#> 6                     0.0004705882                      0.13272885
#>   Size_DblN_peak_Fishery_1_re Size_DblN_peak_Survey_2_re SmryBio_Unfished_re
#> 1                0.0074350394                 0.02869617         -0.02197661
#> 2                0.0099094488                 0.03014833         -0.02073907
#> 3                0.0078602362                 0.02885167         -0.03776553
#> 4                0.0099704724                 0.02999761         -0.03424256
#> 5               -0.0005511811                 0.04370335          0.07303654
#> 6                0.0023129921                 0.04472010          0.07855075
#>   TotYield_Btgt_re TotYield_MSY_re TotYield_SPR_re Totbio_Unfished_re
#> 1      -0.02779283    -0.027885388    -0.027961646        -0.02198128
#> 2       0.02490518     0.024925079     0.024955677        -0.02069312
#> 3      -0.04362871    -0.043722437    -0.043801263        -0.03776969
#> 4       0.00487021     0.004872938     0.004889301        -0.03420418
#> 5       0.08208551     0.082243013     0.082375820         0.07304328
#> 6       0.13759112     0.137861511     0.138096670         0.07860665
#>   VonBert_K_Fem_GP_1_re depletion_re first_yr_full_re last_yr_full_re
#> 1             -0.017750  -0.14981259               25           -0.01
#> 2             -0.022075  -0.02821320               25           -0.01
#> 3             -0.018375  -0.28698960               25           -0.01
#> 4             -0.022100  -0.14806637               25           -0.01
#> 5              0.022810  -0.08932675               25           -0.01
#> 6              0.017800   0.01485512               25           -0.01
rm("ts_dat", "scalar_dat")
#> Warning: object 'ts_dat' not found
#> Warning: object 'scalar_dat' not found