piecewise.linear: Creates a piecewise linear model

View source: R/piecewise.linear.R

piecewise.linearR Documentation

Creates a piecewise linear model

Description

Fit a degree 1 spline with 1 knot point where the location of the knot point is unknown.

Usage

piecewise.linear(
  x,
  y,
  middle = 1,
  CI = FALSE,
  bootstrap.samples = 1000,
  sig.level = 0.05
)

Arguments

x

Vector of data for the x-axis.

y

Vector of data for the y-axis

middle

A scalar in [0,1]. This represents the range that the change-point can occur in. 0 means the change-point must occur at the middle of the range of x-values. 1 means that the change-point can occur anywhere along the range of the x-values.

CI

Whether or not a bootstrap confidence interval should be calculated. Defaults to FALSE because the interval takes a non-trivial amount of time to calculate

bootstrap.samples

The number of bootstrap samples to take when calculating the CI.

sig.level

What significance level to use for the confidence intervals.

Details

The bootstrap samples are taken by resampling the raw data points. Sometimes a more appropriate bootstrap sample would be to calculate the residuals and then add a randomly selected residual to each y-value.

Value

A list of 5 elements is returned:

change.point

The estimate of α.

model

The resulting lm object once α is known.

x

The x-values used.

y

The y-values used.

CI

Whether or not the confidence interval was calculated.

intervals

If the CIs where calculated, this is a matrix of the upper and lower intervals.

References

Chiu, G. S., R. Lockhart, and R. Routledge. 2006. Bent-cable regression theory and applications. Journal of the American Statistical Association 101:542-553.

Toms, J. D., and M. L. Lesperance. 2003. Piecewise regression: a tool for identifying ecological thresholds. Ecology 84:2034-2041.

See Also

The package segmented has a much more general implementation of this analysis and users should preferentially use that package.

Examples

data(Arkansas)
x <- Arkansas$year
y <- Arkansas$sqrt.mayflies

model <- piecewise.linear(x,y, CI=FALSE)
plot(model)
print(model)
predict(model, 2001)

SiZer documentation built on July 10, 2022, 1:05 a.m.