# ---------------------------------------------- # Program: Transformations1.S # Author: Steven M. Boker # Date: Thu Sep 30 10:18:51 EST 2004 # # Examples of transformations # # ---------------------------------------------- # ---------------------------------------------- # Create four example distributions x1 <- rnorm(300, mean=0, sd=1) x2 <- rexp(300) x3 <- (1 / rnorm(300, mean=1, sd=.1)) x4 <- rnorm(300, mean=1, sd=.2)^4 # ---------------------------------------------- # Boxplots for the distributions graphsheet(height=6.4,width=6.4) par(mfrow=c(2,2)) boxplot(x1, xlab="x1") boxplot(x2, xlab="x2") boxplot(x3, xlab="x3") boxplot(x4, xlab="x4") # ---------------------------------------------- # Histograms for the distributions graphsheet(height=6.4,width=6.4) par(mfrow=c(2,2)) hist(x1, xlab="x1") hist(x2, xlab="x2") hist(x3, xlab="x3") hist(x4, xlab="x4") # ---------------------------------------------- # Quantile-Normal plots for the distributions graphsheet(height=6.4,width=6.4) qqmath(~ x1, distribution=qnorm, prepanel = prepanel.qqmathline, panel = function(x, y) { panel.qqmathline(y, distribution = qnorm) panel.qqmath(x, y) }, aspect=1, xlab = "Normal Distribution", ylab="x1") graphsheet(height=6.4,width=6.4) qqmath(~ x2, distribution=qnorm, prepanel = prepanel.qqmathline, panel = function(x, y) { panel.qqmathline(y, distribution = qnorm) panel.qqmath(x, y) }, aspect=1, xlab = "Normal Distribution", ylab="x2") graphsheet(height=6.4,width=6.4) qqmath(~ x3, distribution=qnorm, prepanel = prepanel.qqmathline, panel = function(x, y) { panel.qqmathline(y, distribution = qnorm) panel.qqmath(x, y) }, aspect=1, xlab = "Normal Distribution", ylab="x3") graphsheet(height=6.4,width=6.4) qqmath(~ x4, distribution=qnorm, prepanel = prepanel.qqmathline, panel = function(x, y) { panel.qqmathline(y, distribution = qnorm) panel.qqmath(x, y) }, aspect=1, xlab = "Normal Distribution", ylab="x4") # ---------------------------------------------- # Testing Positive Exponents using Quantile-Normal plots tlen <- length(x4) exponent <- c(rep(1/4, tlen), rep(1/3, tlen), rep(1/2, tlen), rep(1, tlen), rep(2, tlen), rep(3, tlen)) tempx2 <- c(x4^(1/4), x4^(1/3), x4^(1/2), x4^1, x4^2, x4^3) graphsheet(height=6.4,width=8) qqmath(~ tempx2 | as.factor(exponent), prepanel = prepanel.qqmathline, panel = function(x, y) { panel.qqmathline(y, distribution = qnorm) panel.qqmath(x, y) }, aspect=1, layout=c(3,2), xlab = "Unit Normal Quantiles", ylab = "x4") # ---------------------------------------------- # Testing Negative Exponents using Quantile-Normal plots tlen <- length(x4) exponent <- c(rep(-1/3, tlen), rep(-1/2, tlen), rep(-1, tlen), rep(-2, tlen)) tempx2 <- c(x3^(-1/3), x3^(-1/2), x3^-1, x3^-2) graphsheet(height=6.4,width=8) qqmath(~ tempx2 | as.factor(exponent), prepanel = prepanel.qqmathline, panel = function(x, y) { panel.qqmathline(y, distribution = qnorm) panel.qqmath(x, y) }, aspect=1, layout=c(2,2), xlab = "Unit Normal Quantiles", ylab = "x3")