# Demo entry 6738584

R

Submitted by anonymous on May 04, 2018 at 12:30
Language: S. Code size: 1.7 kB.

```#===========================================================
summary(lm(height~weight,women))
op=par(mfrow=c(1,1))
plot(women\$weight,women\$height,xlab = 'height',ylab = 'weight')
points(women\$weight,women\$height,pch=16,col='red')
lines(women\$weight,25.723+women\$weight*0.287,col='blue')
legend('topleft','观测值',pch=16,col='red',bty='n')
legend(113,71,'拟合曲线',lty=1,col = 'blue',bty='n')

#============================================================
pressurex=pressure[-1:-10,]

op=par(mfrow=c(1,2))
plot(pressurex\$temperature,pressurex\$pressure,ylab='pressure',
xlab='temperature',
type='n')
points(pressurex\$temperature,pressurex\$pressure,pch=16,col='red')

for (i in 1:5) {
xx=poly(pressurex\$temperature,i)
yy=coef(lm(pressure~poly(temperature,i),pressurex))
yx=yy[1]+apply(t(xx)*yy[-1],2,sum)
lines(pressurex\$temperature,yx,col=i+1,lty=i+1)
}

legend('topleft',paste('m=',1:5),lty=2:6,col=2:6,bty='n',cex=0.65)

R=NULL
for (i in 1:5) {
xx=poly(pressurex\$temperature,i)
yy=coef(lm(pressure~poly(temperature,i),pressurex))
cc=summary(lm(pressure~poly(temperature,i),pressurex))
R=c(R,cc\$r.squared)
}

plot(R,type = 'n',xlab = 'm')
points(R,pch=16,col='red')
lines(R,col='blue',lty=3)

op=par(mfrow=c(1,2))
summary(lm(pressure~poly(temperature,2),pressurex))
plot(lm(pressure~poly(temperature,2),pressurex))

#================================================================