# 2x2 plot matrix for one-sample problem;
# histogram with smooth, boxplot, emp. cdf, QQ plot

dist.expl<-function(x)
{
par(mfrow=c(2,2))
iqr<-summary(x)[5]-summary(x)[2]
h<-2.5*iqr*length(x)^(-1/3)
nbin<-ceiling(diff(range(x))/h)
h<-4*1.06*iqr/1.34*length(x)^(-1/5)
den<-density(x,width=h)
y1<-min(den\$y)
y2<-max(den\$y)
x1<-min(den\$x)
x2<-max(den\$x)
hist(x,prob=T,nclass=nbin,main='Histogram with
Smooth',ylim=c(y1,y2),xlim=c(x1,x2))
lines(den,type='l',lwd=3)
boxplot(x,main='Boxplot')
cdf.comp(x,mean=mean(x),sd=sqrt(var(x)))
qqnorm(x)
qqline(x)
title('Q-Q Normal Plot')
par(mfrow=c(1,1))
}
cdf.comp<-function(x, distribution = "normal", ...)
{

#one sample
dist.expanded <- distribution
if((bad.obs <- sum(!(x.ok <- is.finite(x)))) > 0) {
is.not.finite.warning(x)
x <- x[x.ok]
"observations with NA/NaN/Inf in 'x' removed.")
)
}
nx <- length(x)
pdistn <- pnorm
x.sort <- sort(x)
F.x <- c(0, seq(length = nx)/nx, 1)
eps <- min(diff(x.sort))
little <- floor(x.sort[1]) - eps
big <- ceiling(x.sort[nx]) + eps
plot(c(little, x.sort, big), F.x, ylab = "", type = "s", ylim
= c(0, 1), main = paste("Empirical CDF"), xlab =
"x")
eval.pts <- seq(little, big, length = 200)
lines(eval.pts, pdistn(eval.pts, ...), lty = 2)
}