10.12 Piecewise regression

his kind of regression fits different functions over different ranges of the explanatory variable. For example,
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") 




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值