knitr::opts_chunk$set( collapse = TRUE, comment = "#>", message = FALSE, warning = FALSE )

This vignette will make most sense if you are familiar with one sample and two sample tests. If these are new to you, have a look at `vignette("one-sample-z-test")`

and `vignette("two-sample-z-test")`

.

Suppose we're interested in people's happiness before and after discovering the #rstats Twitter community. We survey them get before and after happiness scores, using a happiness survey that goes from 0 to 100.

The data looks like this

set.seed(27) before <- round(rnorm(10, 50, 20)) after <- round(before + 5 + rnorm(10, 0, 10)) knitr::kable(data.frame(person = 1:10, before, after))

Crucially, since the before measurement and the after measurement are on the *same person*, we can subtract the before measurement from the after measurement and do a one sample test on these differences.

before <- c(88, 73, 35, 21, 28, 56, 50, 73, 93, 55) after <- c(80, 78, 56, 28, 26, 50, 39, 67, 98, 63) diff <- after - before diff

One key question is: when should we use paired instead of two sample tests? Students typically struggle with this, and it's worth spending some time thinking about this. In abstract terms, we should use paired tests when we have *two observations on the same experimental unit* and two sample tests when we have *two observations on different experimental units*.

The difficulty here is that it takes some time to become comfortable with experimental units. I recommend memorizing

Some examples where paired tests are appropriate:

- left/right shoe

Some examples where you should use a two sample test:

Also note that we

two sample tests, and when should we use

why pair - power pair if you can memorize and analogize

**Any scripts or data that you put into this service are public.**

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.