Diagnostic plots

Quantile-Quantile plots (Q'Q plots)

(Theoretical) Q'Q Plots

This type of diagnostic tools plots quantiles (fractiles) of an empirical distribution against the corresponding quantiles of a theoretical distribution, frequently the normal distribution (in this case the Q'Q-plots are often called "Normal probability plot").

- qqnorm(area) Normal probability plot
- qqline(area) Adds a line through the 1st and 3rd quartile
- qqmath( ~ area | continent, data=world) {lattice} Theoretical Q'Q plot of area for each continent. This function has an optional argument that lets you specify any statistical distribution available in R, for instance qqmath( ~ area | continent, data=world, distribution = qunif) would use the quantiles from a uniform distribution.
- plot.qq(area,"Q'Q plot") {sma} produces a Q'Q plot together with a histogram (a title is mandatory).
- qq.plot(gnpserv) {car} has more options than qqnorm() and accepts an lm object to produce directly a Q'Q plot for the residuals.

Empirical Q'Q plots

Plots quantiles of two empirical distributions.

- qqplot(gnpagr,gnpserv)
- qq(gnpagr ~ world | continent, data=world) {lattice}

Other diagnostic plots

Symmetry plots

- symplot(gnpserv) {package LearnEDA} produces a symmetry plot

Spread-and-Level plot (package car)

- slp(gnpagr,continent)
- spreadLevelPlot(gnpserv,continent)

There is also a similar spread.level.plot function in package LearnEDA.

Program your own symmetry plots

Example 1

In the programming envrionment provided by R, it is not very difficult to build your own diagnostic graphics. Let us first look at the R code of a symmetry diagnostic proposed by Ross Ihaka,

symplot1= function(x) { n=length(x) n2=n %/% 2 sx = sort(x) mx = median(x) plot(mx-sx[1:n2], rev(sx)[1:n2]-mx, xlab="Distance below median", ylab="Distance above median") abline(a=0,b=1,lty="dotted")}

By the way this code is not very different form the code of the symplot function from the LearnEDA (You can see the code of functions programmed in S, by simply typing the name of the function, without parentheses, and the code is displayed.

Example 2

A second example produces a symmetry plot where you plot on y the sorted variable of interest and the corresponding fractions on x. You will get a nicely linear trend if the observations are regularly spaced over the whole range from the mimimum and the maximum.

n = length(gnpserv) plot((1:n - 1)/(n - 1), sort(gnpserv), type="l", main = "Quantiles of variable gnpserv", xlab = "Fractions", ylab = " Quantiles")

Example 3

Symmetry plot where you plot the sorted x values the following way:
(x_{1},x_{n}:), (x_{2},x_{n-1}:), (x_{3},x_{n-2}:),...

x=infmor plot(sort(x)[1:ceiling(length(x)/2)],sort(x,decreasing = TRUE)[1:ceiling(length(x)/2)])