-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathOR-RR.qmd
More file actions
59 lines (55 loc) · 1.18 KB
/
OR-RR.qmd
File metadata and controls
59 lines (55 loc) · 1.18 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
---
title: "OR-RR"
format: html
server: shiny
---
```{r}
sliderInput(
"pi1",
label = "baseline probability",
min = 0.00001,
max = .99999,
value = .5)
numericInput(
"or_max",
label = "max OR",
min = 0.0001,
# max = 100,
value = 10)
plotOutput("plot1")
```
```{r}
#| context: server
library(ggplot2)
odds = function(pi) pi / (1-pi)
odds.inv = function(odds) odds/(1+odds)
OR = function(pi1, pi2) odds(pi2) / odds(pi1)
RR = function(pi1, pi2) pi2 / pi1
OR_to_RR = function(pi1, OR)
{
odds1 = odds(pi1)
odds2 = OR * odds1
pi2 = odds.inv(odds2)
RR = RR(pi1, pi2)
}
RR_to_OR = function(pi1, RR)
{
pi2 = RR * pi1
OR = OR(pi1, pi2)
}
OR_RR_plot = function(pi1, max_OR = 3)
{
ggplot() +
geom_function(fun = function(x) OR_to_RR(pi1 = pi1, OR = x)) +
xlab("OR") +
ylab("RR") +
theme_bw() +
geom_abline(aes(intercept = 0, slope = 1, col = "y=x")) +
geom_hline(aes(yintercept = 1, col = "RR=1")) +
scale_y_continuous(trans = "log10", limits = c(1/max_OR, max_OR)) +
scale_x_continuous(trans = "log10", limits = c(1/max_OR, max_OR))
}
output$plot1 =
OR_RR_plot(input$pi1, input$or_max) |>
renderPlot()
```