Back-calculates length at previous ages from a data.frame that was primarily created from combineData and digitizeRadii. One of several back-calculation models, described in bcFuns and Vigliola and Meekan (2009), can be used. Parameter estimates from various models of fish length on structure radius or structure radius on fish length are computed internally and used in the back-calculations. This function is intended to make back-calculation of fish length at previous ages as streamlined as possible.

backCalc(
  dat,
  lencap,
  BCM,
  inFormat,
  outFormat = inFormat,
  a = NULL,
  L0p = NULL,
  R0p = NULL,
  L0 = NULL,
  R0 = NULL,
  deletePlusGrowth = TRUE,
  digits = getOption("digits")
)

Arguments

dat

A data.frame created with combineData that MUST have at least the length-at-capture appended as a variable. See Details.

lencap

The unquoted name of the length-at-capture variable.

BCM

A single numeric between 1 and 22 or a string that indicates which model to use (based on numbers and names in Vigliola and Meekan (2009)). See Details in bcFuns for the list of available models.

inFormat

The format of the data in dat. The two choices are "long" with one radial measurement per line (and all radial measurements for a fish in separate rows) and "wide" with one fish per line (and all radial measurements in separate variables). Defaults to "long".

outFormat

The format for the returned data.frame. Choices are as described for inFormat. Defaults to be the same as inFormat.

a

The fish length when the structure first forms as used in the Fraser-Lee model (i.e., BCM=1 or BCM="FRALE"). If this is missing then a will be estimated as the intercept from the fish length on structure radius linear regression.

L0p

The length at the “Biological Intercept” point. Only used in the “Biological Intercept” (BCM=3), “Watanabe and Kuroki” (BCM=12), and “Modified Fry” (BCM=14) models.

R0p

The structure radius at the “Biological Intercept” point. Only used in the “Biological Intercept” (BCM=3), “Watanabe and Kuroki” (BCM=12), and “Modified Fry” (BCM=14) models.

L0

The length at the arbitrarily selected point in the “Fry” (BCM=13) model.

R0

The structure radius at the arbitrarily selected point in the “Fry” (BCM=13) model.

deletePlusGrowth

A logical that indicates whether the radial measurement that corresponds to “plus-growth” on the structure should be deleted (TRUE; Default) or not (FALSE).

digits

Number of digits to which the back-calculated lengths should be rounded. Defaults to the value returned by getOptions("digits"), which is generally 7 digits.

Value

A data.frame similar to dat but with the radial measurements replaced by back-calculated lengths at previous ages.

Author

Derek H. Ogle, DerekOgle51@gmail.com

Examples

## Get some data
data(SMBassWB1,package="RFishBC") ## fish data
data(SMBassWB2,package="RFishBC") ## rad data

# Simplify to 3 fish so we can see what is going on
tmp1 <- subset(SMBassWB1,id %in% c(377,378,379))
tmp2 <- subset(SMBassWB2,id %in% c(377,378,379))

# Combine data frames to form a wide data frame (i.e., a left join)
wdat1 <- merge(tmp1,tmp2,by="id",all.x=TRUE)
wdat1
#>    id species lake gear yearcap lencap reading agecap  radcap    rad1    rad2
#> 1 377     SMB   WB    E    1990    244     DHO      7 7.32901 1.14855 2.40505
#> 2 378     SMB   WB    E    1990    205     DHO      6 5.68903 1.44620 2.30517
#> 3 379     SMB   WB    E    1990    117     DHO      2 3.05503 1.59628 3.05503
#>      rad3    rad4    rad5    rad6    rad7 rad8 rad9
#> 1 3.43185 4.32332 5.25482 6.36840 7.32901   NA   NA
#> 2 3.24254 4.23761 4.91082 5.68903      NA   NA   NA
#> 3      NA      NA      NA      NA      NA   NA   NA
 
# Make a long data frame for examples (remove annuli with NA rads)
ldat1 <- tidyr::pivot_longer(wdat1,rad1:rad9,names_to="ann",names_prefix="rad",
                             values_to="rad")
