---
title: "Escrime & cancer du sein"
subtitle: "Petit échantillon"
author: "Philippe MICHEL"
date: "`r Sys.Date()`)"
output:
  xaringan::moon_reader:
    lib_dir: libs
    nature:
      highlightStyle: github
      highlightLines: true
      countIncrementalSlides: false
---


```{r setup, include=FALSE}
options(htmltools.dir.version = FALSE)
knitr::opts_chunk$set(echo = FALSE,
                      warning = FALSE,
                      message = FALSE)
# knitr::opts_chunk$set(echo = TRUE, warning = TRUE, message = TRUE)
```


```{r info}
rm(list = ls())
library("psy")
library("kableExtra")
library("corrplot")
library("rmarkdown")
library("thesisph")
library("Hmisc")
library("tidyverse")
library("missMDA")
library("epiDisplay")
library("FactoMineR")
library("factoextra")
library("lubridate")
library("rlang")
library("knitr")
# sessionInfo()
#
```


```{r import}
# Importation des données
#
tt <- read.csv("data/SF36 long.csv")
names(tt) <- tolower(names(tt))
names(tt) <- chartr("éàèêç", "eaeec", names(tt))
tt$temps <- fct_rev(tt$temps)
av <- subset(tt, tt$temps == "avant")
ap <- subset(tt, tt$temps == "après")
tt$id <- as.factor(tt$id)
#tt <- as_tibble(tt)
```
class: center, inverse, middle

# Validation interne du questionnaire

---
```{r alpha}
aa <- cronbach(av[, c(3:6, 8:11)])
aa <- round(aa$alpha, 3)
```

Même si le SF36 est une échelle bien validée il est préférable de vérifier la validité interne sur notre échantillon.

Le **test de Cronbach** pratiqué sur les questionnaires *avant*  & en excluant les variables calculées (*score physique* & *score mental*) montre :

**$\alpha$ = `r  aa`** 

ce qui est excellent même trop, les variables semblent très liées les unes avec les autres. 

Ce qui est confirmé par le calcul des corrélations entre variables qui sont toutes positives, c'est à dire qu'aucune variable ne baisse quand les autres montent aussi bien avant que après.

---
class: center

```{r corav}
aa <- cor(av[, -c(1, 2, 7, 12)])
corrplot(
  aa,
  method = "color",
  type = "upper",
  order = "hclust",
  tl.col = "black",
  diag = FALSE,
  title = "Tableau de corrélation - Avant",
  mar = c(5, 4, 1, 2)
)
```
---

```{r corap}
aa <- cor(ap[, -c(1, 2, 7, 12)])
corrplot(
  aa,
  method = "color",
  type = "upper",
  order = "hclust",
  tl.col = "black",
  diag = FALSE,
  title = "Tableau de corrélation - Après",
  mar = c(5, 4, 1, 2)
)
```

---
# Description des résultats

## Avant
```{r tabdesc1}
tabdescph(tt[1:22,3:12], capt= 'Questionnaire "avant"', lab = "descav", ka = 1)
```

---
# Description des résultats

## Après


```{r tabdesc2}
tabdescph(tt[23:44,3:12], capt= 'Questionnaire "avant"', lab = "descav", ka = 1)
```

---
## Analyse factorielle
Il s'agit d'un essai de classification des cas. 

Sur cet échantillon il est difficile de définir des groupes dans une population qui semble très homogène. De plus toutes les variables vont dans le même sens & en particulier les deux variables calculées. 

IL n'y a pas de différence évidente avant/après. L'axe 1 est défini par de nombreuses variables, l'axe 2 principalement par *gh*. 

---
```{r fact1}
tti <- tt[, -1]
rmm <- PCA(
  tti,
  quali.sup = 1,
  quanti.sup = c(6, 11),
  graph = FALSE
)
fviz_pca_var(
  rmm,
  col.var = "contrib",
  gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"),
  repel = TRUE
)
```

---
```{r fact2}
fviz_pca_ind(rmm,
             label = "none", # hide individual labels
             habillage = 1, # color by groups
             palette = c("#00AFBB", "#E7B800", "#FC4E07"),
             addEllipses = TRUE # Concentration ellipses
             )
```

---
# Comparaison avant/après 


```{r tabcomp}
tabx <- NULL
for (i in 3:12){
  nn <- names(tt)[i]
  tti <- t.test(tt[,i]~ tt$temps, var.equal = TRUE, paired = TRUE)
  ppi <- round(tti$p.value, 3)
  mmv <- round(mean(av[,i]), 3)
  ssv <- round(sd(av[,i]), 3)
  ligv <- paste0(mmv," ± ", ssv)
  mmp <- round(mean(ap[,i]), 3)
  ssp <- round(sd(ap[,i]), 3)
  ligp <- paste0(mmp," ± ", ssp)
  lig <- c(nn,ligv,ligp,ppi)
  tabx <- rbind(tabx,lig)
}
  kable(tabx, row.names = FALSE, 
          col.names=c("","avant", "après","p"), 
          escape = F) %>% 
      kable_styling(bootstrap_options = "striped", full_width = FALSE,
                    position = "center")
```

Les moyennes avec l'écart-type sont données pour chaque item avant & après.

---
```{r bp1}
tt %>% 
  ggplot() +
  aes(x = temps, y = score.physique, fill = temps) + 
  geom_violin() +
  geom_boxplot(width = 0.1, fill = "white") +
  labs(title = "Score physique"
             ) + 
     theme_light() + 
     theme(plot.title = element_text(size=16, face="bold"),
                axis.title.x = element_blank(),
                axis.title.y = element_blank(),
                axis.text.x = element_text(size=14),
                axis.text.y = element_text(size=12),
                legend.position = "none" 
               ) 
```
---
```{r bp2}
tt %>% 
  ggplot() +
  aes(x = temps, y = score.mental, fill = temps) + 
  geom_violin() +
  geom_boxplot(width = 0.1, fill = "white") +
  labs(title = "Score mental"
             ) + 
     theme_light() + 
     theme(plot.title = element_text(size=16, face="bold"),
                axis.title.x = element_blank(),
                axis.title.y = element_blank(),
                axis.text.x = element_text(size=14),
                axis.text.y = element_text(size=12),
                legend.position = "none" 
               ) 
```


On observe une amélioration significative pour le score mental & le score physique.

---
## Évolution par individu

```{r evo}
tt %>%
  ggplot() +
  aes(
    y = score.physique,
    x = temps,
    group = id,
    color = id
  ) +
  geom_point(show.legend = FALSE,
             size = 2) +
  geom_line(show.legend = FALSE,
            size = 1) +
  labs(title = "Score physique") +
  theme_light() +
  theme(
    plot.title = element_text(size = 16, face = "bold"),
    axis.title.x = element_blank(),
    axis.title.y = element_blank(),
    axis.text.x = element_text(size = 14),
    axis.text.y = element_text(size = 12),
    legend.position = "none"
  )
```
---
```{r evo2}
tt %>%
  ggplot() +
  aes(
    y = score.mental,
    x = temps,
    group = id,
    color = id
  ) +
  geom_point(show.legend = FALSE,
             size = 2) +
  geom_line(show.legend = FALSE,
            size = 1) +
  labs(title = "Score mental") +
  theme_light() +
  theme(
    plot.title = element_text(size = 16, face = "bold"),
    axis.title.x = element_blank(),
    axis.title.y = element_blank(),
    axis.text.x = element_text(size = 14),
    axis.text.y = element_text(size = 12),
    legend.position = "none"
  ) 
```


