| Title: | Estimate Size at Sexual Maturity |
|---|---|
| Description: | Estimate morphometric and gonadal size at sexual maturity for organisms, usually fish and invertebrates. It includes methods for classification based on relative growth (using principal components analysis, hierarchical clustering, discriminant analysis), logistic regression (Frequentist or Bayes), parameters estimation and some basic plots. Optional ggplot-style graphics are available for selected plot methods. |
| Authors: | Josymar Torrejon-Magallanes [cre, aut], Luis Angeles-Gonzalez [aut] |
| Maintainer: | Josymar Torrejon-Magallanes <[email protected]> |
| License: | GPL-2 |
| Version: | 1.2.0 |
| Built: | 2026-05-29 21:15:54 UTC |
| Source: | https://github.com/ejosymart/sizemat |
Classify the individuals in two groups (0: juveniles, 1: adults) based on relative growth.
classify_mature( data, varNames = c("x", "y"), varSex = "sex", selectSex = NULL, method = "ld" )classify_mature( data, varNames = c("x", "y"), varSex = "sex", selectSex = NULL, method = "ld" )
data |
data.frame with allometric variables and sex category (male, female). If sex category contains NA's, that row will be filtered. |
varNames |
the name of two allometric variables to be used for analysis. |
varSex |
the name of the variable containing sex information. |
selectSex |
sex category to be used for analysis. If |
method |
a character string indicating the discriminant analysis method, linear discriminant analysis |
Classify the individuals in two groups (juveniles = 0 and adult = 1).
A Principal Components Analysis was conducted with two allometric variables (x: independent variable, y: dependent variable) in log base, allowing to distinguish two groups that would represent juveniles and adult. The individuals are assigned to each group using a hierarchical classification procedure (hierarchical cluster with agglomeration method: "Ward.D" and the distance measure: "euclidean"). This method is based on establishing a predetermined number of groups (in this case, two) and assigning individuals to one of the groups according to their loads on the two axes of the PCA (Corgos and Freire, 2006).
Using the results of the classification (PCA + cluster), a discriminant analysis (linear or quadratic) is conducted to obtain a discriminating function that permitted any individuals to be classified as a juvenile or an adult on the basis of the X and Y allometric variables.
A data.frame of class 'classify', with x (independent), y (dependent) and classification of maturity (juveniles = 0, adult = 1) variables.
data(crabdata) classify_data = classify_mature(crabdata, varNames = c("carapace_width", "chela_height"), varSex = "sex_category", selectSex = NULL, method = "ld") classify_datadata(crabdata) classify_data = classify_mature(crabdata, varNames = c("carapace_width", "chela_height"), varSex = "sex_category", selectSex = NULL, method = "ld") classify_data
A database containing allometric measures and other attributes of 223 crabs of the specie .
The variables carapace width and chela height were published in Somerton & Donaldson (1996).
data(crabdata)data(crabdata)
A data frame with different variables:
year
month
carapace_width (mm.)
carapace_length (mm.)
chela_height (mm.)
chela_width (mm.)
sex_category (m: male, f: female).
Somerton, D. A., & Donaldson, W. (1996). Contribution of the biology of the grooved and triangle Tanner crabs, Chionectes tanneri and C. angulatus, in the eastern Bering Sea. Fishery Bulletin, 94(2), 348-357.
Watters, G., & Hobday, A. J. (1998). A new method for estimating the morphometric size at maturity of crabs. Canadian Journal of Fisheries and Aquatic Sciences, 55(3), 704-714.
A data set containing the total length and the stages of sexual maturity of 1733 fishes.
data(matFish)data(matFish)
A data frame with two variables:
total_length the total length in cm.
stage_mat the stages of sexual maturity (gonadal maturation stages, I: immature, II-III-IV: mature)
Estimate size at gonad maturity.
gonad_mature( data, varNames = c("allometric", "stage"), immName = "imm", matName = "mad", method = "fq", niter = 999, seed = 70388 )gonad_mature( data, varNames = c("allometric", "stage"), immName = "imm", matName = "mad", method = "fq", niter = 999, seed = 70388 )
data |
data.frame with allometric variables and stage of sexual maturity (gonad maturation stages). |
varNames |
a character string indicating the name of the allometric and the stage of sexual maturity variables to be used for analysis. |
immName |
a character string indicating the name or names of the immaturity stage. |
matName |
a character string indicating the name or names of the maturity stage. |
method |
a character string indicating the method to be applied, |
niter |
number of iterations (bootstrap resampling). |
seed |
a single value, interpreted as an integer. |
Estimate the size at gonad maturity using a logistic regression with X variable and stages of sexual maturity (two categories: immature and mature).
The function requires a data.frame with the X (allometric variable) and the stage of sexual maturity (gonad maturation stage).
The argument varNames requires a character string indicating the name of one allometric and the stage
of sexual maturity variable to be used for analysis (i.e. varNames = c("total_length", "stage_mat")).
So the argument varNames must contain two character strings only, the first is the allometric variable
and the second is the stage of sexual maturity.
The arguments immName and matName require a character string indicating the name
of the stages of sexual maturity in the data.frame. The argument could contain one character string
or should be a vector (i.e. immName = "I", matName = c("II", "III", "IV")).
The argument method requires a character string indicating which regression will be used for the test.
If method = "fq" the logistic regression is based on GLM (frequentist), if method = "bayes" a sample from
the posterior distribution of a logistic regression model using a random walk Metropolis algorithm is generated (see MCMClogit function).
The argument niter requires a number. For the GLM regression (method = "fq"), a non-parametric bootstrap method consists
in generate B bootstrap samples, by resampling with replacement the original data. Then all statistics for each parameter
can be calculated from each bootstrap sample (median and confidence intervals).
For the method = "bayes", the argument niter is related to the number of Metropolis iterations for the sampler.
An object of class 'gonadMat'.
model the summary statistics of the model.
A_boot the 'n iter' values of parameter A.
B_boot the 'n iter' values of parameter B.
L50 the 'n iter' values of parameter L50 (size at gonad maturity).
out a dataframe with the allometric variable "X", stage of sexual maturity, the fitted values for
logistic regression and confidence intervals (95%). Also the summary statistics of the model is provided.
data(matFish) gonad_mat = gonad_mature(matFish, varNames = c("total_length", "stage_mat"), immName = "I", matName = c("II", "III", "IV"), method = "fq", niter = 50) # 'niter' parameters: gonad_mat$A_boot gonad_mat$B_boot gonad_mat$L50_boot gonad_mat$outdata(matFish) gonad_mat = gonad_mature(matFish, varNames = c("total_length", "stage_mat"), immName = "I", matName = c("II", "III", "IV"), method = "fq", niter = 50) # 'niter' parameters: gonad_mat$A_boot gonad_mat$B_boot gonad_mat$L50_boot gonad_mat$out
Estimate size at morphometric maturity.
morph_mature(data, method = "fq", niter = 999, seed = 70388)morph_mature(data, method = "fq", niter = 999, seed = 70388)
data |
an object of class 'classify' with the allometric variables ("X", "Y") and classification of maturity (juveniles = 0, adults = 1). |
method |
a character string indicating the method to be applied, |
niter |
number of iterations (bootstrap resampling). |
seed |
a single value, interpreted as an integer. |
Estimate the size at morphometric maturity using a logistic regression with X variable and maturity classification (two categories: juveniles and adults).
The function requires an object of class "classify" with the X, Y (allometric variables) and classification of maturity (juveniles = 0, adults = 1).
The argument method requires a character string indicating which regression will be used for the test.
If method = "fq" the logistic regression is based on GLM (frequentist) and if method = "bayes" a sample from the posterior distribution
of a logistic regression model using a random walk Metropolis algorithm is generated (see MCMClogit function).
The argument niter requires a number. For the GLM regression (method = "fq"), a non-parametric bootstrap method consists
in generate B bootstrap samples, by resampling with replacement the original data. Then all statistics for each parameter
can be calculated from each bootstrap sample (median and confidence intervals).
For the method = "bayes", the argument 'niter' is related to the number of Metropolis iterations for the sampler.
An object of class 'morphMat'.
model the summary statistics of the model.
A_boot the 'n iter' values of parameter A.
B_boot the 'n iter' values of parameter B.
L50 the 'n iter' values of parameter L50 (size at morphometric maturity).
out a dataframe with the allometric variables "X" and "Y", classification of maturity, the fitted values for
logistic regression and confidence intervals (95%). Also the summary statistics of the model is provided.
data(crabdata) classify_data = classify_mature(crabdata, varNames = c("carapace_width", "chela_height"), varSex = "sex_category", selectSex = NULL, method = "ld") my_mature = morph_mature(classify_data, method = "fq", niter = 50) # 'niter' parameters: my_mature$A_boot my_mature$B_boot my_mature$L50_boot my_mature$outdata(crabdata) classify_data = classify_mature(crabdata, varNames = c("carapace_width", "chela_height"), varSex = "sex_category", selectSex = NULL, method = "ld") my_mature = morph_mature(classify_data, method = "fq", niter = 50) # 'niter' parameters: my_mature$A_boot my_mature$B_boot my_mature$L50_boot my_mature$out
Estimate Nagelkerke's R squared from the result of glm(). Evaluate the goodness of fit for logistic regression.
nagelkerkeR2(x)nagelkerkeR2(x)
x |
An object of class 'glm'. |
Rsquare Nagelkerke's R squared.
set.seed(7388) n <- 300 x <- rnorm(n) a <- 1 b <- -2 p <- 1/(1+exp(a+b*x)) y <- factor(ifelse(runif(n) < p, 1, 0), levels = 0:1) mod1 <- glm(y ~ x, family=binomial) nagelkerkeR2(mod1)set.seed(7388) n <- 300 x <- rnorm(n) a <- 1 b <- -2 p <- 1/(1+exp(a+b*x)) y <- factor(ifelse(runif(n) < p, 1, 0), levels = 0:1) mod1 <- glm(y ~ x, family=binomial) nagelkerkeR2(mod1)
Plot method for classify class
## S3 method for class 'classify' plot( x, xlab = "X", ylab = "Y", col = c(1, 2), pch = c(4, 5), cex = c(1, 1), lty_lines = c(1, 1), lwd_lines = c(1, 1), legendPlot = TRUE, cex_label = 0.8, gg_style = FALSE, point_alpha = 0.8, base_size = 13, ... )## S3 method for class 'classify' plot( x, xlab = "X", ylab = "Y", col = c(1, 2), pch = c(4, 5), cex = c(1, 1), lty_lines = c(1, 1), lwd_lines = c(1, 1), legendPlot = TRUE, cex_label = 0.8, gg_style = FALSE, point_alpha = 0.8, base_size = 13, ... )
x |
an object of class 'classify' with the allometric variables ("X", "Y") and classification of maturity (juveniles = 0, adults = 1). |
xlab |
title for the x axis. |
ylab |
title for the y axis. |
col |
colors for juveniles and adults group. |
pch |
plotting characters for juveniles and adults. |
cex |
character expansion for points. |
lty_lines |
line types for the regression lines. |
lwd_lines |
line widths for the regression lines. |
legendPlot |
legend in the plot (FALSE or TRUE). |
cex_label |
size of the legend text in base graphics. |
gg_style |
logical. If TRUE, return a ggplot2 object. |
point_alpha |
transparency level of points, used only when gg_style = TRUE. |
base_size |
base font size, used only when gg_style = TRUE. |
... |
additional arguments passed to the base plot method. |
data(crabdata) classify_data = classify_mature(crabdata, varNames = c("carapace_width", "chela_height"), varSex = "sex_category", selectSex = NULL, method = "ld") ## Showing different plots plot(classify_data, xlab = "X") plot(classify_data, xlab = "X", ylab = "Y", col = c(1, 2), pch = c(4, 5), cex = c(1, 3)) plot(classify_data, xlab = "Carapace width (mm.)", ylab = "Y", col = c(1, 2), pch = c(4, 5), cex = c(1, 3), lwd_lines = c(1, 3)) plot(classify_data, xlab = "Carapace width (mm.)", ylab = "Y", col = c(1, 2), pch = c(4, 5), cex = c(1, 3), lwd_lines = c(1, 3), main = "Classification")data(crabdata) classify_data = classify_mature(crabdata, varNames = c("carapace_width", "chela_height"), varSex = "sex_category", selectSex = NULL, method = "ld") ## Showing different plots plot(classify_data, xlab = "X") plot(classify_data, xlab = "X", ylab = "Y", col = c(1, 2), pch = c(4, 5), cex = c(1, 3)) plot(classify_data, xlab = "Carapace width (mm.)", ylab = "Y", col = c(1, 2), pch = c(4, 5), cex = c(1, 3), lwd_lines = c(1, 3)) plot(classify_data, xlab = "Carapace width (mm.)", ylab = "Y", col = c(1, 2), pch = c(4, 5), cex = c(1, 3), lwd_lines = c(1, 3), main = "Classification")
Plot method for gonadMat class (size at gonadal maturity)
## S3 method for class 'gonadMat' plot( x, xlab = "X", ylab = "Proportion mature", col = c("blue", "red"), lwd = 2, lty = 2, vline_hist = "black", lwd_hist = 2, lty_hist = 2, onlyOgive = FALSE, showLegend = TRUE, legendPosition = "topleft", gg_style = FALSE, pch = 19, cex = 2.5, point_alpha = 0.8, base_size = 13, label_size = 5, ... )## S3 method for class 'gonadMat' plot( x, xlab = "X", ylab = "Proportion mature", col = c("blue", "red"), lwd = 2, lty = 2, vline_hist = "black", lwd_hist = 2, lty_hist = 2, onlyOgive = FALSE, showLegend = TRUE, legendPosition = "topleft", gg_style = FALSE, pch = 19, cex = 2.5, point_alpha = 0.8, base_size = 13, label_size = 5, ... )
x |
object of class 'gonadMat' with mature parameters and fitted values from the logistic regression. |
xlab |
title for the x axis. |
ylab |
title for the y axis. |
col |
colors for the logistic curve and the L50 reference lines. |
lwd |
line width for fitted values and confidence intervals. |
lty |
line type for fitted values and confidence intervals. |
vline_hist |
color of the vertical lines in the histograms. |
lwd_hist |
line width for vertical lines in the histograms. |
lty_hist |
line type for vertical lines in the histograms. |
onlyOgive |
logical. If TRUE, plot only the maturity ogive. |
showLegend |
logical. If TRUE, show L50 and R2 labels. |
legendPosition |
position of the legend in base graphics and ggplot2 style. Options are "topleft", "topright", "bottomleft", and "bottomright". |
gg_style |
logical. If TRUE, return ggplot2-style plots. |
pch |
plotting character for observed maturity proportions. |
cex |
point size in base graphics and ggplot2 style. |
point_alpha |
transparency level for points, used only when gg_style = TRUE. |
base_size |
base font size, used only when gg_style = TRUE. |
label_size |
size of L50 and R2 labels, used only when gg_style = TRUE. |
... |
additional arguments passed to base graphics. |
data(matFish) gonad_mat = gonad_mature(matFish, varNames = c("total_length", "stage_mat"), immName = "I", matName = c("II", "III", "IV"), method = "fq", niter = 50) plot(gonad_mat, xlab = "Total length (cm.)", ylab = "Proportion mature", col = c("blue", "red"))data(matFish) gonad_mat = gonad_mature(matFish, varNames = c("total_length", "stage_mat"), immName = "I", matName = c("II", "III", "IV"), method = "fq", niter = 50) plot(gonad_mat, xlab = "Total length (cm.)", ylab = "Proportion mature", col = c("blue", "red"))
Plot method for morphMat class (size at morphometric maturity)
## S3 method for class 'morphMat' plot( x, xlab = "X", ylab = "Proportion mature", col = c("blue", "red"), lwd = 2, lty = 2, vline_hist = "black", lwd_hist = 2, lty_hist = 2, onlyOgive = FALSE, gg_style = FALSE, point_alpha = 0.8, base_size = 13, label_size = 5, ... )## S3 method for class 'morphMat' plot( x, xlab = "X", ylab = "Proportion mature", col = c("blue", "red"), lwd = 2, lty = 2, vline_hist = "black", lwd_hist = 2, lty_hist = 2, onlyOgive = FALSE, gg_style = FALSE, point_alpha = 0.8, base_size = 13, label_size = 5, ... )
x |
object of class 'morphMat' with the mature parameters and a data.frame with the allometric variables ("X", "Y") and classification of maturity. Also the fitted values for the logistic regression and confidence intervals (95%). |
xlab |
a title for the x axis. |
ylab |
a title for the y axis. |
col |
color for the logistic curve and for the L50% size at morphometric maturity. |
lwd |
line width for drawing fitted values and confidence intervals. |
lty |
line type for drawing fitted values and confidence intervals. |
vline_hist |
color of the vertical lines in the histogram. The lines represent the median and the confidence intervals. |
lwd_hist |
line width for the vertical line in the histogram. |
lty_hist |
line type for the vertical line in the histogram. |
onlyOgive |
plot only the ogive. |
gg_style |
ggplot style (FALSE or TRUE). |
point_alpha |
transparency level of points, used only when gg_style = TRUE. |
base_size |
base font size, used only when gg_style = TRUE. |
label_size |
size of L50 and R2 labels, used only when gg_style = TRUE. |
... |
Additional arguments to the plot method. |
data(crabdata) classify_data = classify_mature(crabdata, varNames = c("carapace_width", "chela_height"), varSex = "sex_category", selectSex = NULL, method = "ld") my_mature = morph_mature(classify_data, method = "fq", niter = 50) plot(my_mature, xlab = "Carapace width (mm.)", ylab = "Proportion mature", col = c("blue", "red"))data(crabdata) classify_data = classify_mature(crabdata, varNames = c("carapace_width", "chela_height"), varSex = "sex_category", selectSex = NULL, method = "ld") my_mature = morph_mature(classify_data, method = "fq", niter = 50) plot(my_mature, xlab = "Carapace width (mm.)", ylab = "Proportion mature", col = c("blue", "red"))
Print method for classify class
## S3 method for class 'classify' print(x, ...)## S3 method for class 'classify' print(x, ...)
x |
an object of class 'classify' with the allometric variables ("X", "Y") and classification of maturity (juveniles = 0, adults = 1). |
... |
Additional arguments to the print method. |
The number of juveniles and adults. Also shows the regression analysis for juveniles and adults and an ANCOVA analysis to compare slopes.
data(crabdata) classify_data = classify_mature(crabdata, varNames = c("carapace_width", "chela_height"), varSex = "sex_category", selectSex = NULL, method = "ld") print(classify_data)data(crabdata) classify_data = classify_mature(crabdata, varNames = c("carapace_width", "chela_height"), varSex = "sex_category", selectSex = NULL, method = "ld") print(classify_data)
Print method for gonadMat class (size at gonad maturity)
## S3 method for class 'gonadMat' print(x, ...)## S3 method for class 'gonadMat' print(x, ...)
x |
object of class 'gonadMat' with the parameters of the logistic regression and a data.frame with the X and stage of sexual maturity. variables. Also the fitted values for the logistic regression and confidence intervals (95%). |
... |
Additional arguments to the print method. |
The median of the size at gonad maturity estimation, parameters and the Nagelkerke's R squared.
data(matFish) gonad_mat = gonad_mature(matFish, varNames = c("total_length", "stage_mat"), immName = "I", matName = c("II", "III", "IV"), method = "fq", niter = 50) print(gonad_mat)data(matFish) gonad_mat = gonad_mature(matFish, varNames = c("total_length", "stage_mat"), immName = "I", matName = c("II", "III", "IV"), method = "fq", niter = 50) print(gonad_mat)
Print method for morphMat class (size at morphometric maturity)
## S3 method for class 'morphMat' print(x, ...)## S3 method for class 'morphMat' print(x, ...)
x |
object of class 'morphMat' with the parameters of the logistic regression and a data.frame with the allometric variables ("X", "Y") and classification of maturity. Also the fitted values for the logistic regression and confidence intervals (95%). |
... |
Additional arguments to the print method. |
The median of the size at morphometric maturity estimation, parameters and the Nagelkerke's R square.
data(crabdata) classify_data = classify_mature(crabdata, varNames = c("carapace_width", "chela_height"), varSex = "sex_category", selectSex = NULL, method = "ld") my_mature = morph_mature(classify_data, method = "fq", niter = 50) print(my_mature)data(crabdata) classify_data = classify_mature(crabdata, varNames = c("carapace_width", "chela_height"), varSex = "sex_category", selectSex = NULL, method = "ld") my_mature = morph_mature(classify_data, method = "fq", niter = 50) print(my_mature)