# Rproject7_5_beeswax.r

# 1.0 Read in data ----
#       See Example 10.2.1 A, data from White, Riethof, and Kushnir (1960)
#
file0.beeswax<-"Rice 3e Datasets/ASCII Comma/Chapter 10/beeswax.txt"
##   MeltingPoint Hydrocarbon
## 1        63.78       14.27
## 2        63.45       14.80
## 3        63.58       12.28
## 4        63.08       17.09
## 5        63.40       15.10
## 6        64.42       12.92
#x.label="MeltingPoint"
x.label="Hydrocarbon"
x=data.beeswax[,x.label]

# 2.0 Plots of the data

#   2.1 Index Plot
plot(x, ylab=x.label, main="Beeswax Data (White et. al. 1960)")

#   2.2 Plot of the ECDF

plot(ecdf(x), verticals=TRUE,
col.points='blue', col.hor='red', col.vert='green',
main=paste("ECDF of Beeswax ", x.label,sep=""))

#   2.3 Histogram

hist(x, main="Histogram (Counts)")

hist(x, main="Histogram (Density)", probability=TRUE)

#   Add plot of Fitted Normal
grid.x<-seq(.95*min(x), 1.05*max(x), .01)
x.mean=mean(x)
x.var=var(x)
grid.x.normdensity=dnorm(grid.x, mean=x.mean, sd=sqrt(x.var))
lines(grid.x, grid.x.normdensity, col='green')

#   2.4 Normal QQ Plot

qqnorm(x)
#
#   Add line with slope=sqrt(x.var) and interecept=x.mean

abline(a=x.mean, b=sqrt(x.var), col='green')

#   3.0 Compute selected quantiles

list.probs=c(.10,.25,.50,.75,.9)
print(data.frame(cbind(prob=list.probs,
quantile=quantile(x,probs=list.probs))))
##     prob quantile
## 10% 0.10   13.676
## 25% 0.25   14.070
## 50% 0.50   14.570
## 75% 0.75   15.115
## 90% 0.90   15.470