pb210_fit_exponential: Fit an exponential model

View source: R/models.R

pb210_fit_exponentialR Documentation

Fit an exponential model

Description

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.

Usage

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 class 'exponential_manual'
predict(object, newdata, ...)

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

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

## S3 method for class '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)
coefficients(fit_loglinear)

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))
)


paleolimbot/pb210 documentation built on May 8, 2022, 8:10 a.m.