View source: R/piecewise.linear.R
piecewise.linear | R Documentation |
Fit a degree 1 spline with 1 knot point where the location of the knot point is unknown.
piecewise.linear( x, y, middle = 1, CI = FALSE, bootstrap.samples = 1000, sig.level = 0.05 )
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. |
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.
A list of 5 elements is returned:
The estimate of α.
The resulting lm
object once α is known.
The x-values used.
The y-values used.
Whether or not the confidence interval was calculated.
If the CIs where calculated, this is a matrix of the upper and lower intervals.
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.
The package segmented
has a much more general implementation
of this analysis and users should preferentially use that package.
data(Arkansas) x <- Arkansas$year y <- Arkansas$sqrt.mayflies model <- piecewise.linear(x,y, CI=FALSE) plot(model) print(model) predict(model, 2001)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.