ldat1 <- subset(ldat1,!is.na(rad))
ldat1 <- as.data.frame(ldat1)
ldat1
#>     id species lake gear yearcap lencap reading agecap  radcap ann     rad
#> 1  377     SMB   WB    E    1990    244     DHO      7 7.32901   1 1.14855
#> 2  377     SMB   WB    E    1990    244     DHO      7 7.32901   2 2.40505
#> 3  377     SMB   WB    E    1990    244     DHO      7 7.32901   3 3.43185
#> 4  377     SMB   WB    E    1990    244     DHO      7 7.32901   4 4.32332
#> 5  377     SMB   WB    E    1990    244     DHO      7 7.32901   5 5.25482
#> 6  377     SMB   WB    E    1990    244     DHO      7 7.32901   6 6.36840
#> 7  377     SMB   WB    E    1990    244     DHO      7 7.32901   7 7.32901
#> 8  378     SMB   WB    E    1990    205     DHO      6 5.68903   1 1.44620
#> 9  378     SMB   WB    E    1990    205     DHO      6 5.68903   2 2.30517
#> 10 378     SMB   WB    E    1990    205     DHO      6 5.68903   3 3.24254
#> 11 378     SMB   WB    E    1990    205     DHO      6 5.68903   4 4.23761
#> 12 378     SMB   WB    E    1990    205     DHO      6 5.68903   5 4.91082
#> 13 378     SMB   WB    E    1990    205     DHO      6 5.68903   6 5.68903
#> 14 379     SMB   WB    E    1990    117     DHO      2 3.05503   1 1.59628
#> 15 379     SMB   WB    E    1990    117     DHO      2 3.05503   2 3.05503

## Back-calculate using Dahl-Lea method
# wide in and wide out
wwres1 <- backCalc(wdat1,lencap,BCM="DALE",inFormat="wide",digits=0)
#>  Using the Dahl-Lea model.
wwres1
#> # A tibble: 3 × 15
#>      id species lake  gear  yearcap lencap reading agecap  len1  len2  len3
#>   <dbl> <fct>   <fct> <fct>   <int>  <int> <chr>    <int> <dbl> <dbl> <dbl>
#> 1   377 SMB     WB    E        1990    244 DHO          7    38    80   114
#> 2   378 SMB     WB    E        1990    205 DHO          6    52    83   117
#> 3   379 SMB     WB    E        1990    117 DHO          2    61   117    NA
#> # ℹ 4 more variables: len4 <dbl>, len5 <dbl>, len6 <dbl>, len7 <dbl>

# wide in and long out
wlres1 <- backCalc(wdat1,lencap,BCM="DALE",inFormat="wide",
                   outFormat="long",digits=0)
#>  Using the Dahl-Lea model.
wlres1
#> # A tibble: 15 × 10
#>       id species lake  gear  yearcap lencap reading agecap   ann bclen
#>    <dbl> <fct>   <fct> <fct>   <int>  <int> <chr>    <int> <dbl> <dbl>
#>  1   377 SMB     WB    E        1990    244 DHO          7     1    38
#>  2   377 SMB     WB    E        1990    244 DHO          7     2    80
#>  3   377 SMB     WB    E        1990    244 DHO          7     3   114
#>  4   377 SMB     WB    E        1990    244 DHO          7     4   144
#>  5   377 SMB     WB    E        1990    244 DHO          7     5   175
#>  6   377 SMB     WB    E        1990    244 DHO          7     6   212
#>  7   377 SMB     WB    E        1990    244 DHO          7     7   244
#>  8   378 SMB     WB    E        1990    205 DHO          6     1    52
#>  9   378 SMB     WB    E        1990    205 DHO          6     2    83
#> 10   378 SMB     WB    E        1990    205 DHO          6     3   117
#> 11   378 SMB     WB    E        1990    205 DHO          6     4   153
#> 12   378 SMB     WB    E        1990    205 DHO          6     5   177
#> 13   378 SMB     WB    E        1990    205 DHO          6     6   205
#> 14   379 SMB     WB    E        1990    117 DHO          2     1    61
#> 15   379 SMB     WB    E        1990    117 DHO          2     2   117

