Skip to content

Commit 41edf8d

Browse files
authored
Merge pull request #62 from fishR-Core-Team/dev
Dev to Master for v0.2.7
2 parents 26de836 + 2f89963 commit 41edf8d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+2184
-541
lines changed

DESCRIPTION

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
Package: RFishBC
2-
Version: 0.2.6
3-
Date: 2023-8-28
2+
Version: 0.2.7
3+
Date: 2023-12-18
44
Title: Back-Calculation of Fish Length
5-
Authors@R: person("Derek","Ogle",
6-
email="derek@derekogle.com",
5+
Authors@R: person(c("Derek","H."),"Ogle",
6+
email="DerekOgle51@gmail.com",
77
role=c("aut","cre"),
88
comment=c(ORCID="0000-0002-0370-9299"))
99
Description: Helps fisheries scientists collect measurements from calcified

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ export(findScalingFactor)
1313
export(gConvert)
1414
export(getID)
1515
export(listFiles)
16+
export(saveDigitizedImage)
1617
export(showDigitizedImage)

NEWS.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
# RFishBC 0.2.5.9000
1+
# RFishBC 0.2.7
2+
* Updated my (DHO) e-mail address in description and all `@author` tags in the documentation files.
3+
* Removed use of `captioner` package in vignettes as it is no longer available on CRAN (address [#54](https://github.com/fishR-Core-Team/RFishBC/issues/54)).
4+
* Removed `itemize()` in `@return` section of `digitizeRadii()` documentation (addresses note in R-devel CRAN check).
5+
* Replaced `itemize()` with `describe()` in `@details` section of `RFBCoptions()` documentation (addresses note in R-devel CRAN check).
6+
* `backCalc()`: replaced use of `gather()` and `spread()` with `pivot_longer()` and `pivot_wider()` as `gather()` and `spread()` are no longer actively developed.
7+
* `backCalc()`: added ability to retain fish for which no radial measurements were made (addresses [#49](https://github.com/fishR-Core-Team/RFishBC/issues/49)).
8+
* `backCalc()`: added a warning if the r-squared value for the length-structure relationship used in the back-calculation technique is below 0.80 (only for those functions that use a linear model). This attempts to address [#47](https://github.com/fishR-Core-Team/RFishBC/issues/47).
9+
* `backCalc()`: Added simple examples to documentation.
10+
* `saveDigitizedImage()`: Added (address [#44](https://github.com/fishR-Core-Team/RFishBC/issues/44)).
11+
* `showDigitizedImage()`: Added `Encoding()` to unicode "arrows" for plotting to address an issue in the upcoming R v4.4.0 (will address [#59](https://github.com/fishR-Core-Team/RFishBC/issues/59)).
12+
13+
# RFishBC 0.2.6
214
* Updated `test-coverage.yaml` to [latest version](https://github.com/r-lib/actions/blob/v2/examples/test-coverage.yaml).
315
* Updated `pkgdown.yaml` to [latest version](https://github.com/r-lib/actions/blob/v2/examples/pkgdown.yaml).
416
* `listFiles()`: Corrected URL errors in documentation.

R/RFBCoptions.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#' @return None, but the list in \code{RFBCoptions} will be modified.
1111
#'
1212
#' @details The arguments that can be set with this function are:
13-
#' \itemize{
13+
#' \describe{
1414
#' \item{\code{reading}: }{A single character string (or an object that can be coerced to a character) that identifies the reading for a structure. If the structure will be read multiple times, then this may be used to specify the particular reading. Defaults to \code{NULL}. Used in \code{\link{digitizeRadii}}.}
1515
#' \item{\code{description}: }{A single character string that contains a short (but more detailed than in \code{reading}) description for a reading of a structure. Defaults to \code{NULL}. Used in \code{\link{digitizeRadii}}.}
1616
#' \item{\code{suffix}: }{A single character string that will be added to the RData file name. If \code{NULL} and \code{reading} is not \code{NULL}, then this will be replaced with the value in \code{reading}. Defaults to \code{NULL}. Used in \code{\link{digitizeRadii}}.}
@@ -60,7 +60,7 @@
6060
#'
6161
#' @seealso \code{\link{digitizeRadii}} and \code{\link{showDigitizedImage}}
6262
#'
63-
#' @author Derek H. Ogle, \email{derek@@derekogle.com}
63+
#' @author Derek H. Ogle, \email{DerekOgle51@gmail.com}
6464
#'
6565
#' @export
6666
#'

R/aStandard.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#' @param species A string that contains the species name for which to find teh standard intercept value.
66
#' @return A single value from \code{\link{StdIntLit}} that is the standard intercept value (a; mm) for the species provided in \code{species}.
77
#'
8-
#' @author Derek H. Ogle, \email{derek@@derekogle.com}
8+
#' @author Derek H. Ogle, \email{DerekOgle51@gmail.com}
99
#'
1010
#' @seealso \code{\link{StdIntLit}}
1111
#'

R/addFindNotes.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#'
1010
#' @details A detailed description of its use is in the "Other Features" vignette on the \href{https://fishr-core-team.github.io/RFishBC/index.html}{RFishBC website}.
1111
#'
12-
#' @author Derek H. Ogle, \email{derek@@derekogle.com}
12+
#' @author Derek H. Ogle, \email{DerekOgle51@gmail.com}
1313
#'
1414
#' @export
1515
#'
@@ -42,7 +42,7 @@ addNote <- function(nms,note) {
4242
#'
4343
#' @details A detailed description of its use is in the "Other Features" vignette on the \href{https://fishr-core-team.github.io/RFishBC/index.html}{RFishBC website}.
4444
#'
45-
#' @author Derek H. Ogle, \email{derek@@derekogle.com}
45+
#' @author Derek H. Ogle, \email{DerekOgle51@gmail.com}
4646
#'
4747
#' @export
4848
#'

R/backCalc.R

Lines changed: 91 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#' @param 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 \code{\link{bcFuns}} for the list of available models.
88
#' @param a The fish length when the structure first forms as used in the Fraser-Lee model (i.e., \code{BCM=1} or \code{BCM="FRALE"}). If this is missing then \code{a} will be estimated as the intercept from the fish length on structure radius linear regression.
99
#' @param L0p The length at the \dQuote{Biological Intercept} point. Only used in the \dQuote{Biological Intercept} (\code{BCM=3}), \dQuote{Watanabe and Kuroki} (\code{BCM=12}), and \dQuote{Modified Fry} (\code{BCM=14}) models.
10-
#' @param R0p The stucture radius at the \dQuote{Biological Intercept} point. Only used in the \dQuote{Biological Intercept} (\code{BCM=3}), \dQuote{Watanabe and Kuroki} (\code{BCM=12}), and \dQuote{Modified Fry} (\code{BCM=14}) models.
10+
#' @param R0p The structure radius at the \dQuote{Biological Intercept} point. Only used in the \dQuote{Biological Intercept} (\code{BCM=3}), \dQuote{Watanabe and Kuroki} (\code{BCM=12}), and \dQuote{Modified Fry} (\code{BCM=14}) models.
1111
#' @param L0 The length at the arbitrarily selected point in the \dQuote{Fry} (\code{BCM=13}) model.
1212
#' @param R0 The structure radius at the arbitrarily selected point in the \dQuote{Fry} (\code{BCM=13}) model.
1313
#' @param inFormat The format of the data in \code{dat}. The two choices are \code{"long"} with one radial measurement per line (and all radial measurements for a fish in separate rows) and \code{"wide"} with one fish per line (and all radial measurements in separate variables). Defaults to \code{"long"}.
@@ -17,8 +17,61 @@
1717
#'
1818
#' @return A data.frame similar to \code{dat} but with the radial measurements replaced by back-calculated lengths at previous ages.
1919
#'
20+
#' @author Derek H. Ogle, \email{[email protected]}
21+
#'
22+
#' @keywords manip
23+
#'
2024
#' @examples
21-
#' ## None yet.
25+
#' ## Get some data
26+
#' data(SMBassWB1,package="RFishBC") ## fish data
27+
#' data(SMBassWB2,package="RFishBC") ## rad data
28+
#'
29+
#' # Simplify to 3 fish so we can see what is going on
30+
#' tmp1 <- subset(SMBassWB1,id %in% c(377,378,379))
31+
#' tmp2 <- subset(SMBassWB2,id %in% c(377,378,379))
32+
#'
33+
#' # Combine data frames to form a wide data frame (i.e., a left join)
34+
#' wdat1 <- merge(tmp1,tmp2,by="id",all.x=TRUE)
35+
#' wdat1
36+
#'
37+
#' # Make a long data frame for examples (remove annuli with NA rads)
38+
#' ldat1 <- tidyr::pivot_longer(wdat1,rad1:rad9,names_to="ann",names_prefix="rad",
39+
#' values_to="rad")
40+
#' ldat1 <- subset(ldat1,!is.na(rad))
41+
#' ldat1 <- as.data.frame(ldat1)
42+
#' ldat1
43+
#'
44+
#' ## Back-calculate using Dahl-Lea method
45+
#' # wide in and wide out
46+
#' wwres1 <- backCalc(wdat1,lencap,BCM="DALE",inFormat="wide",digits=0)
47+
#' wwres1
48+
#'
49+
#' # wide in and long out
50+
#' wlres1 <- backCalc(wdat1,lencap,BCM="DALE",inFormat="wide",
51+
#' outFormat="long",digits=0)
52+
#' wlres1
53+
#'
54+
#' # long in and wide out
55+
#' lwres1 <- backCalc(ldat1,lencap,BCM="DALE",inFormat="long",digits=0)
56+
#' lwres1
57+
#'
58+
#' # wide in and long out
59+
#' llres1 <- backCalc(ldat1,lencap,BCM="DALE",inFormat="long",
60+
#' outFormat="long",digits=0)
61+
#' llres1
62+
#'
63+
#' ## Situation with no radial measurements for some fish
64+
#' # Create an extra fish with length (tmp1) but no rad
65+
#' tmp1a <- rbind(tmp1,
66+
#' data.frame(id=999,
67+
#' species="SMB",lake="WB",gear="E",
68+
#' yearcap=1990,lencap=225))
69+
#' wdat2 <- merge(tmp1a,tmp2,by="id",all.x=TRUE)
70+
#' wdat2
71+
#'
72+
#' # wide in and wide out
73+
#' wwres2 <- backCalc(wdat2,lencap,BCM="DALE",inFormat="wide",digits=0)
74+
#' wwres2
2275
#'
2376
#' @export
2477
backCalc <- function(dat,lencap,BCM,inFormat,outFormat=inFormat,
@@ -48,20 +101,25 @@ backCalc <- function(dat,lencap,BCM,inFormat,outFormat=inFormat,
48101
## Convert wide to long
49102
nms <- names(dat)
50103
rads <- nms[grepl("rad",nms) & !grepl("radcap",nms)]
51-
dat <- tidyr::gather(dat,key=ann,value=rad,rads[1]:rads[length(rads)])
104+
dat <- tidyr::pivot_longer(dat,rads[1]:rads[length(rads)],
105+
names_to="ann",values_to="rad")
52106
## Change annuli labels into annuli numbers
53107
dat$ann <- as.numeric(stringr::str_replace_all(dat$ann,"rad",""))
54-
## Remove annuli where the radius was missing
55-
dat <- dat[!is.na(dat$rad),]
56-
## Delete plus-growth if asked to do so
57-
if (deletePlusGrowth) dat <- dat[dat$ann<=dat$agecap,]
58-
## Sort by id and then ann number
59-
dat <- dat[order(dat$id,dat$ann),]
60108
}
109+
## Extract fish for which a radius was not measured (save to add back at end)
110+
## assumes no rads measured if first was not measured
111+
norad_dat <- dat[dat$ann==1 & is.na(dat$rad),]
112+
113+
## Remove annuli where the radius was missing
114+
dat <- dat[!is.na(dat$rad),]
115+
## Delete plus-growth if asked to do so
116+
if (deletePlusGrowth) dat <- dat[dat$ann<=dat$agecap,]
117+
## Sort by id and then ann number
118+
dat <- dat[order(dat$id,dat$ann),]
61119

62120
## Perform relevant regressions if needed
63121
### initiate all possible regression variables (except for a)
64-
b <- c <- A <- B <- C <- NULL
122+
b <- c <- A <- B <- C <- rsq <- NULL
65123
### Get data (one lencap and one radcap per id) for regressions
66124
regdat <- dat[dat$ann==1,]
67125
regLcap <- regdat[,rlang::quo_name(rlang::enquo(lencap)),drop=TRUE]
@@ -72,23 +130,28 @@ backCalc <- function(dat,lencap,BCM,inFormat,outFormat=inFormat,
72130
regLR <- stats::lm(regLcap~regRcap)
73131
if (is.null(a) | BCM!=2) a <- stats::coef(regLR)[[1]]
74132
b <- stats::coef(regLR)[[2]]
133+
rsq <- FSA::rSquared(regLR)
75134
} else if (BCM==6) { # SLR of R on L (extract A, B)
76135
regRL <- stats::lm(regRcap~regLcap)
77136
A <- stats::coef(regRL)[[1]]
78137
B <- stats::coef(regRL)[[2]]
138+
rsq <- FSA::rSquared(regRL)
79139
} else if (BCM==7) { # MLR of R on L and A (extract A, B, C)
80140
regRLA <- stats::lm(regRcap~regLcap+regAcap)
81141
A <- stats::coef(regRLA)[[1]]
82142
B <- stats::coef(regRLA)[[2]]
83143
C <- stats::coef(regRLA)[[3]]
144+
rsq <- FSA::rSquared(regRLA)
84145
} else if (BCM==8) { # MLR of L on R and A (extract a, b, c)
85146
regLRA <- stats::lm(regLcap~regRcap+regAcap)
86147
a <- stats::coef(regLRA)[[1]]
87148
b <- stats::coef(regLRA)[[2]]
88149
c <- stats::coef(regLRA)[[3]]
150+
rsq <- FSA::rSquared(regLRA)
89151
} else if (BCM==9) { # SLR of log(L) on log(R) (extract c)
90152
regLR2 <- stats::lm(log(regLcap)~log(regRcap))
91153
c <- stats::coef(regLR2)[[2]]
154+
rsq <- FSA::rSquared(regLR2)
92155
} else if (BCM==10) { # NLS of L on R (extract c)
93156
tmp <- stats::lm(log(regLcap)~log(regRcap))
94157
sv <- stats::coef(tmp)
@@ -122,11 +185,13 @@ backCalc <- function(dat,lencap,BCM,inFormat,outFormat=inFormat,
122185
a <- stats::coef(qregLR)[[1]]
123186
b <- stats::coef(qregLR)[[2]]
124187
c <- stats::coef(qregLR)[[3]]
188+
rsq <- FSA::rSquared(qregLR)
125189
} else if (BCM==18) { # QR of R on L (extract A,B,C)
126190
qregRL <- stats::lm(regRcap~regLcap+I(regLcap^2))
127191
A <- stats::coef(qregRL)[[1]]
128192
B <- stats::coef(qregRL)[[2]]
129193
C <- stats::coef(qregRL)[[3]]
194+
rsq <- FSA::rSquared(qregRL)
130195
} else if (BCM==21) { # NLS L on R (extract a, bb)
131196
tmp <- stats::lm(log(regLcap)~regRcap)
132197
sv <- stats::coef(tmp)
@@ -144,6 +209,15 @@ backCalc <- function(dat,lencap,BCM,inFormat,outFormat=inFormat,
144209
B <- stats::coef(nlsRL)[[2]]
145210
}
146211

212+
# Warn about possible poor back-calculation values
213+
if (!is.null(rsq)) {
214+
if (rsq<0.80)
215+
WARN("R-squared for the length-structure relationship is low (",
216+
formatC(rsq,format="f",digits=3),"). The\n",
217+
"computed model coefficients and resulting back-calculated lengths\n",
218+
"may be suspect! Examine the length-structure plot for your data.\n")
219+
}
220+
147221
## Perform the back-calculation
148222
### Get the back-calculation model function
149223
BCFUN <- bcFuns(BCM)
@@ -158,12 +232,17 @@ backCalc <- function(dat,lencap,BCM,inFormat,outFormat=inFormat,
158232
dat$bclen <- round(dat$bclen,digits=digits)
159233

160234
## Prepare data to return
235+
### Add back fish with no radial measurements if they exist
236+
if (nrow(norad_dat)>0) {
237+
norad_dat$bclen <- NA
238+
dat <- rbind(dat,norad_dat)
239+
}
161240
### Remove radii information
162241
dat <- dat[,!grepl("rad",names(dat))]
163242
### Convert to wide format (if asked to do so)
164243
if (outFormat=="wide") {
165-
dat <- tidyr::spread(dat,key=ann,value=bclen,sep="len")
166-
names(dat) <- gsub("ann","",names(dat))
244+
dat <- tidyr::pivot_wider(dat,names_from="ann",names_prefix="len",
245+
values_from="bclen")
167246
}
168247
## Return the data
169248
dat

R/bcFuns.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#' }
3434
#' @return A function that can be used to predict length at previous age (Li) given length-at-capture (Lcap), hard-part radius-at-age i (Ri), and hard-part radius-at-capture (Rcap). In addition, some functions/models may require the previous age (agei) and the age-at-capture (agec), certain parameters related to the biological intercept (R0p & L0p), or certain parameters estimated from various regression models (a,b,c,A,B,C). See source for more information.
3535
#'
36-
#' @author Derek H. Ogle, \email{derek@@derekogle.com}
36+
#' @author Derek H. Ogle, \email{DerekOgle51@gmail.com}
3737
#'
3838
#' @section IFAR Supplement: \url{https://derekogle.com/IFAR/supplements/backcalculation.html}
3939
#'

R/combineData.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#'
1212
#' @details A detailed description of its use is in \href{https://fishr-core-team.github.io/RFishBC/articles/collectRadiiData.html}{this vignette} on the \href{https://fishr-core-team.github.io/RFishBC/index.html}{RFishBC website}. The list of R data file names may be efficiently created with \code{\link{listFiles}} as described in that vignette. The R data file names may also be selected from a dialog box if using Windows.
1313
#'
14-
#' @author Derek H. Ogle, \email{derek@@derekogle.com}
14+
#' @author Derek H. Ogle, \email{DerekOgle51@gmail.com}
1515
#'
1616
#' @export
1717
#'

0 commit comments

Comments
 (0)