x <- c(5.7,6.1,6,5.9,5.8,5.7,5.6,5.4,5.4,5.5,5.6,5.7,5.9,6.1,6,5.8,5.8,5.7,5.5,5.3,5.2,5.2,5,5.1,5.1,5.2,4.9,4.8,4.5,4.5,4.4,4.4,4.2,4.1,3.9,3.8,3.9,4.2,4.1,3.8,3.6,3.7,3.5,3.4,3.1,3.1,3.1,3.2,3.3,3.5,3.6,3.5,3.3,3.2,3.1,3.2,3,3,3.1,3.4)
#'GNU S' R Code compiled by R2WASP v. 1.0.44 ()
#Author: Prof. Dr. P. Wessa
#To cite this work: AUTHOR(S), (YEAR), YOUR SOFTWARE TITLE (vNUMBER) in Free Statistics Software (v$_version), Office for Research Development and Education, URL http://www.wessa.net/rwasp_YOURPAGE.wasp/
#Source of accompanying publication: Office for Research, Development, and Education
#Technical description: Write here your technical program description (don't use hard returns!)
n <- length(x)
c <- array(NA,dim=c(401))
l <- array(NA,dim=c(401))
mx <- 0
mxli <- -999
for (i in 1:401)
{
l[i] <- (i-201)/100
if (l[i] != 0)
{
x1 <- (x^l[i] - 1) / l[i]
} else {
x1 <- log(x)
}
c[i] <- cor(qnorm(ppoints(x), mean=0, sd=1),x1)
if (mx < c[i])
{
mx <- c[i]
mxli <- l[i]
}
}
c
mx
mxli
if (mxli != 0)
{
x1 <- (x^mxli - 1) / mxli
} else {
x1 <- log(x)
}
postscript(file="/var/www/html/rcomp/tmp/1xj8j1258106295.ps",horizontal=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) 
plot(l,c,main='Box-Cox Normality Plot',xlab='Lambda',ylab='correlation')
mtext(paste('Optimal Lambda =',mxli))
grid()
dev.off()
postscript(file="/var/www/html/rcomp/tmp/2xhkm1258106295.ps",horizontal=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) 
hist(x,main='Histogram of Original Data',xlab='X',ylab='frequency')
grid()
dev.off()
postscript(file="/var/www/html/rcomp/tmp/3eman1258106295.ps",horizontal=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) 
hist(x1,main='Histogram of Transformed Data',xlab='X',ylab='frequency')
grid()
dev.off()
postscript(file="/var/www/html/rcomp/tmp/4daj51258106295.ps",horizontal=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) 
qqnorm(x)
qqline(x)
grid()
mtext('Original Data')
dev.off()
postscript(file="/var/www/html/rcomp/tmp/5d29n1258106295.ps",horizontal=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) 
qqnorm(x1)
qqline(x1)
grid()
mtext('Transformed Data')
dev.off()

#Note: the /var/www/html/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab
load(file="/var/www/html/rcomp/createtable")

a<-table.start()
a<-table.row.start(a)
a<-table.element(a,'Box-Cox Normality Plot',2,TRUE)
a<-table.row.end(a)
a<-table.row.start(a)
a<-table.element(a,'# observations x',header=TRUE)
a<-table.element(a,n)
a<-table.row.end(a)
a<-table.row.start(a)
a<-table.element(a,'maximum correlation',header=TRUE)
a<-table.element(a,mx)
a<-table.row.end(a)
a<-table.row.start(a)
a<-table.element(a,'optimal lambda',header=TRUE)
a<-table.element(a,mxli)
a<-table.row.end(a)
a<-table.end(a)
table.save(a,file="/var/www/html/rcomp/tmp/6fdar1258106295.tab") 

system("convert tmp/1xj8j1258106295.ps tmp/1xj8j1258106295.png")
system("convert tmp/2xhkm1258106295.ps tmp/2xhkm1258106295.png")
system("convert tmp/3eman1258106295.ps tmp/3eman1258106295.png")
system("convert tmp/4daj51258106295.ps tmp/4daj51258106295.png")
system("convert tmp/5d29n1258106295.ps tmp/5d29n1258106295.png")

