| SSblin | R Documentation | 
Self starter for a bilinear function with parameters a (intercept), b (first slope), xs (break-point), c (second slope)
blin(x, a, b, xs, c)
SSblin(x, a, b, xs, c)
x | 
 input vector  | 
a | 
 the intercept  | 
b | 
 the first-phase slope  | 
xs | 
 break-point of transition between first-phase linear and second-phase linear  | 
c | 
 the second-phase slope  | 
This is a special case with just two parts but a more general approach is to consider a segmented function with several breakpoints and linear segments. Splines would be even more general. Also this model assumes that there is a break-point that needs to be estimated.
a numeric vector of the same length as x containing parameter estimates for equation specified
blin: vector of the same length as x using the bilinear function
package segmented.
require(ggplot2)
set.seed(1234)
x <- 1:30
y <- blin(x, 0, 0.75, 15, 1.75) + rnorm(30, 0, 0.5)
dat <- data.frame(x = x, y = y)
fit <- nls(y ~ SSblin(x, a, b, xs, c), data = dat)
## plot
ggplot(data = dat, aes(x = x, y = y)) + 
  geom_point() + 
  geom_line(aes(y = fitted(fit)))
## Minimal example
## This is probably about the smallest dataset you 
## should use with this function
dat2 <- data.frame(x = 1:5, y = c(1.1, 1.9, 3.1, 2, 0.9))
fit2 <- nls(y ~ SSblin(x, a, b, xs, c), data = dat2)
ggplot(data = dat2, aes(x = x, y = y)) + 
  geom_point() + 
  geom_line(aes(y = fitted(fit2)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.