piecewise.linear {SiZer} | R 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 |
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
\alpha
.- model
The resulting
lm
object once\alpha
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)