# ------------------------------------------------ # Program: Univariate3.S # Author: Steven M. Boker # Date: Thu Sep 23 12:46:53 EST 2004 # # Provides examples of the use of QQ plots for the # visualization of univariate distributions # # ------------------------------------------------ # ------------------------------------------------ # Quantile plot of sepal length using the "plot" command. graphsheet(height=6.4,width=6.4) tLength <- length(iris$sepal.length) plot(c(1:tLength)/tLength, sort(iris$sepal.length), xlab = "Fraction Value", ylab="Sepal Length (cm)") # ------------------------------------------------ # Quantile plot of sepal length using Trellis graphics graphsheet(height=6.4,width=6.4) qqmath(~ sepal.length, distribution=qunif, data=iris, aspect=1, xlab = "Fraction Value", ylab="Sepal Length (cm)") # ------------------------------------------------ # Quantile plot of sepal length conditioned by variety graphsheet(height=4,width=7.5) qqmath(~ sepal.length | variety, distribution=qunif, data=iris, panel = function(x, y) { panel.grid() panel.xyplot(x, y) }, layout=c(3,1), aspect=1, xlab = "Fraction Value", ylab="Sepal Length (cm)") # ------------------------------------------------ # Quantile-Normal plot of sepal length against normal distribution graphsheet(height=6.4,width=6.4) qqnorm(iris$sepal.length, xlab = "Quantiles from Normal Distribution", ylab = "Quantiles from Sample") # ------------------------------------------------ # Quantile-Quantile plot of sepal.length against normal distribution graphsheet(height=6.4,width=6.4) qqmath(~ sepal.length, distribution=qnorm, data=iris, prepanel = prepanel.qqmathline, panel = function(x, y) { panel.qqmathline(y, distribution = qnorm) panel.qqmath(x, y) }, aspect=1, xlab = "Normal Distribution", ylab="Sepal Length (cm)") # ------------------------------------------------ # Quantile-Quantile plot of sepal.length against normal distribution # by the conditioning variable variety. graphsheet(height=6.4,width=6.4) qqmath(~ sepal.length | variety, distribution=qnorm, data=iris, prepanel = prepanel.qqmathline, panel = function(x, y) { panel.qqmathline(y, distribution = qnorm) panel.qqmath(x, y) }, aspect=1,layout=c(2,2), xlab = "Normal Distribution", ylab="Sepal Length (cm)") # ------------------------------------------------ # Quantile-Quantile plot of sepal.length of Setosa versus Versicolor graphsheet(height=6.4,width=6.4) qq(variety ~ sepal.length, data=iris, subset=variety=="Setosa" | variety=="Versicolor", aspect=1)