## October 16, Q-Q plots for assesment of marginal normality rm(list = ls()) ################################################################################### ## example from the book y <- c(-1,-0.1,0.16, 0.41, 0.62, 0.80, 1.26, 1.54, 1.71, 2.30) n <- length(y) ## eventhough they are already sorted sort.y <- sort(y) ## determine probabilities based upon sample data prob <- (1:n - 0.5)/n ## determine quatiles based on the standard normal distribution quant.norm <- qnorm(prob, mean=0, sd=1) ## make the Q-Q plot plot(quant.norm, sort.y, pch=16, xlab="Theoretical Quantiles", ylab="Sample Quantiles", main="Normal Q-Q plot") ## let's add a line which passes throuugh the first and third quartile q.25 <- qnorm(0.25, mean=0, sd=1) q.75 <- qnorm(0.75, mean=0, sd=1) y.25 <- quantile(y, prob=0.25) y.75 <- quantile(y, prob=0.75) b <- (y.75-y.25)/(q.75-q.25) a <- y.25 - b*q.25 abline(a,b,lwd=2) ## R has a function that does this in one shot qqnorm(y) qqline(y) ## Radiation data y <- c(0.15,0.09,0.18,0.10,0.05,0.12,0.08,0.05,0.08,0.10,0.07, 0.02,0.01,0.10,0.10,0.10,0.02,0.10,0.01,0.01,0.40,0.10,0.05,0.03, 0.05,0.15,0.10,0.15,0.09,0.08,0.18,0.10,0.20,0.11,0.30,0.02,0.20, 0.20,0.30,0.30,0.40,0.30,0.05) qqnorm(unique(y), pch=16) qqline(unique(y)) ## let's look at some random variation in Q-Q plots ## All data are genereated from a standard normal distribution par(mfrow=c(2,5)) for(i in 1:10){ y <- rnorm(30, mean=0, sd=1) qqnorm(y, pch=16) qqline(y) } ## let's look at some random variation in Q-Q plots ## now n=500 par(mfrow=c(2,5)) for(i in 1:10){ y <- rnorm(500, mean=0, sd=1) qqnorm(y, pch=16) qqline(y) }