-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenintro_stats.Rmd
56 lines (44 loc) · 1.6 KB
/
openintro_stats.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
---
title: "OpenIntro Stats"
author: "Ben Anderson"
date: "30 September 2016"
output:
html_document:
fig_caption: yes
keep_md: yes
number_sections: yes
toc: yes
---
# Open Intro Stats v3
Textbook etc available [online](https://www.openintro.org/stat/textbook.php?stat_book=os).
You will need to make sure the [openintro package](https://github.com/OpenIntroOrg/openintro-r-package) is loaded. To do this:
`>install.packages("devtools") (if you didn't already)`
`>library(devtools)`
`>install_github("OpenIntroOrg/openintro-r-package", subdir = "openintro")`
You will also need to install the OIdata package:
`install_github("OpenIntroOrg/openintro-r-package", subdir = "OIdata")`
Now we've done that, we will load the packages into R.
```{r setup}
knitr::opts_chunk$set(echo = TRUE)
library(openintro)
library(OIdata)
```
All set!
# Example 1: Histograms
An example from Open Stats v3. See if you can predict what the histograms will look like...
```{r histPlot_example_1}
data(run10)
par(mfrow=c(2,2))
histPlot(run10$time)
histPlot(run10$time[run10$gender=='M'], probability=TRUE, xlim=c(30, 180),
ylim=c(0, 0.025), hollow=TRUE)
histPlot(run10$time[run10$gender=='F'], probability=TRUE, add=TRUE,
hollow=TRUE, lty=3, border='red')
legend('topleft', col=c('black', 'red'), lty=2:3, legend=c('M','F'))
histPlot(run10$time, col=fadeColor('yellow', '33'), border='darkblue',
probability=TRUE, breaks=30, lwd=3)
brks <- c(40, 50, 60, 65, 70, 75, 80, seq(82.5, 120, 2.5), 125,
130, 135, 140, 150, 160, 180)
histPlot(run10$time, probability=TRUE, breaks=brks,
col=fadeColor('darkgoldenrod4', '33'))
```