---
title: "Acide tranexamique - augmentation mammaire"
bibliography: stat.bib
thanks: "Dr Mathilde LEHELLEY-GOUPY - Chirurgie plastique"
subtitle: "Rapport statistique"
author: "Philippe MICHEL"
lang: fr-FR
date: today
date-format: "DD/MM/YYYY"
format: pdf
pdf-engine: lualatex
keep-tex: true
number-sections: true
toc: true
lof: true
lot: true
mainfont: Faune
mainfontoptions:
  - Numbers=OldStyle
  - Ligatures=TeX
sansfont: Myriad Pro
sansfontoptions:
  - Ligatures=TeX
mathfontoptions: 
  - Numbers=Proportional
fig-cap-location: bottom
tbl-cap-location: top
class: scrartcl
classoption: [french]
papersize: a4paper
editor: source
cite-method: biblatex
license: "CC BY-SA"
---

```{r setup, include= FALSE}
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE, cache = FALSE,
 fig.width = 7,
 fig.asp = 0.8,
 out.width = "100%"
)
```

```{r info}
rm(list=ls())
library("baseph")
library("tidyverse")
library("kableExtra")
library(labelled)
library(gtsummary)
library(colorspace)
# sessionInfo()
```

## Réorganisation des données

Les variables *uniformes* ont été supprimées à savoir :

- `Gender` = F
- `Surgical Pocket` = Retro-Muscular

Les valeurs des drains ont été résumées en une seule variable `drain (mL)`.

```{r}
#| label: import

rm(list = ls())
bn <- read_csv("datas/titres.csv",show_col_types = FALSE)
bnom <- bn$nom
#
tt <- debutph("datas/TXA.csv", bnom)


#
tt <- tt |> 
  mutate(drain = drain.right.d1 + drain.right.d2 +  drain.right.d3 + drain.left.d1 + drain.left.d2 + drain.left.d3) |> 
  select(-starts_with("drain."))
var_label(tt$drain) <- "drain (mL)"

```

## Description de la population

```{r}  
#| label: groupes

gg <- tt |> 
  group_by(groupe) |> 
  summarise(n())
```


L'échantillon comporte deux groupes : un groupe "témoin" de 
 `r gg[[1,2]]` cas & un groupe traité `TXA` de `r gg[[2,2]]` cas. Il y a `r ncol(tt)-1` variables dont trois concernent le suivi à distance.

```{r}
#| label: tab1
#| tbl-cap: "Description de la population"

tabcph(tt[,1:6], groupe, test = "moy", titre = "Description de la population")
```


## Critère principal

On recherche une différence sur l'évolution des patients entre les deux groupes.

### Péri opératoire

```{r}
#| label: tabc1
#| tbl-cap: "Èvolution péri-opératoire"
nlig <- c(1,7,8,13,9)
tabcph(tt[,nlig], groupe, test = "moy", titre = "Èvolution péri-opératoire")
```

L'acide tranexamique semble diminuer le saignement post opératoire. On cherche si d'autres facteurs ont pu jouer sur ce critère.

```{r}
#| label: draint1
#| tbl-cap: "Facteurs de saignement - analyse monovariée"

tll <- c("", "p-value")
for (i in 1:8){
ll <- lm(tt$drain~pull(tt[,i]))
lla <- anova(ll)
lla <- beaup(lla[[5]][1])
llig <- c(var_label(tt[i]),lla)
tll <- rbind(tll,llig)
}
kbl(tll,
    booktabs = T,
    row.names = FALSE,
    col.names =c("","p-value"), 
    escape = FALSE) |>
  kable_styling(latex_options = c("hold_position", "scale_down"),
                position = "center") |>
  footnote(general = "variables factorielles : t. test ; variables numériques : test de corrélation")
```

```{r}
#| label: draint2
#| tbl-cap: "Facteurs de saignement - analyse multivariée"

lm(formula = drain ~ groupe + mean.operative.blood.pressure + 
            operative.time, data = tt) |> 
  tbl_regression() |>
  bold_labels() |> 
  as_kable_extra(
    format = "latex",
    booktabs = TRUE
  )
```


Seul le traitement semble influer sur le saignement par les drains.

```{r}
#| label: draing1
#| fig-cap: "Operative time and Drain volume"

tt |> 
  ggplot() +
  aes(x = operative.time, y = drain) +
  geom_point() +
  geom_smooth(method=lm) + 
      labs(
      title = "Operative time and Drain volume",
      subtitle = "p = 0.017",
      x = "Operative time (min)",
      y = "Drain (mL)",
    ) +
  theme_light() +
    theme(
      plot.title = element_text(size = 18, face = "bold"),
      plot.subtitle = element_text(size = 12),
      axis.title.x = element_text(size = 12),
      axis.title.y = element_text(
        size = 12,
        vjust = .5
      ),
      axis.text.x = element_text(
        size = 12,
      ),
      axis.text.y = element_text(size = 12),
      legend.position = "none"
    )
```

```{r}
#| label: draing2
#| fig-cap: "Treatment TXA and Drain volume"

tt |> 
  ggplot() +
  aes(x = groupe, y = drain, fill = groupe) +
  geom_boxplot() +
        labs(
      title = "Treatment TXA and Drain volume",
      subtitle = "p = 0.023",
      x = "",
      y = "Drain (mL)",
    ) +
  theme_light() +
    scale_fill_discrete_qualitative(palette = "Dynamic") +
    theme(
      plot.title = element_text(size = 18, face = "bold"),
      plot.subtitle = element_text(size = 12),
      axis.title.x = element_blank(),
      axis.title.y = element_text(
        size = 12,
        vjust = .5
      ),
      axis.text.x = element_text(
        size = 12,
      ),
      axis.text.y = element_text(size = 12),
      legend.position = "none"
    )


```

### Évaluation à distance

```{r}
#| label: tabc2
nlig <- c(1,10:12)
tabcph(tt[,nlig], groupe, test = "moy", titre = "Èvolution")
``` 

## Technique {.appendix}

Les données démographiques on été décrites par la moyenne & l'écart-type pour les données numériques, en pourcentage pour les données catégorielles. 

Pour le critère principal la comparaison des deux groupes a été réalisée par des tests de $\chi^2$ pour les données discrètes & des test de Student pour les données numériques. . 

un modèle de régression linéaire a ensuite été utilisé pour rechercher des facteurs prédictif du saignement. Ce modèle
de régression linéaire a permis d’explorer les facteurs associés à la réponse après un balayage bivarié retenant comme candidats les facteurs ayant une association avec la réponse significative à p=0,25. Une recherche du meilleur modèle a ensuite été réalisée par un step-by-step descendant évaluée par le critère d’information d’Akaike.

L'analyse statistique a été réalisée avec le logiciel **R** [@rstat] & divers packages en particulier `tidyverse` [@tidy], `FactoMineR` [@facto] & `baseph` [@baseph]. 
