T12=read.table("D://T1-2.DAT") # read data (textbook Table 1.2) from CD
#T12=read.table("//sttdc1/FacultyReds/zuo/My Documents/My SAS #Files/stt843/dataset/T1-2.DAT")
dim(T12) #check the dimension of T12
############ NOW HISTOGRAM
hist(T12[,1]) #histogram of the 1st variable, too few classes
help(hist) #read the explanation about the function "hist"
hist(T12[,1],nclass.Sturges)
hist(T12[,1],nclass.scott)
hist(T12[,1],nclass.FD,xlab="density",main="Histogram of density",col="lightblue", border="purple")
hist(T12[,1],nclass=10,xlab="density",main="Histogram of density",col='green',border='red')
#try different class number options
################# NOW BOXPLOT
boxplot(T12[,1], col='red', border="green") #see explanations for boxplot from R or textbook
title(main="Boxplot", sub="Density variable in Table 1.2") #adding titles
################ DOT DIAGRAM
plot(T12[,1], rep(1, dim(T12)[1]), xlab="Density", ylab=" ", pch=".", cex=5)
plot(T12[,1], rep(1, dim(T12)[1]), xlab="Density", ylab=" ",pch=16,col='green')
title("Dot diagram of density in Table 1.2")
################# SCATTER PLOT
plot(T12[,1], T12[,2], xlab="density", ylab="machine direction")
plot(T12[,1], T12[,3], xlab="density", ylab="cross direction")
plot(T12[,2], T12[,3], xlab="machine direction",ylab="cross direction",pch="*")
title("scatter plot of machine and cross directions")
################# PAIRWISE SCATTER PLOT
pairs(T12)
pairs(T12, labels=c("densitry","machine direction","cross direction"),
main="Pairwise scatter plot of Table 1.2")
################## 3D scatterplot #load the package scatterplot3d first
scatterplot3d(T12, color=c("red"), pch=18,xlab="density",highlight.3d=TRUE,
ylab="machine direction", zlab="cross direction",col.axis=c("blue"),col.grid=c("gray"))
################ MEAN, VARIANCE, CORRELATION
mean(T12[,1])
T12bar=apply(T12,2,mean) #calculate mean with respect to the 2nd subscript
T12bar
var(T12[,2])
T12var=apply(T12,2,var)
T12var
varT12=var(T12)
varT12
corT12=cor(T12)
corT12