-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcohort.rmd
81 lines (69 loc) · 3.16 KB
/
cohort.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
---
title: "Cohort characteristics"
output: html_notebook
---
```{r}
library(mbtools)
theme_set(theme_minimal())
```
```{r}
cohort <- rbind(
fread("no_weight_loss.csv", colClasses=c(public_client_id="character")),
fread("successful_weight_loss.csv", colClasses=c(public_client_id="character"))
)
cohort[, "subset" := "controls"]
cohort[weight_change_relative < 0, "subset" := "weight loss"]
cohort[, subset := factor(subset)]
subcohort <- fread("data/manifest.csv", colClasses = classes)[has_close_microbiome == T]
subcohort[, "public_client_id" := paste0("0", public_client_id)]
cohort[, "additional_assays" := FALSE]
cohort[public_client_id %chin% subcohort$public_client_id, "additional_assays" := TRUE]
```
```{r}
library(arivale.data.interface)
chem <- get_snapshot("chemistries", clean=T)
chem <- chem[cohort, on=c("public_client_id", "days_in_program"), roll="nearest"]
```
```{r, fig.width=4, fig.height=3}
tt <- cohort[, t.test(bmi[since_baseline > 0], bmi[since_baseline == 0], paired=TRUE)]
ggplot(cohort, aes(x=since_baseline, y=bmi, group=public_client_id,
fill=additional_assays, color=subset)) +
geom_line(alpha=0.5) +
geom_point(shape=21, stroke=0, size=2.5) +
scale_fill_manual(values=c("black", "mediumseagreen")) +
labs(x="time in program [days]", y="BMI [kg/m²]") +
guides(color="none", fill="none")
ggsave("figures/bmi_trajectories.png", width=4, height=3, dpi=300)
cohort[, t.test(bmi[since_baseline == 0], bmi[since_baseline > 0], paired=TRUE)]
```
```{r, fig.width=8, fig.height=8}
measures <- c("ADIPONECTIN__SERUM", "HDL_CHOL_DIRECT", "LDL_CHOL_CALCULATION",
"GLUCOSE", "HOMA_IR", "INSULIN", "CRP_HIGH_SENSITIVITY",
"GLYCOHEMOGLOBIN_A1C")
legends <- c("serum adiponectin [mg/L]", "serum HDL [mg/L]", "serum LDL [mg/L]",
"serum glucose [mg/L]", "HOMA IR [index]", "serum insulin [mIU/L]",
"serum CRP [mg/L]", "glycated hemoglobin [%]")
select <- chem[, c("public_client_id", "since_baseline", "additional_assays", measures), with=F]
names(select) <- c("public_client_id", "since_baseline", "additional_assays", legends)
select <- melt(select, id.vars=c("public_client_id", "since_baseline", "additional_assays"), value.name="value", variable.name="measure")
stats <- function(value, since_baseline) {
s <- t.test(value[since_baseline > 0], value[since_baseline == 0], paired=TRUE)
list(t=s$statistic, p=s$p.value, delta_mu=s$estimate)
}
res <- select[, stats(value, since_baseline), by="measure"]
res[, "label" := sprintf("Δ=%.2g, p=%.2g", delta_mu, p)]
pl <- ggplot(select, aes(x=since_baseline, y=value, group=public_client_id, color=additional_assays)) +
geom_line(alpha=0.5, color="seagreen4") +
geom_point() +
labs(x="time in program [days]", y="") +
facet_wrap(~ measure, scales="free_y") +
guides(color="none") +
scale_color_manual(values=c("black", "tomato"))
pl <- pl + geom_text(data = res,
mapping = aes(x = Inf, y = Inf, label = label, group=1),
color = "black",
hjust = 1,
vjust = 2.5)
ggsave("figures/other_trajectories.png", width=8, height=8, dpi=300)
pl
```