#R Script for 2008 Linear Models 01 #READ TABLE AND ASSIGN VARIABLES FROM COLUMNS: K=read.table("c:/2008LinearModelsData/Toluca.txt") attach(K) X=V1 Y=V2 #DESCRIPTIVE INFORMATION: K lsfit(X,Y) #CONSTRUCTING LINEAR REGRESSION: lm(Y~X) #COLLECTING INFORMATION FROM THE REGRESSION: Yh=predict(lm(Y~X)) RESIDUALS=resid(lm(Y~X)) #REPORTING WITHIN A DATAFRAME: RESULTS=data.frame(X,Y,Yh,RESIDUALS) RESULTS #PLOTTING DATA, REGRESSION LINE AND RESIDUALS: plot(X,Y) points(X,Yh,col="blue") abline(lm(Y~X),col="blue") segments(X,Yh,X,Y,col="red")