forked from behrman/ros
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstents_tv.Rmd
More file actions
90 lines (70 loc) · 1.81 KB
/
stents_tv.Rmd
File metadata and controls
90 lines (70 loc) · 1.81 KB
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
---
title: "Regression and Other Stories: Stents"
author: "Andrew Gelman, Jennifer Hill, Aki Vehtari"
date: "`r Sys.Date()`"
output:
github_document:
toc: true
---
Tidyverse version by Bill Behrman.
Stents - comparing distributions. See Chapter 3 in
Regression and Other Stories.
-------------
```{r, message=FALSE}
# Packages
library(tidyverse)
# Parameters
# Common code
file_common <- here::here("_common.R")
#===============================================================================
# Run common code
source(file_common)
```
# 3 Some basic methods in mathematics and probability
## 3.5 Probability distributions
### Comparing distributions
Data
```{r}
# Mean times for each group
time_placebo <- 510
time_stent <- 530
# Standard deviations for each group
sd_placebo <- 190
sd_stent <- 190
```
```{r}
v <- pnorm(time_stent, mean = time_placebo, sd = sd_placebo)
v
```
The mean time for the treatment group would have been in the `r round(100* v)`th percentile for the control group.
Distributions of potential outcomes for patients given placebo or heart stent.
```{r}
x <-
seq(
max(
0,
min(time_placebo - 3 * sd_placebo, time_stent - 3 * sd_stent)
),
max(time_placebo + 3 * sd_placebo, time_stent + 3 * sd_stent),
length.out = 201
)
v <-
tribble(
~group, ~data,
"Placebo", tibble(x, y = dnorm(x, mean = time_placebo, sd = sd_placebo)),
"Stent", tibble(x, y = dnorm(x, mean = time_stent, sd = sd_stent))
) %>%
unnest(data)
v %>%
ggplot(aes(x, y, color = group)) +
geom_line() +
scale_x_continuous(breaks = scales::breaks_width(200)) +
scale_y_continuous(breaks = 0) +
labs(
title =
"Distributions of potential outcomes for patients given placebo or heart stent",
x = "Exercise time (seconds)",
y = NULL,
color = "Group"
)
```