Skip to contents

Fits a broken-stick model to estimate size at maturity. Code adapted from Dr. Bradley Stevens at the University of Maryland Eastern Shore. Differs from the broken-stick methods implemented in regrans(), chngpt::chngpt(), segmented::segmented(), SiZer::piecewise.linear(), etc. in that only values of the x-axis variable present in the data are tested as possible SM50 values.

Usage

broken_stick_stevens(
  dat,
  xvar,
  yvar,
  lower = NULL,
  upper = NULL,
  log = FALSE,
  verbose = FALSE
)

Arguments

dat

data frame or matrix containing the data

xvar

Name of column (integer or double) of measurements for the x-axis variable (e.g., carapace width).

yvar

Name of column (integer or double) of measurements for the y-axis variable (e.g., claw height).

lower

Integer or double; the lower bound for possible SM50 values. Must be on the same scale of the data. Defaults to the 20th percentile of the x-variable.

upper

Integer or double; the upper bound for possible SM50 values. Must be on the same scale of the data. Defaults to the 80th percentile of the x-variable.

log

Boolean; should both variables be log-transformed before performing the regression? Defaults to FALSE.

verbose

Should additional output be returned besides the SM50 estimate?

Value

If verbose is FALSE (the default), an estimate of SM50. Otherwise, output is a list that also includes the original data with a column representing which line (immature or mature) the point was assigned to, the immature amd mature slope and intercept parameters, and the F and p-values for the final piecewise model.

Examples

set.seed(12)
fc <- fake_crustaceans(n = 100, L50 = 100, allo_params = c(1, 0.2, 1.1, 0.2))
broken_stick_stevens(fc, xvar = "x", yvar = "y", verbose = FALSE)
#> [1] 91.10524