I did piecewise regressions, found the breakpoints and plotted following this example. According to the results, there is only one breakpoint at 107.4733, so 2 lines are expected to be presented: one before and one after this value of x. However, when plotting 3 lines appear, indicating 3 segments. How can I solve this? Where is the error?
library(ggplot2)
library(segmented)
x <- c(0, 60, 90, 120, 180, 240)
y <- c(0.0000000, 0.6900891, 1.9523416, 2.3142669, 1.8167140, 2.6999062)
data <- data.frame(x, y)
my.lm <- lm(y ~ x, data = data)
my.seg <- segmented(my.lm,
seg.Z = ~ x)
my.fitted <- fitted(my.seg)
my.model <- data.frame(x = data$x, y = my.fitted)
ggplot(my.model, aes(x = x, y = y)) + geom_line() +
geom_vline(xintercept = my.seg$psi[2])