---
title: "ROutput_2018-01-24"
output: html_document
---

One-sample $t$-test

```{r}
# Get data
library(Sleuth3)
poetry.dat = case0101
summary(poetry.dat)

# Do 1-sample t-test
intrinsic = poetry.dat$Score[poetry.dat$Treatment=="Intrinsic"]
intrinsic

t.test(intrinsic,mu=20,alternative="greater")

# Do t-test test-stat by hand
mean(intrinsic)
sd(intrinsic)

(mean(intrinsic) - 20)/(sd(intrinsic)/sqrt(24))

# p-value by hand
1-pt(-0.1287411,23)
```

$z$ confidence intervals
```{r}
# 90% CI
mean(intrinsic) + c(-1,1)*qnorm(.95)*sd(intrinsic)/sqrt(24)

# 95% CI
mean(intrinsic) + c(-1,1)*qnorm(.975)*sd(intrinsic)/sqrt(24)

# 99% CI
mean(intrinsic) + c(-1,1)*qnorm(.995)*sd(intrinsic)/sqrt(24)

# Multiplier for 90% CI
qnorm(.95)

# Multiplier for 95% CI
qnorm(.975)

# Multiplier for 99% CI
qnorm(.995)

# Example #1 in Chapter 2 notes, 90% CI
0.5 + c(-1,1)*qnorm(.95)*.4/sqrt(77)
```