n<-100 set.seed(101) x<-runif(n,0,100) y<-2.0+1.5*x plot(x,y) y<-2.0+1.5*x+rnorm(n) plot(x,y) y<-2.0+1.5*x+rnorm(n)*20 plot(x,y,pch=19) y<-2.0+1.5*x+rnorm(n)*20 points(x,y,pch=19,col='red') y<-2.0+1.5*x+rnorm(n)*20 points(x,y,pch=3,col='green') set.seed(476) y1<-2.0+1.5*x+rnorm(n)*20 y2<-2.0+1.5*x+rnorm(n)*20 y3<-2.0+1.5*x+rnorm(n)*20 #################################### par(mfrow=c(2,2),mar=c(2,2,2,2)) plot(x,y1,pch=19) fit1<-lm(y1~x) abline(coef(fit1),col='red') abline(2,1.5,col='blue') plot(x,y2,pch=19) fit2<-lm(y2~x) abline(coef(fit2),col='red') abline(2,1.5,col='blue') plot(x,y3,pch=19) fit3<-lm(y3~x) abline(coef(fit3),col='red') abline(2,1.5,col='blue') #################################### summary(fit1) pdf('myplot.pdf') plot(x,y1,pch=19) fit1<-lm(y1~x) abline(coef(fit1),col='red') dev.off()