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

## 1
```{r}
A<-c(88, 82, 87, 79, 85, 90, 84, 88, 83, 89, 80, 81, 81, 85, 83, 87, 82, 80, 79, 78)
B<-c(75, 81, 80, 77, 78, 81, 86, 78, 77, 84, 82, 78, 80, 80, 78, 76, 83, 85, 76, 79)

hist(A)
hist(B)
boxplot(A, B, names=c("Alloy A", "Alloy B"), main="Strength of Alloy A and B")
```

An alternative option for visualization, using package `ggplot2`.
```{r}
d = data.frame('strength' = c(A, B), 'type' = c(rep('A', length(A)), rep('B', length(B))))
# boxplot(strength~type, data=d)
ggplot(d, aes(x=type, y=strength))+geom_boxplot()
ggplot(d, aes(x=strength, fill=type))+geom_histogram(position = "dodge", binwidth = 1)
```

## 2
```{r}
par(mfrow=c(1, 2)) 
qqnorm(A) 
qqline(A) 
qqnorm(B) 
qqline(B) 
par(mfrow=c(1,1))
```

```{r}
ggplot(d, aes(sample=strength, color=type))+geom_qq()+geom_qq_line()
```

## 4
```{r}
tapply(d$strength, d$type, sd)
```

## 5
```{r}
t.test(x=A, y=B, alternative="greater", var.equal=TRUE, conf.level=0.95)
```

```{r, echo=F, hide=T}
t.test(strength~type, data=d, alternative="greater", var.equal=TRUE, conf.level=0.95)
```

## 8
```{r}
t.test(x=A, y=B, var.equal=TRUE, conf.level=0.95)
```

