---
title: "Kleibaum Ch 17 Q1"
output: html_document
---

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

Let's read in the data:
```{r}
lines <- 
"TREAT    DAYS
    1       8
    1       7
    1       7
    1      10
    1       8
    2       4
    2       6
    2       6
    2       3
    2       5
    2       6
    3       6
    3       4
    3       4
    3       5
    3       4
    3       3
    4       7
    4       4
    4       6
    4       6
    4       3
    4       5
    5       9
    5       3
    5       5
    5       7
    5       7
    5       6"
con <- textConnection(lines)
data <- read.csv(con, sep="")
data$TREAT <- relevel(factor(data$TREAT), ref=5)
```

The data consists of observation on patients who were given five different treatments. For each patient, we have the treatment they were given, and the day it took for the patient to heal.

Here is a boxplot:
```{r}
bwplot(TREAT~DAYS, data=data)
```

Let's fit a linear model:

```{r}
fit <- lm(DAYS~TREAT, data=data)
summary(fit)
```

Here is the output from running ANOVA

```{r}
anova(fit)
```

Some diagnostic plots:

```{r}
plot(fit)
```

Here are the pairwise comparisons:

```{r}
with(data, pairwise.t.test(DAYS, TREAT, p.adj = "none"))
```

```{r}
with(data, pairwise.t.test(DAYS, TREAT, p.adj = "bonf"))
```

```{r}
TukeyHSD(aov(fit), conf.level = 0.95)
```


