-
Notifications
You must be signed in to change notification settings - Fork 6
/
07-lesson-07-just-enough-statistics-slides.Rmd
196 lines (123 loc) · 4.39 KB
/
07-lesson-07-just-enough-statistics-slides.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
---
title: "Just Enough Statistics"
author: "Finn Catling & Ahmed Al-Hindawi"
date: "12 March 2018"
output:
slidy_presentation: default
ioslides_presentation: default
---
# Before we start...
```{r, warning=FALSE, message=FALSE}
library(readr)
library(dplyr)
library(ggplot2)
RCT <- read_csv("https://raw.githubusercontent.com/datascibc/Data-Science-for-Docs/master/data/breast-rct-clean-fakeage.csv")
```
# The big picture
Our RCT attempts to answer a research question by collecting data from a *sample* of a *population*.
Data collection consists in measuring the values of several *variables* for each member of the population.
# Descriptive statistics
- Inspect the data
- Organise the data
- Summarise the data
## Inferential statistics
- Draw conclusions about the population from the sample
- Test the reliability of those conclusions
## Variables
- Variables may be *continuous* or *discrete*
- Consider these:
- **age**
- **random**, **satisfaction**
# Distributions
```{r, warning=FALSE}
RCT %>% ggplot(aes(x=RCT$age)) + geom_histogram(binwidth=8)
RCT %>% ggplot(aes(x=RCT$id)) + geom_bar()
RCT %>% ggplot(aes(x=RCT$ps12)) + geom_bar()
RCT %>% ggplot(aes(x=RCT$binary_satisfaction)) + geom_bar()
```
Do our variables looks like this?
```{r, out.width = "800px", echo=FALSE}
knitr::include_graphics("http://www.statisticshowto.com/wp-content/uploads/2014/12/gaussian-distribution-family.png")
```
# Means, medians and modes
- Mean: sum of all datapoints / number of datapoints
- Median: middle datapoint
- Mode: most common datapoint
```{r, out.width = "800px", echo=FALSE}
knitr::include_graphics("https://upload.wikimedia.org/wikipedia/commons/thumb/d/de/Comparison_mean_median_mode.svg/2000px-Comparison_mean_median_mode.svg.png")
```
Have a go with these variables: **age**, **ps12**, **move24h**
You can use the functions `mean()` and `median()`, for example:
```{r}
mean(RCT$ps12, na.rm=TRUE)
median(RCT$ps12, na.rm=TRUE)
```
# Measuring 'spread'
- For normally-distibuted data, use standard deviation
- For non normally-distributed data, use interquartile range
```{r}
IQR(RCT$age, na.rm=TRUE)
sd(RCT$age, na.rm=TRUE)
```
# Calculate it all at once
```{r}
summary(RCT)
```
# Testing (here be dragons)
- best_option <- "**Ask a statistician**"
- pragmatic_option <- "Do it yourself, **carefully** and **simply**"
## Think about
1. The hypothesis you want to test
2. Where your observations come from
3. The type of variables you are dealing with
4. The assumptions that different tests use
5. Interpreting the test results
# Hypothesis 1
> 'Mean age differs between the two treatment arms'
> Recall: The treatment arms are 1) patients receiving local anaesthetic via drain, and 2) patients receiving local anaesthetic via injection to the skin flaps'
- What sort of variables are these?
- What is the *independent variable*?
- What is the *dependent variable*?
- What is the *null hypothesis*?
- **Which test should we use?**
# Unpaired 2-tail t test: Assumptions
- Values within each group are independent
- The two groups are independent of one another
- (Values in each group should be approximately normally-distributed)
# Let's look at our data...
```{r}
RCT %>% ggplot(aes(x=fake_age, group=random, fill=random)) + geom_histogram(position="identity", alpha=0.5, binwidth=6) + theme_bw()
```
Note that the 'spread' of the groups is different - a problem for the standard t test, but R takes care of this for us behind the scenes.
# Let's run the test!
```{r}
t.test(RCT$fake_age~RCT$random)
```
# Hypothesis 2
> 'Patient satisfaction after axillary node dissection depends on treatment arm.'
# Hypothesis 2
> 'Patient satisfaction after axillary node dissection depends on treatment arm.'
- What sort of variables are these?
- What is the *independent variable*?
- What is the *dependent variable*?
- What is the *null hypothesis*?
- **Which test should we use?**
# Chi-squared test for independence: Assumptions
- The two groups are independent of one another
- Count in each cell of the table should be 5 or more
# Let's look at our data
```{r}
tbl = table(RCT$random, RCT$binary_satisfaction)
```
```{r, echo=FALSE}
tbl
```
## Let's run the test!
```{r}
chisq.test(tbl)
```
# Picking the right test
[UCLA Which test?](https://stats.idre.ucla.edu/other/mult-pkg/whatstat/)
# A gentle (and pretty!) intro to probability/stats
[Seeing theory](http://students.brown.edu/seeing-theory/)
# Questions