---
title: "2024 OLGA NOF IADR Tartu"
author: "SU"
date: 2024-12-06
date-modified: last-modified
language:
title-block-published: "CREATED"
title-block-modified: "UPDATED"
format:
html:
toc: true
toc-expand: 3
code-fold: true
code-tools: true
editor: visual
execute:
echo: false
cache: true
warning: false
message: false
---
```{r}
# Load required libraries with pacman; installs them if not already installed
pacman::p_load(tidyverse, # tools for data science
visdat, #NAs
hrbrthemes, # nice ggplot themes
janitor, # for data cleaning and tables
here, # for reproducible research
gtsummary, # for tables
# explore, # for EDA, check https://rolkra.github.io/explore/
# countrycode, # to normalize country data
# library(ggeasy), # to use variable labels in ggplot, then easy_labs()
easystats, # check https://easystats.github.io/easystats/
scales,
lubridate
)
```
# Dataset
```{r}
df <- read_csv(here("data", "df.csv"))
```
```{r}
theme_set(theme_minimal())
```
## Questions
Everything comparing MID vs Control
### Average costs & 95% CI costs
```{r}
df |>
group_by(Group) |>
summarise(mean_cost = mean(Cost, na.rm = TRUE),
sd_cost = sd(Cost, na.rm = TRUE),
n = n(),
se = sd_cost/sqrt(n),
ci = qt(0.975, df = n-1) * se) |>
mutate(ci = ci) |>
mutate(across(where(is.numeric), round, 1)) |>
knitr::kable()
```
```{r}
# Plot the costs per group
df |>
ggplot(aes(x = Group, y = Cost, fill = Group)) +
geom_violin(alpha = .2) +
geom_boxplot(width = 0.2) +
geom_jitter(width = 0.1, alpha = 0.1) +
labs(title = "Costs per group",
x = "Group",
y = "Costs (€)") +
theme(legend.position = "none")
```
```{r}
df |>
with(glm(Cost ~ Group)) |>
gtsummary::tbl_regression()
```
### Treated primary teeth & 95% CI (Treated primary teeth )
```{r}
# count the number of primary teeth per group
df |>
group_by(Group) |>
summarise(mean_treated_primary_teeth = mean(`Treated primary teeth`, na.rm = TRUE),
sd_treated_primary_teeth = sd(`Treated primary teeth`, na.rm = TRUE),
n = n(),
se = sd_treated_primary_teeth/sqrt(n),
ci = qt(0.975, df = n-1) * se) |>
mutate(ci = ci) |>
mutate(across(where(is.numeric), round, 1)) |>
knitr::kable()
```
```{r}
# plot the number of treated primary teeth per group
df |>
ggplot(aes(x = Group, y = `Treated primary teeth`, fill = Group)) +
geom_violin(alpha = .2) +
geom_boxplot(width = 0.2) +
geom_jitter(width = 0.1, alpha = 0.1) +
labs(title = "Treated primary teeth per group",
x = "Group",
y = "Treated primary teeth") +
theme(legend.position = "none")
```
```{r}
df |>
with(glm(`Treated primary teeth` ~ Group)) |>
gtsummary::tbl_regression()
```
### Extracted primary teeth & 95% CI
```{r}
# count the number of extracted primary teeth per group
df |>
group_by(Group) |>
summarise(mean_extracted_primary_teeth = mean(`Extractions (primary teeth)`, na.rm = TRUE),
sd_extracted_primary_teeth = sd(`Extractions (primary teeth)`, na.rm = TRUE),
n = n(),
se = sd_extracted_primary_teeth/sqrt(n),
ci = qt(0.975, df = n-1) * se) |>
mutate(ci = ci) |>
mutate(across(where(is.numeric), round, 1)) |>
knitr::kable()
```
```{r}
# plot the extracted primary teeth per group
df |>
ggplot(aes(x = Group, y = `Extractions (primary teeth)`, fill = Group)) +
geom_violin(alpha = .2) +
geom_boxplot(width = 0.1) +
geom_jitter(width = 0.1, alpha = 0.07) +
labs(title = "Extracted primary teeth per group",
x = "Group",
y = "Extracted primary teeth") +
theme(legend.position = "none")
```
```{r}
df |>
with(glm(`Extractions (primary teeth)` ~ Group)) |>
gtsummary::tbl_regression()
```
### Treated permanent teeth & 95% CI
```{r}
# count the number of permanent teeth treated per group
df |>
group_by(Group) |>
summarise(mean_treated_permanent_teeth = mean(`Treated permanent teeth`, na.rm = TRUE),
sd_treated_permanent_teeth = sd(`Treated permanent teeth`, na.rm = TRUE),
n = n(),
se = sd_treated_permanent_teeth/sqrt(n),
ci = qt(0.975, df = n-1) * se) |>
mutate(ci = ci) |>
mutate(across(where(is.numeric), round, 1)) |>
knitr::kable()
```
```{r}
# plot the treated permanent teeth per group
df |>
ggplot(aes(x = Group, y = `Treated permanent teeth`, fill = Group)) +
geom_violin(alpha = .2) +
geom_boxplot(width = 0.1) +
geom_jitter(width = 0.1, alpha = 0.05) +
labs(title = "Treated permanent teeth per group",
x = "Group",
y = "Treated permanent teeth") +
theme(legend.position = "none")
```
```{r}
df |>
with(glm(`Treated permanent teeth` ~ Group)) |>
gtsummary::tbl_regression()
```
### Extracted permanent teeth & 95% CI
```{r}
# count the number of permanent teeth extracted per group
df |>
group_by(Group) |>
summarise(mean_extracted_permanent_teeth = mean(`Extractions (permanent teeth)`, na.rm = TRUE),
sd_extracted_permanent_teeth = sd(`Extractions (permanent teeth)`, na.rm = TRUE),
n = n(),
se = sd_extracted_permanent_teeth/sqrt(n),
ci = qt(0.975, df = n-1) * se) |>
mutate(ci = ci) |>
mutate(across(where(is.numeric), round, 2)) |>
knitr::kable()
```
```{r}
#plot permanent tetth extracted per group
df |>
ggplot(aes(x = Group, y = `Extractions (permanent teeth)`, fill = Group)) +
geom_violin(alpha = .2) +
geom_boxplot(width = 0.1) +
geom_jitter(width = 0.1, alpha = 0.05) +
labs(title = "Extracted permanent teeth per group",
x = "Group",
y = "Extracted permanent teeth") +
theme(legend.position = "none")
```
```{r}
df |>
with(glm(`Extractions (permanent teeth)` ~ Group)) |>
gtsummary::tbl_regression()
```