options(OutDec = ",", scipen = 999)
set.seed(67)
library(dplyr)
library(ggplot2)
library(gtsummary)
library(patchwork)
theme_gtsummary_language(
language = "fr",
decimal.mark = ",",
# 95% CI separator : " - " à " ; "
ci.sep = " ; ",
big.mark = " "
)
theme_gtsummary_compact()
# Présentation commune des tableaux de régression
formater_estimation_table <- function(x) {
gtsummary::style_number(x, digits = 2, decimal.mark = ",", big.mark = " ")
}
formater_ic_table <- function(x) {
gtsummary::style_number(x, digits = 2, decimal.mark = ",", big.mark = " ")
}
formater_p_table <- function(p) {
ifelse(is.na(p), NA_character_,
ifelse(p < 0.001, "< 0,001", formatC(p, format = "f", digits = 3, decimal.mark = ",")))
}
presenter_table_regression <- function(tableau) {
tableau |>
modify_fmt_fun(c(conf.low, conf.high) ~ formater_ic_table) |>
modify_column_merge(
pattern = "[{conf.low} ; {conf.high}]",
rows = !is.na(conf.low) & !is.na(conf.high)
) |>
modify_header(
label = "**Terme**", estimate = "**OR**",
conf.low = "**IC 95 %**", p.value = "**p-valeur**"
)
}
load("../../data/birthweight.RData")
birthweight <- data
bw <- birthweight |>
transmute(
faible_poids = factor(LOW, levels = c(0, 1), labels = c("Non", "Oui")),
poids_naissance = BWT,
age = AGE,
age10 = AGE / 10,
poids_mere_lb = LWT,
poids_mere_10lb = LWT / 10,
tabagisme = factor(SMOKE, levels = c(0, 1), labels = c("Non-fumeuse", "Fumeuse")),
hypertension = factor(HT, levels = c(0, 1), labels = c("Non", "Oui")),
origine = factor(RACE, levels = c(1, 2, 3), labels = c("Caucasienne", "Afro-américaine", "Autre"))
)
# Couleurs et thème graphique
okabe_ito <- c(
noir = "#000000",
orange = "#E69F00",
bleu_ciel = "#56B4E9",
vert = "#009E73",
jaune = "#F0E442",
bleu = "#0072B2",
vermillon = "#D55E00",
rose = "#CC79A7"
)
theme_ste <- function(base_size = 10) {
theme_classic(base_size = base_size) +
theme(
axis.title = element_text(face = "bold"),
legend.position = "bottom",
legend.title = element_text(face = "bold")
)
}