SSlinear: Simple linear regression functions

linearR Documentation

Simple linear regression functions

Description

These functions provide the simple linear regression model (linear), the linear regression model with self-starter for the nls function (NLS.linear) and the simple linear regression function with self-starter for the drm function in the drc package (DRC.linear). For the 'nls' function, we also provide function and self starter for the simple linear regression through origin (NLS.linearOrigin). Obviously, fitting linear functions with nonlinear least square regression is sub-optimal, but it might be useful for comparing alternative models.

Usage

  linear.fun(predictor, a, b)
  NLS.linear(predictor, a, b)
  NLS.linearOrigin(predictor, b)
  DRC.linear(fixed = c(NA, NA), names = c("a", "b"))

Arguments

predictor

a numeric vector of values at which to evaluate the model.

a

numeric. The response when the predict is equal to 0.

b

numeric. The slope.

fixed

numeric vector. Specifies which parameters are fixed and at what value they are fixed. NAs for parameter that are not fixed.

names

a vector of character strings giving the names of the parameters. The default is reasonable.

Details

The simple linear regression model is given by the following equation:

f(x) = a + b x

Value

linear.fun, NLS.linear and NLS.linearOrigin return a numeric value, while DRC.linear returns a list containing the nonlinear function, the self starter function and the parameter names.

Author(s)

Andrea Onofri

References

Ratkowsky, DA (1990) Handbook of nonlinear regression models. New York (USA): Marcel Dekker Inc.

Onofri, A. (2020). A collection of self-starters for nonlinear regression in R. See: https://www.statforbiology.com/2020/stat_nls_usefulfunctions/

Examples

# Simple linear regression
X <- seq(5, 50, 5)
Y <- 10 + 0.5*X + rnorm(10, 0, 0.5)

model1 <- nls(Y ~ NLS.linear(X, a, b))
model2 <- nls(Y ~ NLS.linearOrigin(X, b)) # force through origin
summary(model1); summary(model2)

model1 <- drm(Y ~ X, fct = DRC.linear())
model2 <- drm(Y ~ X, fct = DRC.linear(fixed = c(0, NA)))
summary(model1); summary(model2)

OnofriAndreaPG/aomisc documentation built on Sept. 15, 2024, 9:53 p.m.