-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
100 lines (77 loc) · 2.17 KB
/
README.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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%",
message = FALSE,
out.width = 600
)
```
# deltatest
<!-- badges: start -->
<!-- badges: end -->
## Installation
You can install the development version of deltatest from [GitHub](https://github.com/) with:
``` r
# install.packages("remotes")
remotes::install_github("hoxo-m/deltatest")
```
## Example
```{r example}
library(deltatest)
n_user <- 2000
set.seed(314)
df_c <- generate_dummy_data(n_user)
df_t <- generate_dummy_data(n_user)
deltatest(df_c$click, df_c$view, df_t$click, df_t$view)
```
```{r}
set.seed(314)
p_values <- NULL
for (i in 1:5000) {
df_c <- generate_dummy_data(n_user)
df_t <- generate_dummy_data(n_user)
x <- rbind(colSums(df_c), colSums(df_t)) |> data.frame()
result <- prop.test(x$click, x$view, correct = FALSE)
p_values[i] <- result$p.value
}
library(ggplot2)
library(dplyr)
df <- data.frame(p_value = p_values) |>
mutate(range = cut(p_value, breaks = seq(0, 1, by = 0.05))) |>
group_by(range) |>
summarise(p = factor(ceiling(max(p_value) * 20) / 20), n = n()) |>
mutate(prop = n / sum(n))
ggplot(df, aes(p, prop)) +
geom_col() +
geom_hline(yintercept = 0.05, color = "red") +
scale_y_continuous(breaks = seq(0, 1, by = 0.01), minor_breaks = NULL) +
xlab("p-value") + ylab("proportion")
```
```{r}
set.seed(314)
p_values <- NULL
for (i in 1:5000) {
df_c <- generate_dummy_data(n_user)
df_t <- generate_dummy_data(n_user)
result <- deltatest(df_c$click, df_c$view, df_t$click, df_t$view)
p_values[i] <- result$p.value
}
library(ggplot2)
library(dplyr)
df <- data.frame(p_value = p_values) |>
mutate(range = cut(p_value, breaks = seq(0, 1, by = 0.05))) |>
group_by(range) |>
summarise(p = factor(ceiling(max(p_value) * 20) / 20), n = n()) |>
mutate(prop = n / sum(n))
ggplot(df, aes(p, prop)) +
geom_col() +
geom_hline(yintercept = 0.05, color = "red") +
scale_y_continuous(breaks = seq(0, 1, by = 0.01), minor_breaks = NULL) +
xlab("p-value") + ylab("proportion")
```