Skip to contents

A wrapper function allowing for multiple methods of piecewise regression to be applied using a standard format for inputs. See vignette("broken-stick") and vignette("two-line") for more information.

Usage

piecewise_mods(
  dat,
  xvar,
  yvar,
  lower = NULL,
  upper = NULL,
  log = FALSE,
  method = c("segmented", "chngpt", "regrans", "stevens", "TL", "all")
)

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 trans 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 trans 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.

method

Method to use for the regression. A single string or vector containing one or more of c("segmented", "chngpt", "regrans", "stevens", "TL"), or "all" to return the results of all methods for comparison.

Value

An estimate of SM50 from the specified method(s).

Details

The two_line_logistic() function is closely related but not included in this wrapper function because you will generally want more control over the initial values of the parameters and the nonlinear least-squares algorithm may not always converge.

This function is primarily intended for easy comparison between the SM50 estimates produced by a variety of different piecewise regression models. For follow-up analyses, we recommend calling the specific function(s) of interest (regrans(), broken_stick_stevens(), two_line(), segmented::segmented(), or chngpt::chngpt()) and exploring how changing the upper and lower bounds for possible SM50 values and the number of breakpoints to be tested may influence the resulting estimates.

Examples

set.seed(12)
fc <- fake_crustaceans(n = 100, L50 = 100, allo_params = c(1, 0.2, 1.1, 0.2))
piecewise_mods(fc, xvar = "x", yvar = "y", method = c("segmented", "chngpt"))
#>    chngpt segmented 
#>  89.44561  88.71463