Fits the exponential model (y ~ exp(m * x + b)), estimating parameters m and b using stats::nls(). The log-linear version fits the model log(y) ~ x using stats::lm(), where the y-intercept is b and the slope of the line is m. The log-linear version overestimates the importance of small values but is widely used. NA and zero values are removed observation-wise prior to fitting.

pb210_fit_exponential(x, y, subset = NULL)

pb210_fit_loglinear(x, y, subset = NULL)

pb210_fit_exponential_manual(m, b)

pb210_fit_exponential_zero()

pb210_fit_exponential_constant(value)

# S3 method for exponential_manual
predict(object, newdata, ...)

# S3 method for exponential_manual
coef(object, ...)

# S3 method for lm_loglinear
predict(object, newdata, ...)

# S3 method for lm_loglinear
coef(object, ...)

Arguments

x

An independent variable like depth or cumulative dry mass.

y

A dependent variable that responds exponentially to x.

subset

NULL to do no subsetting, a logical or numeric vector to subset manually, or a function of two variables (x and y) that returns NULL, a logical vector, or a numeric vector that will be used to subset the data. This is particularly useful in conjunction with finite_head() or finite_tail().

m, b, value

Directly specify coefficients for a manual fit.

object

A model fit object.

newdata

A tibble with a column x.

...

Not used.

Value

A model object like that returned by stats::nls(), with a stats::predict() method.

Examples

fake_depth <- 0:10 fake_pb210 <- exp(5 - fake_depth) + rnorm(11, sd = 0.005) fit_exp <- pb210_fit_exponential(fake_depth, fake_pb210) fit_loglinear <- pb210_fit_loglinear(fake_depth, fake_pb210) coefficients(fit_exp)
#> b m #> 5.000006 -1.000037
coefficients(fit_loglinear)
#> b m #> 4.9468010 -0.9794711
tibble::tibble( new_depth = 0:5, fitted_exp = predict(fit_exp, newdata = tibble::tibble(x = new_depth)), fitted_loglin = predict(fit_loglinear, newdata = tibble::tibble(x = new_depth)) )
#> # A tibble: 6 x 3 #> new_depth fitted_exp fitted_loglin #> <int> <dbl> <dbl> #> 1 0 148. 141. #> 2 1 54.6 52.8 #> 3 2 20.1 19.8 #> 4 3 7.39 7.45 #> 5 4 2.72 2.80 #> 6 5 1.00 1.05