```{r setup, include=FALSE}
knitr::opts_chunk$set(echo=TRUE, fig.align="center")
```

#### Statistics for Laboratory Scientists ( 140.615 )

## Sample Size and Power Calculations

#### Examples from class using power.t.test

```{r}
power.t.test(n=10,delta=5,sd=10)
power.t.test(delta=5,sd=10,power=0.8)
power.t.test(delta=5,sd=10,power=0.8,alternative="one.sided")
```

#### Some more details

It only matters what the $\Delta / \sigma$ ratio is.

```{r}
power.t.test(n=10,delta=5,sd=10)
power.t.test(n=10,delta=0.5,sd=1)
power.t.test(n=10,delta=0.5)
power.t.test(delta=5,sd=10,power=0.8)
power.t.test(delta=0.5,power=0.8)
```

Extracting the sample size or power.

```{r}
attributes(power.t.test(n=10,delta=0.5))
power.t.test(n=10,delta=0.5)$power
power.t.test(delta=0.5,power=0.8)$n
ceiling(power.t.test(delta=0.5,power=0.8)$n)
```

There is always a (small) chance you reject the null for the wrong reason.

```{r}
power.t.test(n=10,delta=0.5)$power
power.t.test(n=10,delta=0.5,strict=TRUE)$power
power.t.test(n=10,delta=1.5)$power
power.t.test(n=10,delta=1.5,strict=TRUE)$power
```


