Software Setup and Randomization Tests

`knit`

an `R Markdown`

document?No? See

`Handouts`

\(\rightarrow\)`Setup Instructions`

at http://pol346.com/setup_instructions.htmlTo test that it is working, create a new

`R Markdown`

document in RStudio, and see if can`knit`

If you can’t complete installation, follow-up with instructors

`R`

and `RStudio`

?- No? See
`Handouts`

\(\rightarrow\)`R Hacks`

at http://pol346.com/r_keyboard_shortcuts.html

Teresa Amabile ran an experiment on effects of intrinsic and extrinsic motivation on creativity

Subjects with creative writing experience randomly assigned: 24 to “Intrinsic,” 23 to “Extrinsic”

After questionnaire, subjects asked to write a Haiku about “laughter”

Poems submitted to 12 poets, who rated them on 40-point scale of creativity

Score is average of 12 judges

If treatment had no effect, then observed outcomes are unrelated to whether subject was assigned to treatment or control group

Under assumption of “null hypothesis” or that treatment had no effect, we could shuffle all treatment and control assignments and recalculate difference-in-means

These simulated results allow us to see if our observed result is extreme compared to other plausible treatment and control groups

Each randomization is like a possible parallel universe (under assumption of no effect of treatment)

With Base R

`t.test()`

, calculate whether there is a significant difference-in-meansRandomize treatment assignment and calculate a new difference-in-means. See Chapter 1 supplement at http://pol346.com/chapter1.html

Now, repeat Step 2 ten times. How do these results compare to observed difference-in-means?

Randomize treatment assignment and calculate difference-in-means 1,000 times, plot histogram of differences

With

`infer`

calculate randomization distribution and plot histogram of differences. For more about`infer`

, see https://moderndive.com

```
# load packages
suppressMessages(library(dplyr))
suppressMessages(library(janitor))
library(infer)
# load data
creativity <- Sleuth2::case0101 %>% # chapter 01, case 01
clean_names()
# view data
creativity %>% head(2)
```