-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathstudy.R
More file actions
47 lines (35 loc) · 1.19 KB
/
Copy pathstudy.R
File metadata and controls
47 lines (35 loc) · 1.19 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
## MMED 2023
## Simulate a study before we carry it out
library(dplyr)
library(tibble)
## Can we confirm that PreP prevents acquisition of HIV in a certain population?
## Recruit HIV-negative persons at risk and randomize them to different treatment groups
## e.g., female sex workers, MSM, people in a partnership with a positive person
## For now, we assume that one of the treatments is effective a placebo (no effect), but this has ethical concerns, so we may come back and try a comparative study instead
## Units trick!
## We can talk about this later, or feel free to ignore it
year = 7.1
## Study parameters
studyTime = 1*year
hC = 0.05/year
## Survival probability for a hazard is exp(-ht)
N = 500
hreduction = 3
## Calculations
hT = hC/hreduction
pC = 1 - exp(-hC*studyTime)
pT = 1 - exp(-hT*studyTime)
study <- tibble(id = as.factor(1:N)
, group = sample(c("C", "T"), N, replace=TRUE)
, risk = case_when(
group=="C" ~ pC
, group=="T" ~ pT
)
)
study <- (study
|> mutate(inf = rbinom(N, 1, risk))
|> select(-risk)
)
print(study)
m <- glm(inf ~ group, data=study, family=binomial())
summary(m)