Created
February 8, 2022 17:25
-
-
Save aliaksandrkazlou/416f053a0e1bed691e748d043c781537 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#### Libraries -------------------- | |
library(data.table) | |
library(ggplot2) | |
library(msm) | |
library(glue) | |
#### Data -------------------- | |
# inputs from here https://jamanetwork.com/journals/jamapsychiatry/fullarticle/482702 | |
set.seed(100) | |
n_depressed <- 195 | |
n_healthy <- 1282 - n_depressed | |
d_mean_depressed <- 19 | |
d_mean_healthy <- 22 | |
vitamin_d_depressed <- rtnorm(n_depressed, d_mean_depressed, 10, lower=0.1) | |
vitamin_d_healthy <- rtnorm(n_healthy, d_mean_healthy, 10, lower=0.1) | |
vitamin_d_healthy[vitamin_d_healthy > max(vitamin_d_depressed)] | |
dt <- rbind(data.table(d_ng_ml=vitamin_d_depressed, depression='дэпрэсія'), | |
data.table(d_ng_ml=vitamin_d_healthy, depression='здаровыя')) | |
#### Plots -------------------- | |
p1 <- ggplot(dt, aes(x=d_ng_ml, fill=depression)) + | |
geom_histogram( color="#e9ecef", alpha=0.6, position = 'identity', bins = 50) + | |
scale_fill_manual(values=c("#69b3a2", "#404080")) + | |
theme_minimal(base_size = 9) + | |
labs(fill="") + | |
geom_vline(xintercept = max(vitamin_d_depressed) + 0.5, color="red") + | |
theme(plot.subtitle = element_text(color = "#666666"), | |
plot.caption = element_text(color = "#AAAAAA")) + | |
labs(title = "Сімуляцыя размеркавання вітаміна D", | |
subtitle = glue("Дэпрэсія адсутнічае пры ўзроўні вітаміна D > {round(max(vitamin_d_depressed), 1)} ng/ml"), | |
caption = "by Aliaksandr Kazlou — akazlou.github.io") | |
ggsave(plot = p1, "d_depression_p1.png", dpi = "retina") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment