-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
126 lines (97 loc) · 4.71 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
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
---
output:
github_document:
df_print: tibble
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
# Non-Conservative Size-α Modified Fisher's Exact Test
<!-- badges: start -->
[![lifecycle](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
[![R-CMD-check](https://github.com/pvdmeulen/modifiedfisher/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/pvdmeulen/modifiedfisher/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->
```{r options, echo = FALSE, message=FALSE, include=FALSE}
options(cli.ignore_unknown_rstudio_theme = TRUE)
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
tidy = TRUE,
fig.path = "man/figures/README-",
out.width = "100%"
)
```
## Installation
You can install the latest version of this `modifiedfisher` package by using `devtools`:
```{r installation, echo = TRUE, eval = FALSE}
devtools::install_github("pvdmeulen/modifiedfisher")
```
## Examples
The modified Fisher Exact Test (see more information below) can be called using the `modified_fisher_exact_test()` function:
```{r example1, echo = TRUE, eval = TRUE}
library(modifiedfisher)
modified_fisher_exact_test(u = 5, m = 12, v = 7, n = 11, odds_ratio = 1, alpha = 0.05)
```
The above example uses $m = 12$ and $n = 11$, echoing Figure 1(a) and Table 2 in the paper linked below. As you can see, the p-value, estimated odds ratio, and confidence intervals match the paper's. A similar size plot can be constructed by setting the `local_size_data` argument to `TRUE`, and using the resulting local size dataframe to construct the plot:
```{r example2, echo = TRUE, eval = TRUE}
test_result <- modified_fisher_exact_test(u = 5, m = 12, v = 7, n = 11, odds_ratio = 1, alpha = 0.05, local_size_data = TRUE)
```
The data is now stored in the `test_result$local.size.data` object, with the first five rows given by:
```{r print_data, echo = FALSE, eval = TRUE}
knitr::kable(head(test_result$local.size.data))
```
Plotting this leads to a similar plot as Figure 1(a):
```{r plot_data, echo = FALSE, eval = TRUE, message = FALSE, warning = FALSE}
library(ggplot2)
library(ggdark)
plot <- ggplot(data = test_result$local.size.data, aes(x = pi1, y = size)) +
geom_line(colour = "#DB5461", linewidth = 1) +
#scale_y_continuous(limits = c(-4, 4*alpha*100)) +
geom_hline(yintercept = 0.05*100, linetype = 2, colour = "grey30",
linewidth = 0.4) +
coord_cartesian(ylim = c(0, 1.05*0.05*100)) +
#scale_color_brewer(palette = "Dark2") +
labs(
title = "Size of Modified Fisher Exact Test",
subtitle = latex2exp::TeX(paste0("\\textit{$m=", 12, ",\\,n=", 11,
",\\,H_{0}=", 1, "$}")),
y = "Size (%)",
x = bquote(pi[.("1")])
) +
theme(
text = element_text(size = 12),
plot.title = element_text(face = "bold"),
plot.subtitle = element_text(family = "STIX Two Text", face = "italic"),
axis.title.x = element_text(family = "STIX Two Text", face = "italic"),
legend.position = "bottom",
legend.title = element_blank(),
legend.text = element_text(size = 12),
plot.background = element_rect(fill = NA),
panel.background = element_rect(fill = NA)
)
light_plot <- plot +
theme_bw()
dark_plot <- plot +
ggdark::dark_theme_bw() +
theme(
panel.background = element_rect(fill = "#0D1116"),
plot.background = element_rect(fill = "#0D1116")
)
ggsave(light_plot, filename = "man/figures/README-light_plot_data-1.svg",
width = 160, height = 120, units = "mm", bg = "transparent",
dpi = "retina")
ggsave(dark_plot, filename = "man/figures/README-dark_plot_data-1.svg",
width = 160, height = 120, units = "mm", bg = "transparent",
dpi = "retina")
#knitr::include_graphics("man/figures/README-plot_data-1.svg")
```
<picture>
<source media="(prefers-color-scheme: dark)" srcset="man/figures/README-dark_plot_data-1.svg">
<source media="(prefers-color-scheme: light)" srcset="man/figures/README-light_plot_data-1.svg">
<img alt="Shows a graph with test size on the y-axis and nuisance parameter pi_1 between zero and one on the x-axis, with a line showing the relationship between the two. The line is shaped like two humps, with the maximum being rouhgly 4%.">
</picture>
## The Modified Fisher Exact Test
### [Read the article here](https://www.researchgate.net/publication/351111885_Consistent_Confidence_Limits_P_Values_and_Power_of_the_Non-Conservative_Size_-a_Modified_Fisher_Exact_Test)
- Add brief rationale and explanation of theory
## Next steps
- Implement checks and unit tests
- Document functions in a consistent way with article / SAS macro
- Add randomised Fisher Exact Test option