---
title: "Chapter 6 output"
output:
  html_document: default
  pdf_document: default
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```



```{r cars}
################################################################
#############chapter 6: descriptive statstics###################
################################################################

###############Earthquake data############################
earthquake<-c(18,14,10,15,8,15,6,11,8,7,12,11,23,16,15,25,22,20,16,23)
earthquake  
mean(earthquake)
sort(earthquake) #sort data from smallest to largest
median(earthquake)
table(earthquake)  #mode is 15, since it appears 3 times
sum(table(earthquake))  #number of observations of vector earthquake
var(earthquake)
sd<-sqrt(var(earthquake))  #standard deviation
sd
fivenum(earthquake)
hist(earthquake,breaks=5)
boxplot(earthquake)
x<-seq(1:20)
plot(x,earthquake)

###############Waiting time data############################
wt<-c(16,45,16,54,15,49,12,54,91,21,33,20,27,53,24,46,39,31,41,27)
sort(wt)
fivenum(wt)
Q1<-fivenum(wt)[2]
Q1
Q3<-fivenum(wt)[4]
Q3
IQR<-Q3-Q1
IQR
Q1-1.5*IQR
Q3+1.5*IQR
Q3+3*IQR


###############Stat 345 test 1 data############################
test1<-c(61,61,82,44,94,75,95,89,90,78,87,55,79,91,74,51,89,36,57,73,49,90,83,66,78,100,61,80,61,94,61,88,92,
         64,97,90,81,40,67,78,50,88,
         64,100)
#test1 <- read.table("~/teaching/stat345/S2019/notes/lecture notes/test12019",header=TRUE)
table(test1)  #mode is 5, since it appears 5 times
sum(table(test1))  #number of observations, 44 students taking the test
xbar<-mean(test1)
xbar
median(test1)
v<-var(test1)  #variance of test 1 score
v
s<-sd(test1)
s

fivenum(test1)


##Graphic summaries

stem(test1) #stem and leaf plot
hist(test1)
boxplot(test1)


##check if the data is roughly normal

qqnorm(test1)
qqline(test1) ##indication of nonnormal

##construct confidence interval using t distribution
##set lower.tail=FALSE to have the same function
##given by the Table V in Appendix A in your textbook.
talpha <- qt(p=0.025, df=44-1, lower.tail=FALSE)
talpha
UB <- xbar + talpha*s/sqrt(44) #upper bound of 95% CI
LB <- xbar - talpha*s/sqrt(44) #lower bound of 95% CI
UB
LB

######problems in ch06 hw##################
Applied7eChap06 <- read.csv("~/teaching/stat345/S2019/datasets/ds_txt/Applied7eChap06.csv", header=TRUE)
Applied7eChap06$Ex6.44
ch06.44<-Applied7eChap06$Ex6.44[1:27]
ch06.44
stem(ch06.44)
# Simple Dotplot
dotchart(ch06.44,
   main="Dot plot of measurements on NbOCl",
   xlab="gram-mole
per liter")
```


