fit_length_weight: Fit a length-weight model

View source: R/growth.R

fit_length_weightR Documentation

Fit a length-weight model

Description

For use with data for a single species.

Usage

fit_length_weight(
  dat,
  sex = c("female", "male", "all"),
  downsample = Inf,
  min_samples = 50L,
  method = c("tmb", "rlm", "lm"),
  df = 3,
  too_high_quantile = 1,
  usability_codes = c(0, 1, 2, 6),
  scale_weight = 1/1000
)

Arguments

dat

Input data frame. Should be from gfdata::get_survey_samples() or gfdata::get_commercial_samples().

sex

Either "male" or "female".

downsample

If not Inf this represents a number of fish specimens to sample prior to model fitting. Can be useful for large data sets that you want to fit with MCMC for testing purposes.

min_samples

The minimum number of fish before a model will be fit.

method

"rlm" for MASS::rlm() or "lm" for stats::lm(). "tmb" for a regression fit with TMB that uses Student-t errors with a degrees of freedom defined by the argument df.

df

The fixed degrees of freedom to use if method = "tmb". Large values (say over 100) are effectively the normal distribution. Small values make the distribution more robust to outliers. The model may become unstable if df < 2.

too_high_quantile

A quantile above which to discard weights and lengths. Can be useful for outliers. Defaults to including all data.

usability_codes

An optional vector of usability codes. All usability codes not in this vector will be omitted. Set to NULL to include all samples.

scale_weight

A value to multiply all weights by. Useful for changing units.

Examples

## Not run: 
d <- gfdata::get_survey_samples("pacific ocean perch")
model_f <- fit_length_weight(d, sex = "female")
model_m <- fit_length_weight(d, sex = "male")
plot_length_weight(object_female = model_f, object_male = model_m)

## End(Not run)

seananderson/gfplot documentation built on April 5, 2024, 6:29 a.m.