REGRANS broken-stick regression method
Usage
regrans(
dat,
xvar,
yvar,
lower = NULL,
upper = NULL,
log = FALSE,
verbose = FALSE,
n_tries = 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.
- log
Boolean; should both variables be log-transformed before performing the regression? Defaults to FALSE.
- verbose
Return all breakpoints tested and their sum of squares, or only the estimated SM50?
- n_tries
Number of breakpoints to test within the unknown range.
Value
If verbose = TRUE, a data frame with the breakpoints tested and their sum of squares. Otherwise, a single value for the breakpoint with the lowest sum of squares.
Examples
set.seed(12)
fc <- fake_crustaceans(n = 100, L50 = 100, allo_params = c(1, 0.2, 1.1, 0.2))
regrans(fc, "x", "y", verbose = FALSE)
#> [1] 89.43822
head(regrans(fc, "x", "y", verbose = TRUE), n = 30)
#> changept sum_sq
#> 1 89.43822 1917.861
#> 2 89.74331 1919.376
#> 3 90.04840 1921.015
#> 4 90.35348 1922.750
#> 5 90.65857 1924.568
#> 6 90.96366 1926.505
#> 7 91.26874 1928.923
#> 8 91.57383 1931.428
#> 9 91.87892 1933.981
#> 10 92.18401 1936.569
#> 11 92.48909 1939.569
#> 12 92.79418 1943.374
#> 13 93.09927 1947.164
#> 14 93.40436 1950.928
#> 15 93.70944 1954.658
#> 16 94.01453 1958.346
#> 17 94.31962 1962.537
#> 18 94.62470 1966.590
#> 19 94.92979 1969.784
#> 20 95.23488 1973.135
#> 21 95.53997 1977.559
#> 22 95.84505 1982.278
#> 23 96.15014 1986.913
#> 24 96.45523 1991.515
#> 25 96.76032 1996.374
#> 26 97.06540 2001.115
#> 27 97.37049 2005.811
#> 28 97.67558 2011.004
#> 29 97.98066 2016.360
#> 30 98.28575 2021.730