Skip to content

Commit f1a9fec

Browse files
committed
add in one prop coerced from logical
1 parent ffef239 commit f1a9fec

File tree

4 files changed

+175
-46
lines changed

4 files changed

+175
-46
lines changed

inst/doc/flights_examples.R

+46-23
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,29 @@ ggplot(null, aes(x = stat)) +
5252
null %>%
5353
summarize(p_value = mean(stat < x_tilde) * 2)
5454

55+
## ------------------------------------------------------------------------
56+
p_hat <- fli_small %>%
57+
summarize(mean(day_hour == "morning")) %>%
58+
pull()
59+
null <- fli_small %>%
60+
specify(response = day_hour, success = "morning") %>%
61+
hypothesize(null = "point", p = .5) %>%
62+
generate(reps = 1000, type = "simulate") %>%
63+
calculate(stat = "prop")
64+
ggplot(null, aes(x = stat)) +
65+
geom_bar() +
66+
geom_vline(xintercept = p_hat, color = "red")
67+
null %>%
68+
summarize(p_value = mean(stat < p_hat) * 2)
69+
70+
## ------------------------------------------------------------------------
71+
null <- fli_small %>%
72+
mutate(day_hour_logical = (day_hour == "morning")) %>%
73+
specify(response = day_hour_logical, success = "TRUE") %>%
74+
hypothesize(null = "point", p = .5) %>%
75+
generate(reps = 1000, type = "simulate") %>%
76+
calculate(stat = "prop")
77+
5578
## ------------------------------------------------------------------------
5679
d_hat <- fli_small %>%
5780
group_by(season) %>%
@@ -166,29 +189,29 @@ ggplot(null, aes(x = stat)) +
166189
null %>%
167190
summarize(p_value = mean(stat > slope_hat) * 2)
168191

169-
## ----eval=FALSE----------------------------------------------------------
170-
# x_bar <- fli_small %>%
171-
# summarize(mean(arr_delay)) %>%
172-
# pull()
173-
# boot <- fli_small %>%
174-
# specify(response = arr_delay) %>%
175-
# generate(reps = 1000, type = "bootstrap") %>%
176-
# calculate(stat = "mean") %>%
177-
# pull()
178-
# c(lower = x_bar - 2 * sd(boot),
179-
# upper = x_bar + 2 * sd(boot))
180-
181-
## ----eval=FALSE----------------------------------------------------------
182-
# p_hat <- fli_small %>%
183-
# summarize(mean(day_hour == "morning")) %>%
184-
# pull()
185-
# boot <- fli_small %>%
186-
# specify(response = day_hour, success = "morning") %>%
187-
# generate(reps = 1000, type = "bootstrap") %>%
188-
# calculate(stat = "prop") %>%
189-
# pull()
190-
# c(lower = p_hat - 2 * sd(boot),
191-
# upper = p_hat + 2 * sd(boot))
192+
## ------------------------------------------------------------------------
193+
x_bar <- fli_small %>%
194+
summarize(mean(arr_delay)) %>%
195+
pull()
196+
boot <- fli_small %>%
197+
specify(response = arr_delay) %>%
198+
generate(reps = 1000, type = "bootstrap") %>%
199+
calculate(stat = "mean") %>%
200+
pull()
201+
c(lower = x_bar - 2 * sd(boot),
202+
upper = x_bar + 2 * sd(boot))
203+
204+
## ------------------------------------------------------------------------
205+
p_hat <- fli_small %>%
206+
summarize(mean(day_hour == "morning")) %>%
207+
pull()
208+
boot <- fli_small %>%
209+
specify(response = day_hour, success = "morning") %>%
210+
generate(reps = 1000, type = "bootstrap") %>%
211+
calculate(stat = "prop") %>%
212+
pull()
213+
c(lower = p_hat - 2 * sd(boot),
214+
upper = p_hat + 2 * sd(boot))
192215

193216
## ------------------------------------------------------------------------
194217
d_hat <- fli_small %>%

inst/doc/flights_examples.Rmd

+35-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ output:
77
df_print: kable
88
vignette: |
99
%\VignetteIndexEntry{flights example}
10-
%\VignetteEngine{knitr::rmarkdown}
1110
%\VignetteEncoding{UTF-8}
11+
%\VignetteEngine{knitr::rmarkdown}
12+
editor_options:
13+
chunk_output_type: console
1214
---
1315

1416
```{r include=FALSE}
@@ -86,6 +88,36 @@ null %>%
8688
summarize(p_value = mean(stat < x_tilde) * 2)
8789
```
8890

91+
### One categorical (one proportion)
92+
93+
```{r}
94+
p_hat <- fli_small %>%
95+
summarize(mean(day_hour == "morning")) %>%
96+
pull()
97+
null <- fli_small %>%
98+
specify(response = day_hour, success = "morning") %>%
99+
hypothesize(null = "point", p = .5) %>%
100+
generate(reps = 1000, type = "simulate") %>%
101+
calculate(stat = "prop")
102+
ggplot(null, aes(x = stat)) +
103+
geom_bar() +
104+
geom_vline(xintercept = p_hat, color = "red")
105+
null %>%
106+
summarize(p_value = mean(stat < p_hat) * 2)
107+
```
108+
109+
Logical variables will be coerced to factors:
110+
111+
```{r}
112+
null <- fli_small %>%
113+
mutate(day_hour_logical = (day_hour == "morning")) %>%
114+
specify(response = day_hour_logical, success = "TRUE") %>%
115+
hypothesize(null = "point", p = .5) %>%
116+
generate(reps = 1000, type = "simulate") %>%
117+
calculate(stat = "prop")
118+
```
119+
120+
89121
### Two categorical (2 level) variables
90122

91123
```{r}
@@ -225,7 +257,7 @@ null %>%
225257

226258
### One numerical (one mean)
227259

228-
```{r eval=FALSE}
260+
```{r}
229261
x_bar <- fli_small %>%
230262
summarize(mean(arr_delay)) %>%
231263
pull()
@@ -240,7 +272,7 @@ c(lower = x_bar - 2 * sd(boot),
240272

241273
### One categorical (one proportion)
242274

243-
```{r eval=FALSE}
275+
```{r}
244276
p_hat <- fli_small %>%
245277
summarize(mean(day_hour == "morning")) %>%
246278
pull()

0 commit comments

Comments
 (0)