## Understanding QQ plots

## Try distributions like rchisq, rt, runif, rf to view its heavy, or light, left, or right tail.

``` n <- 30; ry <- rnorm(n); qqnorm(ry);qqline(ry); max(ry) min(ry) ##view and guess what are x(s) and y(s) I <- rep(1,n); qr <- ((ry%*%t(I) > I %*% t(ry))+.5*(ry %*% t(I) == I%*%t(ry)))%*%I *(1/n);##qr are the sample quantiles points(qr,ry,col="blue"); ##to view the fact, try the following points(qr,qr*0,col="green",pch="|"); rx <- qnorm(qr); points(rx,ry,col="red",pch="O"); ##Red O(s) circle black o(s) exactly.```

## Anscombe’s 4 Regressions — A Trivially Updated Demo

```##---------- ## This is a trivially updated version based on the R document "?anscombe". require(stats); require(graphics) anscombe```

```##-- now some "magic" to do the 4 regressions in a loop:##< - ff = y ~ x for(i in 1:4) { ff[2:3] = lapply(paste(c("y","x"), i, sep=""), as.name) assign(paste("lm.",i,sep=""), lmi <- lm(ff, data= anscombe)) }```

``` ## See how close they are (numerically!) sapply(objects(pattern="lm\\.[1-4]\$"), function(n) coef(get(n))) lapply(objects(pattern="lm\\.[1-4]\$"), function(n) coef(summary(get(n)))) ## Now, do what you should have done in the first place: PLOTS op <- par(mfrow=c(4,3),mar=.1+c(4,4,1,1), oma= c(0,0,2,0)) for(i in 1:4) { ff[2:3] <- lapply(paste(c("y","x"), i, sep=""), as.name) plot(ff, data =anscombe, col="red", pch=21, bg = "orange", cex = 1.2, xlim=c(3,19), ylim=c(3,13)) abline(get(paste("lm.",i,sep="")), col="blue") plot(lm(ff, data =anscombe),which=1,col="red", pch=21, bg = "orange", cex = 1.2 ,sub.caption="",caption="" ) plot(lm(ff, data =anscombe),which=2,col="red", pch=21, bg = "orange", cex = 1.2 ,sub.caption="",caption="" ) } mtext("Anscombe's 4 Regression data sets", outer = TRUE, cex=1.5) par(op) ## ```

`## Anscombe, F. J. (1973). Graphs in statistical analysis. American Statistician, 27, 17–21.`