it might fit different linear regressions to the left- and right-hand halves of a scatterplot. Two important
questions arise in piecewise regression:
how many segments to divide the line into;
where to position the break points on the x axis
data <- read.table("c:\\temp\\sasilwood.txt",header=T)
attach(data)
names(data)
plot(log(Species)~log(Area),pch=21,col="red",bg="yellow")
model1 <- lm(log(Species)~log(Area))
par(mfrow=c(2,2))
plot(model1)
table(Area)
Break <- sort(unique(Area))[3:11]
d <- numeric(9)
for (i in 1:9) {
model <-
lm(log(Species)~(Area<Break[i])*log(Area)+(Area>=Break[i])*log(Area))
d[i] <- summary(model)[[6]] }
windows(7,4)
par(mfrow=c(1,2))
plot(log(Break),d,typ="l",col="red")
Break[which(d==min(d))]
model2 <- lm(log(Species)~log(Area)*(Area<100)+log(Area)*(Area>=100))
anova(model1,model2)
summary(model2)
summary(model2)[[4]]
a1 <- summary(model2)[[4]][1]+summary(model2)[[4]][3]
a2 <- summary(model2)[[4]][1]
b1 <- summary(model2)[[4]][2]+summary(model2)[[4]][4]
b2 <- summary(model2)[[4]][2]
plot(log(Area),log(Species),col="blue")
lines(c(-5,4.6),c(a1+b1*-5,a1+b1*4.6),col="red")
lines(c(4.6,15),c(a2+b2*4.6,a2+b2*15),col="red")