Skip to contents

Fits a nonlinear model made up of two distinct line segments connected by a logistic curve.

Usage

two_line_logistic(
  dat,
  xvar,
  yvar,
  imm_int = 1,
  imm_slope = 0.2,
  mat_int = 4,
  mat_slope = 0.3,
  SM50_start = NULL,
  alpha_start = 9,
  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).

imm_int

Starting value for the immature intercept parameter when fitting the NLS model

imm_slope

tarting value for the immature slope parameter when fitting the NLS model

mat_int

Starting value for the mature intercept parameter when fitting the NLS model

mat_slope

Starting value for the mature slope parameter when fitting the NLS model

SM50_start

Starting value for SM50 parameter when fitting the NLS model. If not provided, taken to be the median of the x-variable

alpha_start

Starting value for the logistic slope parameter when fitting the NLS model

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 the NLS model object.

Details

This relies on minpack.lm::nlsLM(), which is often able to converge when stats::nls() function cannot find a solution.

Examples

set.seed(12)
fc <- fake_crustaceans(
  error_scale = 17,
  slope = 9,
  L50 = 75,
  n = 800,
  allo_params = c(0.9, 0.25, 1.05, 0.2),
  x_mean = 85
)
two_line_logistic(fc, "x", "y", verbose = FALSE)
#>     SM50 
#> 77.68165