# ANDERSON'S IRIS DATASET: iris attach(iris) SL=Sepal.Length SW=Sepal.Width PL=Petal.Length PW=Petal.Width # HISTOGRAM: ? hist() hist(SL,breaks=15,col="blue") # BOX PLOT: ? boxplot() boxplot(PL) boxplot(iris) boxplot(SL~Species) # STEM & LEAF PLOT: ? stem() stem(SL) # SCATTER PLOTS OF RESIDUALS # DEFINING EXAMPLE X,Y Y=SL X=SW # PLOT OF RESIDUALS: e=resid(lm(Y~X)) plot(X,e,col="black") abline(0,0,col="blue") # RESIDUALS VS FITTED VALUES: e=resid(lm(Y~X)) Yh=fitted(lm(Y~X)) plot(Yh,e,col="blue") abline(0,0,col="brown") # PLOT OF SEMI-STUDENTIZED RESIDUALS: K=summary(lm(Y~X),digits=10) sqrtMSE=K$sigma sqrtMSE print(summary(lm(Y~X)),digits=10) ess=e/sqrtMSE plot(X,ess,col="red") abline(0,0,col="blue") #STANDARD DIAGNOSTIC PLOTS FROM A LINEAR MODEL: LM=lm(Y~X) op = par(mfrow = c(2, 2), pty = "s") plot(LM) par(op) # LOWESS LINES: # USING TOLUCA DATA K=read.table("c:/2008LinearModelsData/toluca.txt") attach(K) X=V1 Y=V2 plot(lowess(Y~X),type="l",col="red") points(X,Y,col="blue")