Fits separate linear models for the allometric growth of immature and mature individuals. Code adapted from Dr. Bradley Stevens at the University of Maryland Eastern Shore.
Usage
two_line(
dat,
xvar,
yvar,
lower = NULL,
upper = NULL,
verbose = FALSE,
bps = "even",
log = FALSE,
num_bps = 100
)
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.
- verbose
Should additional output be returned besides the SM50 estimate?
- bps
Should the values tested as possible breakpoints be restricted to only observed values of the x-variable ("obs"), or should it be a specified number of evenly-spaced values between the lower and upper limits of the unknown region ("even", the default)
- log
Boolean; should both variables be log-transformed before performing the regression? Defaults to FALSE.
- num_bps
When
bps = "even"
, how many values should be tested as possible endpoints? Defaults to 100, but should be increased.
Value
If verbose is FALSE (the default), two possible estimates of SM50: the breakpoint x-value marking the transition between immature and mature points/lines, and the intersection point where the two lines cross. The intersection value will typically be extremely unrealistic unless the slopes of the lines are drastically different. If verbose is TRUE, 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 and mature slope and intercept parameters, and the intersection point of the two lines.
Details
The optimal breakpoint between lines is found by minimizing the residual sum of squares when iterating over (1) num_bps evenly-spaced values within the possible range or (2) all values of the x-axis variable present in the unknown range.
See also
two_line_logistic()
for an alternative two-line model with a
logistic transition between the left and right segments and
piecewise_mods()
for segmented/piecewise regression methods.
Examples
#' set.seed(12)
fc <- fake_crustaceans(n = 100, L50 = 100, allo_params = c(1, 0.2, 1.1, 0.2))
two_line(fc, xvar = "x", yvar = "y", verbose = FALSE)
#> breakpoint intersection
#> 104.1017 1561.0893