# long in and wide out
lwres1 <- backCalc(ldat1,lencap,BCM="DALE",inFormat="long",digits=0)
#>  Using the Dahl-Lea model.
lwres1
#>     id species lake gear yearcap lencap reading agecap ann bclen
#> 1  377     SMB   WB    E    1990    244     DHO      7   1    38
#> 2  377     SMB   WB    E    1990    244     DHO      7   2    80
#> 3  377     SMB   WB    E    1990    244     DHO      7   3   114
#> 4  377     SMB   WB    E    1990    244     DHO      7   4   144
#> 5  377     SMB   WB    E    1990    244     DHO      7   5   175
#> 6  377     SMB   WB    E    1990    244     DHO      7   6   212
#> 7  377     SMB   WB    E    1990    244     DHO      7   7   244
#> 8  378     SMB   WB    E    1990    205     DHO      6   1    52
#> 9  378     SMB   WB    E    1990    205     DHO      6   2    83
#> 10 378     SMB   WB    E    1990    205     DHO      6   3   117
#> 11 378     SMB   WB    E    1990    205     DHO      6   4   153
#> 12 378     SMB   WB    E    1990    205     DHO      6   5   177
#> 13 378     SMB   WB    E    1990    205     DHO      6   6   205
#> 14 379     SMB   WB    E    1990    117     DHO      2   1    61
#> 15 379     SMB   WB    E    1990    117     DHO      2   2   117

# wide in and long out
llres1 <- backCalc(ldat1,lencap,BCM="DALE",inFormat="long",
                   outFormat="long",digits=0)
#>  Using the Dahl-Lea model.
llres1
#>     id species lake gear yearcap lencap reading agecap ann bclen
#> 1  377     SMB   WB    E    1990    244     DHO      7   1    38
#> 2  377     SMB   WB    E    1990    244     DHO      7   2    80
#> 3  377     SMB   WB    E    1990    244     DHO      7   3   114
#> 4  377     SMB   WB    E    1990    244     DHO      7   4   144
#> 5  377     SMB   WB    E    1990    244     DHO      7   5   175
#> 6  377     SMB   WB    E    1990    244     DHO      7   6   212
#> 7  377     SMB   WB    E    1990    244     DHO      7   7   244
#> 8  378     SMB   WB    E    1990    205     DHO      6   1    52
#> 9  378     SMB   WB    E    1990    205     DHO      6   2    83
#> 10 378     SMB   WB    E    1990    205     DHO      6   3   117
#> 11 378     SMB   WB    E    1990    205     DHO      6   4   153
#> 12 378     SMB   WB    E    1990    205     DHO      6   5   177
#> 13 378     SMB   WB    E    1990    205     DHO      6   6   205
#> 14 379     SMB   WB    E    1990    117     DHO      2   1    61
#> 15 379     SMB   WB    E    1990    117     DHO      2   2   117

## Situation with no radial measurements for some fish
# Create an extra fish with length (tmp1) but no rad
tmp1a <- rbind(tmp1,
               data.frame(id=999,
               species="SMB",lake="WB",gear="E",
               yearcap=1990,lencap=225))
wdat2 <- merge(tmp1a,tmp2,by="id",all.x=TRUE)
wdat2
#>    id species lake gear yearcap lencap reading agecap  radcap    rad1    rad2
#> 1 377     SMB   WB    E    1990    244     DHO      7 7.32901 1.14855 2.40505
#> 2 378     SMB   WB    E    1990    205     DHO      6 5.68903 1.44620 2.30517
#> 3 379     SMB   WB    E    1990    117     DHO      2 3.05503 1.59628 3.05503
#> 4 999     SMB   WB    E    1990    225    <NA>     NA      NA      NA      NA
#>      rad3    rad4    rad5    rad6    rad7 rad8 rad9
#> 1 3.43185 4.32332 5.25482 6.36840 7.32901   NA   NA
#> 2 3.24254 4.23761 4.91082 5.68903      NA   NA   NA
#> 3      NA      NA      NA      NA      NA   NA   NA
#> 4      NA      NA      NA      NA      NA   NA   NA
                
# wide in and wide out
wwres2 <- backCalc(wdat2,lencap,BCM="DALE",inFormat="wide",digits=0)
#>  Using the Dahl-Lea model.
wwres2
#> # A tibble: 4 × 15
#>      id species lake  gear  yearcap lencap reading agecap  len1  len2  len3
#>   <dbl> <fct>   <fct> <fct>   <dbl>  <dbl> <chr>    <int> <dbl> <dbl> <dbl>
#> 1   377 SMB     WB    E        1990    244 DHO          7    38    80   114
#> 2   378 SMB     WB    E        1990    205 DHO          6    52    83   117
#> 3   379 SMB     WB    E        1990    117 DHO          2    61   117    NA
#> 4   999 SMB     WB    E        1990    225 NA          NA    NA    NA    NA
#> # ℹ 4 more variables: len4 <dbl>, len5 <dbl>, len6 <dbl>, len7 <dbl>