9deportes

Published

October 26, 2024

crees que podríamos hacer un análisis multivariante donde se pueda observar todos los deportes por separado para mujeres y hombres por separado?? con C.I. 95% también sería interesante poder comparar cuándo “sube más el cortisol de 0 a 30” si los días de descanso (rest) o los días de competición (Comp)??

Carga de datos

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.5.1     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.1
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggsignif)
library(DT)
#devtools::load_all("../ggstatsplot-main")
library(ggstatsplot)
Warning: package 'ggstatsplot' was built under R version 4.4.1
You can cite this package as:
     Patil, I. (2021). Visualizations with statistical details: The 'ggstatsplot' approach.
     Journal of Open Source Software, 6(61), 3167, doi:10.21105/joss.03167
library(lme4)
Warning: package 'lme4' was built under R version 4.4.1
Loading required package: Matrix

Attaching package: 'Matrix'

The following objects are masked from 'package:tidyr':

    expand, pack, unpack
library(lmerTest)

Attaching package: 'lmerTest'

The following object is masked from 'package:lme4':

    lmer

The following object is masked from 'package:stats':

    step
theme_set(theme_minimal())
miTema <-theme_get()
#miTema <-theme_get() +
#theme(axis.text.x = element_text(angle = 0, vjust = 0, hjust=1),legend.position = "none")
theme_set(miTema)

df=readxl::read_xlsx("CAR_PNEC_3.xlsx",1) %>% 
  mutate(ID=1:nrow(.),
         IMC=round(IMC,2),
         
         Cluster=as.factor(sprintf("%d_%d",Sport,Cluster))) %>%
  select(ID,Cluster,everything()) %>%
  mutate(CORTinc_rest=round(CORT_30_rest-CORT_Awak_rest,3),
         CORTinc_comp=round(CORT_30_comp-CORT_awak_comp,3),
         CORTincDif=round(CORTinc_comp-CORTinc_rest,3)) %>% 
  mutate(Sport=factor(Sport, 
                         levels=1:8,
                         labels=c("Hockey","Handball","e-Sports","Swimming", "Football", "Athletism", "Badminton","Judo"))) %>% 
  mutate(Sport = forcats::fct_relevel(Sport,
  "Swimming", "Athletism", "Judo", "Badminton", "Football", "Hockey", "Handball", "e-Sports"),
         IT=factor(IT,labels=c("Individual","Team")),
         GENDER=factor(GENDER,labels=c("Female","Male"))) %>% 
         mutate(Clasificacion=case_when(
           Sport=="e-Sports" ~ 3,
           IT =="Individual" ~ 1,
           TRUE ~2
         ),
         Clasificacion=factor(Clasificacion,levels=1:3,labels=c("Individual","Team","e-Sports"))) %>% 
  select(ID:GENDER,Clasificacion,starts_with("CORTinc"),everything())
#df %>% datatable()

Octubre de 2024

Gráficos nuevos

df2=df %>% select(ID,GENDER,Sport,Type=Clasificacion, 
                      CORT_Awak_rest, CORT_30_rest, 
                      CORT_awak_comp, CORT_30_comp) %>% 
  mutate(CORT_rest_rel=CORT_30_rest/CORT_Awak_rest,
         CORT_comp_rel=CORT_30_comp/CORT_awak_comp,
         CORT_rest_incRel=(CORT_Awak_rest-CORT_30_rest)/CORT_Awak_rest*100,
         CORT_comp_increl=(CORT_awak_comp-CORT_30_comp)/CORT_awak_comp*100)


df3=df2 %>% select(ID,GENDER,Sport,Type,CORT_rest_rel,CORT_comp_rel) %>% pivot_longer(-c(ID,GENDER,Sport,Type)) %>% 
  mutate(name=str_replace(name,"_rel","")) %>% separate(name,into=c("Hormone","Activity")) %>% 
  mutate(Activity=factor(Activity,levels=c("rest","comp"), labels=c("Rest", "Competition")))
  

creaGrafico=function(df,Deporte="Football"){
ggwithinstats(df %>%  filter(Sport==Deporte),
              x = Activity,
              y = value,
              type = "np"
)+ylab("Relative change in cortisol after 30 minutes")+xlab(Deporte)+
    coord_cartesian(ylim=c(0.25,12))+ 
    #escala logaritmica en el eje y
    scale_y_log10()+
  theme_minimal()+theme(legend.position = "none")
}

#creaGrafico("Football")
#creaGrafico("Hockey")


listaGraficos=df3 %>% distinct(Sport) %>% pull(Sport) %>% map(creaGrafico %>% partial(df=df3))
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
gridExtra::grid.arrange(grobs=listaGraficos,ncol=2)

Segmentación de los resultados

Algunas categorías pueden quedar muy vacías así que tendremos diferentes niveles de segmentación.

Swimming y Athletism

listaGraficos=c("Swimming","Athletism") %>% map(creaGrafico %>% partial(df=df3))
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
gridExtra::grid.arrange(grobs=listaGraficos,ncol=2)

Swimming y Athletism por Sexo

listaGraficos=c("Swimming Female", "Swimming Male", "Athletism Female", "Athletism Male") %>%
  map(creaGrafico %>% partial(df=df3 %>% mutate(Sport =sprintf("%s %s",Sport,GENDER))))
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
gridExtra::grid.arrange(grobs=listaGraficos,ncol=2)

Judo y Badminton

listaGraficos=c("Judo","Badminton") %>% map(creaGrafico %>% partial(df=df3))
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
gridExtra::grid.arrange(grobs=listaGraficos,ncol=2)

Judo y Badminton por Sexo

listaGraficos=c("Judo Female", "Judo Male", "Badminton Female", "Badminton Male") %>%
  map(creaGrafico %>% partial(df=df3 %>% mutate(Sport =sprintf("%s %s",Sport,GENDER))))
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
gridExtra::grid.arrange(grobs=listaGraficos,ncol=2)

Deportes de equipo

En realidad no hay deportes de equipo con los dos sexos.

listaGraficos=c("Hockey", "Handball", "Football") %>% map(creaGrafico %>% partial(df=df3))
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
gridExtra::grid.arrange(grobs=listaGraficos,ncol=2)

Deportes de equipo por sexo

listaGraficos=c("Hockey Male", "Handball Female", "Football Male") %>%
  map(creaGrafico %>% partial(df=df3 %>% mutate(Sport =sprintf("%s %s",Sport,GENDER))))
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
gridExtra::grid.arrange(grobs=listaGraficos,ncol=2)

Abril de 2024

Vamos a dejar temporalmente fuera a los e-sports. Seguimos con el resto.

df=df %>% filter(Sport!="e-Sports")

¿La respuesta al cortisol está relacionada con las exigencias del deportista al empezar el día comparado con el día de descanso.?

Todos los días de competición han sido dias importantes (salvo quizás no tanto Atletismo y natación).

Es posible que en el futbol la variabilidad sea relacionada con ser suplente, portero, …

Llamamos repuesta al cortisol a la diferencia entre los 30 minutos y el despertar (Salience/Slope)

Queremos comparar los slopes INTRA entre dias de descanso y dias de competición.

Deportes individuales vs deportes de equipo.

Las demandas cognitivs produicen respuestas anticipatorias. Los equipos de e-sports no tienen ningun esfuerzo físico, pero si mental. Queremos comparar e-sports vs individuales.

n por deportes

df %>%  filter(complete.cases(.)) %>%
  group_by(Sport,GENDER) %>% 
  summarise(n=n()) %>% knitr::kable()
`summarise()` has grouped output by 'Sport'. You can override using the
`.groups` argument.
Sport GENDER n
Swimming Female 4
Swimming Male 8
Athletism Female 13
Athletism Male 11
Judo Female 7
Judo Male 8
Badminton Female 20
Badminton Male 14
Football Male 77
Hockey Male 14
Handball Female 14

n total:

df %>% filter(complete.cases(.)) %>%
  summarise(n=n())
# A tibble: 1 × 1
      n
  <int>
1   190

Discriptiva general de qué diferencia hay en los cambios entre dias de competicion y dias normales (CORTinc_Dif)

Dado que suele haber ciertos incrementos a los 30 minutos de despertarse, y tenemos dias de competición y de descanso, vamos a llamar CORTinc_Dif a la diferencia entre los respectivos incrementos de cortisol a los 30 minutos de despertarse entre dias de competición y días de descanso. Exploremos la variable en los diferentes deportes y vamos a añadir unos contrastes simples entre ellos:

Tras corregir por las diferencias de variabilidad con la prueba de Welch aparentemente los que experimentan cambios más altos entre dias de competición son los jugadores de badminton, que presentan diferencias significativas con respecto a los de atletismo y natación, que son los que experimentan menos cambios.

El coeficiente omega cuadrado parcial=0.32 indica que aproximadamente el 32% de la variabilidad en la variable dependiente se puede explicar por la diferencia entre los tipos de deporte, y visto como size-effect es un valor de efecto grande el que tiene el deporte en los cambios experimentados (valores mayores que 0.06 se consideran medianos y mayores que 0.14 grandes. Incluso el intervalo de confianza del 95% deja claro que el tamaño de efecto es de mediano a grande tirando más a grande.)

Deportes individuales vs deportes de equipo.

Pero el objetivo no era ese sino comparar deportes individuales y de grupo. Vamos a hacerlo de la forma más simple comparandolos directamente tal cual sin tener en cuenta otras consideraciones:

ggbetweenstats(
  data = df,
  x = IT,
  y = CORTincDif,
    var.equal=FALSE,
  bf.message=FALSE,
    point.args= list(color="gray"),
  ggsignif.args = list(textsize = 3, tip_length = 0.01, na.rm = TRUE),
  centrality.plotting = FALSE,
  centrality.point.args=list(alpha=0.5),
  centrality.label.args=list(fill = "#FFFFFF88",
                             max.overlaps = getOption("ggrepel.max.overlaps", default = 20)),
  ylab="Differences in salivary cortisol",
  xlab=""

)

Ahora vamos a hacer lo mismo usando una prueba no paramétrica:

ggbetweenstats(
  data = df,
  x = IT,
  y = CORTincDif,
  type="np",
  bf.message=FALSE,
    point.args= list(color="gray"),
  ggsignif.args = list(textsize = 3, tip_length = 0.01, na.rm = TRUE),
  centrality.plotting = FALSE,
  centrality.point.args=list(alpha=0.5),
  centrality.label.args=list(fill = "#FFFFFF88",
                             max.overlaps = getOption("ggrepel.max.overlaps", default = 20)),
  ylab="Differences in salivary cortisol",
  xlab=""
)

Tal cual, en la comparación no se aprecia diferencias significativas. Pero hay algo que no tenemos en cuenta… Los deportistas pertenecen a diferentes deportes y podría haber un efecto concreto de cada deporte (cluster) y lo que buscamos es si, más allá de ese efecto del deporte, hay algo que diferencie a los deportes individuales de los de equipo.

Vamos a hacer un modelo mixto con el deporte como factor aleatorio y el tipo de deporte como factor fijo:

lmer(CORTincDif ~ IT + (1 | Sport), data = df) %>% summary()
Linear mixed model fit by REML. t-tests use Satterthwaite's method [
lmerModLmerTest]
Formula: CORTincDif ~ IT + (1 | Sport)
   Data: df

REML criterion at convergence: 1222.3

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-2.5765 -0.4721 -0.1467  0.2953  5.6573 

Random effects:
 Groups   Name        Variance Std.Dev.
 Sport    (Intercept)  1.639   1.280   
 Residual             36.523   6.043   
Number of obs: 190, groups:  Sport, 7

Fixed effects:
            Estimate Std. Error     df t value Pr(>|t|)   
(Intercept)   3.5454     0.9349 6.0330   3.792  0.00896 **
ITTeam        0.5376     1.3904 4.9692   0.387  0.71502   
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Correlation of Fixed Effects:
       (Intr)
ITTeam -0.672

En este modelo el intercept nos mide cuanto aumenta el cortisol en los dias de competición en los deportes individuales y es 3.3253 (EE 0.94, p=0.013), pero en los de equipo, aunque el cambio es mayor (hay que añadirele 0.78), no es significativamente diferente a los individuales.

Sí que los deportes son diferentes entre sí (como vimos badminton vs Natación), sí que hay un aumento los días de competición con respecto a los de descanso, pero no hay un cambio especial entre dias de competición y descanso entre deportes de equipo e individuales.

Segmento por sexos, no vaya a ser que las mujeres vayan por un lado completamente diferente de los hombres:

lmer(CORTincDif ~ IT + (1 | Sport), data = df %>% filter(GENDER=="Male")) %>% summary()
boundary (singular) fit: see help('isSingular')
Linear mixed model fit by REML. t-tests use Satterthwaite's method [
lmerModLmerTest]
Formula: CORTincDif ~ IT + (1 | Sport)
   Data: df %>% filter(GENDER == "Male")

REML criterion at convergence: 878.4

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-2.2550 -0.4217 -0.1398  0.2337  4.9836 

Random effects:
 Groups   Name        Variance Std.Dev.
 Sport    (Intercept)  0.00    0.000   
 Residual             47.26    6.874   
Number of obs: 132, groups:  Sport, 6

Fixed effects:
             Estimate Std. Error        df t value Pr(>|t|)    
(Intercept)   3.66876    1.07358 130.00000   3.417 0.000845 ***
ITTeam       -0.08744    1.29301 130.00000  -0.068 0.946190    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Correlation of Fixed Effects:
       (Intr)
ITTeam -0.830
optimizer (nloptwrap) convergence code: 0 (OK)
boundary (singular) fit: see help('isSingular')
lmer(CORTincDif ~ IT + (1 | Sport), data = df %>% filter(GENDER=="Female")) %>% summary()
Linear mixed model fit by REML. t-tests use Satterthwaite's method [
lmerModLmerTest]
Formula: CORTincDif ~ IT + (1 | Sport)
   Data: df %>% filter(GENDER == "Female")

REML criterion at convergence: 314.9

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-1.4778 -0.6994 -0.1253  0.5597  2.7369 

Random effects:
 Groups   Name        Variance Std.Dev.
 Sport    (Intercept)  3.164   1.779   
 Residual             13.596   3.687   
Number of obs: 58, groups:  Sport, 5

Fixed effects:
            Estimate Std. Error    df t value Pr(>|t|)  
(Intercept)    3.499      1.087 3.235   3.218   0.0437 *
ITTeam         1.899      2.306 2.780   0.823   0.4750  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Correlation of Fixed Effects:
       (Intr)
ITTeam -0.472

Mirando los sexos por separado, no se ve nada diferente a lo que vimos en el global. No hay diferencias significativas entre deportes individuales y de equipo en la respuesta al cortisol entre dias de competición y descanso. Solo parece que los hombres experimentan menos cambios que las mujeres. Veamos un modelo que desglose por tipo de deporte y sexo:

lmer(CORTincDif ~ GENDER+ IT + (1 | Sport), data = df) %>% summary()
Linear mixed model fit by REML. t-tests use Satterthwaite's method [
lmerModLmerTest]
Formula: CORTincDif ~ GENDER + IT + (1 | Sport)
   Data: df

REML criterion at convergence: 1220

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-2.5660 -0.4641 -0.1521  0.3206  5.6470 

Random effects:
 Groups   Name        Variance Std.Dev.
 Sport    (Intercept)  1.562   1.250   
 Residual             36.708   6.059   
Number of obs: 190, groups:  Sport, 7

Fixed effects:
            Estimate Std. Error      df t value Pr(>|t|)   
(Intercept)   3.7917     1.0892  8.7075   3.481  0.00728 **
GENDERMale   -0.4813     1.1541 76.6288  -0.417  0.67782   
ITTeam        0.6481     1.4055  5.3767   0.461  0.66280   
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Correlation of Fixed Effects:
           (Intr) GENDER
GENDERMale -0.528       
ITTeam     -0.449 -0.210

No vemos nada diferente a lo anterior. No hay diferencias significativas entre deportes individuales y de equipo en la respuesta al cortisol entre dias de competición y descanso. Sí, el cortisol sube significativamente más los dias de competición, se observa más en las mujeres y más en los deportes de equipo, pero no significativo con respecto a los hombres y los deportes individuales respectivamente.

Visión en modo de “Slopes”, incrementos de cortisol según deportes y días de competición

Vamos a hacer un seguimiento de cada individuo y ver como varía su cortisol en los días de competición y descanso, aunque este tipo de gráficos es más adecuado para muestras pequeñas que estas muestras tan grandes y donde hay riesgo de ver más bien una maraña de líneas.

Vamos a pasar la base de datos al formato tidy

dfLong=df %>% pivot_longer(-c(ID:IMC)) %>% 
  mutate(name=str_replace(name,"^CORT_","")) %>% 
    mutate(name=str_replace(name,"^[Aa]wak_","m00_"),
           name=str_replace(name,"^30_","m30_")) %>% 
  separate(name,into=c("time","activity")) %>% 
  mutate(time=as.factor(time),activity=as.factor(activity)) %>% 
  rename(Cortisol=value)
dfLong  %>% datatable()
dfLong %>% names()
 [1] "ID"            "Cluster"       "Sport"         "IT"           
 [5] "GENDER"        "Clasificacion" "CORTinc_rest"  "CORTinc_comp" 
 [9] "CORTincDif"    "IMC"           "time"          "activity"     
[13] "Cortisol"     
tipoDia="comp"



#thisSport="Badminton"
#thisActivity="comp"
#thisGender="Male"

graficoIntra=function(thisSport,thisActivity,thisGender,...){
   ggwithinstats(
  data = dfLong %>% filter(Sport==thisSport,activity==thisActivity,GENDER==thisGender),
  x = time,
  y = Cortisol,
  type = "np",
  effsize.type = "d",
  conf.level = 0.99,
  title = str_c(thisSport,"/",thisActivity,"/",thisGender),
  package = "ggsci",
  palette = "nrc_npg"
)+  scale_y_log10()+coord_cartesian(ylim=c(1.5,40))
}

#graficoIntra(thisSport,thisActivity,thisGender)
#dfLong %>% count(IT)

dfOrden=dfLong %>% distinct(IT,Sport,GENDER,activity) %>% arrange(IT,Sport,GENDER,rev(activity)) %>% 
  transmute(IT=IT,thisSport=Sport,thisActivity=activity,thisGender=GENDER) %>% 
  mutate(grafico=pmap(.,graficoIntra)) #%>% 
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
#  slice(-c(21,22))

#dfOrden  %>% pluck("grafico")

Deportes de equipo

dfOrden %>% filter(IT=="Team") %>% pull(grafico) %>% keep(negate(is.null)) %>% gridExtra::grid.arrange(grobs=.,ncol=2)

Lo de arriba va en otro formato: y CORTISOL x: 0/30 CATEGORIAS: sEXO, cOMP/DESCANSO Medias+/EE

dfSummary1=df %>% select(Sport,Type=Clasificacion, 
                      CORT_Awak_rest, CORT_30_rest, 
                      CORT_awak_comp, CORT_30_comp) %>% 
  pivot_longer(-c(Sport,Type)) %>% 
  group_by(Sport,Type,name) %>% 
  summarise(mean=mean(value),se=sd(value)/sqrt(n()), n=n(),.groups = 'drop') %>% 
  mutate(Moment=ifelse(str_detect(name,"wak"),0,1),
         Day=ifelse(str_detect(name,"comp"),1,0)) %>% 
  mutate(Moment=ifelse(Moment==1,"30 min","Awake"),
         Moment=forcats::fct_relevel(Moment,"Awake","30 min"),
         Day=ifelse(Day==1,"Comp.","Rest")) %>% 
  select(Sport,Type,Moment,Day,everything())
  

dfSummary1
# A tibble: 28 × 8
   Sport     Type       Moment Day   name            mean    se     n
   <fct>     <fct>      <fct>  <chr> <chr>          <dbl> <dbl> <int>
 1 Swimming  Individual 30 min Comp. CORT_30_comp    8.51 0.630    12
 2 Swimming  Individual 30 min Rest  CORT_30_rest    5.14 0.577    12
 3 Swimming  Individual Awake  Rest  CORT_Awak_rest  3.74 0.441    12
 4 Swimming  Individual Awake  Comp. CORT_awak_comp  4.92 0.419    12
 5 Athletism Individual 30 min Comp. CORT_30_comp    7.93 0.533    24
 6 Athletism Individual 30 min Rest  CORT_30_rest    6.53 0.559    24
 7 Athletism Individual Awake  Rest  CORT_Awak_rest  4.74 0.423    24
 8 Athletism Individual Awake  Comp. CORT_awak_comp  4.28 0.440    24
 9 Judo      Individual 30 min Comp. CORT_30_comp    9.98 0.638    15
10 Judo      Individual 30 min Rest  CORT_30_rest    5.18 0.420    15
# ℹ 18 more rows

dfSummary2=df %>% select(GENDER,Sport,Type=Clasificacion, 
                      CORT_Awak_rest, CORT_30_rest, 
                      CORT_awak_comp, CORT_30_comp) %>% 
  pivot_longer(-c(GENDER,Sport,Type)) %>% 
  group_by(GENDER,Sport,Type,name) %>% 
  summarise(mean=mean(value),se=sd(value)/sqrt(n()), n=n(),.groups = 'drop') %>% 
  mutate(Moment=ifelse(str_detect(name,"wak"),0,1),
         Day=ifelse(str_detect(name,"comp"),1,0)) %>% 
  mutate(Moment=ifelse(Moment==1,"30 min","Awake"),
         Moment=forcats::fct_relevel(Moment,"Awake","30 min"),
         Day=ifelse(Day==1,"Comp.","Rest")) %>% 
  select(GENDER,Sport,Type,Moment,Day,everything())
  

dfSummary2
# A tibble: 44 × 9
   GENDER Sport     Type       Moment Day   name            mean    se     n
   <fct>  <fct>     <fct>      <fct>  <chr> <chr>          <dbl> <dbl> <int>
 1 Female Swimming  Individual 30 min Comp. CORT_30_comp    8.7  1.19      4
 2 Female Swimming  Individual 30 min Rest  CORT_30_rest    6.77 1.21      4
 3 Female Swimming  Individual Awake  Rest  CORT_Awak_rest  5.24 0.563     4
 4 Female Swimming  Individual Awake  Comp. CORT_awak_comp  5.83 0.696     4
 5 Female Athletism Individual 30 min Comp. CORT_30_comp    8.23 0.856    13
 6 Female Athletism Individual 30 min Rest  CORT_30_rest    7.38 0.839    13
 7 Female Athletism Individual Awake  Rest  CORT_Awak_rest  5.55 0.657    13
 8 Female Athletism Individual Awake  Comp. CORT_awak_comp  4.56 0.659    13
 9 Female Judo      Individual 30 min Comp. CORT_30_comp   10.7  0.707     7
10 Female Judo      Individual 30 min Rest  CORT_30_rest    5.00 0.503     7
# ℹ 34 more rows

Tal vez no deberían pintar nada en este gráfico los deportes donde no hay simultáneamente hombres y mujeres (curiosamente son todos deportes de equipo).

Está sería la versión desglosandolos en dos gráficos: Uno para deportes individuales (donde es posible comparar sexos), y otro para deportes de equipo (donde no es posible comparar sexos):

Deportes individuales, posible comparar géneros

Una versión

Deportes de equipo, no es posible comparar géneros

Ahora vamos a por versión equivalente, pero comparando sexos:

Esto se puede entender añadiendo a todo el mundo en general o solo añadir aquellos deportes donde haya a la vez hombres y mujeres, controlando por el deporte que practican y estudiando cuanto se desvían con respecto a la media del mismo.

El primero es más simple, pero el segundo nos permite aislarnos del deporte en concreto, aunque perdemos casos. Lo vamos ahacer de las dos formas y luego ya veremos qué es mejor contar:

Comparación por sexos sin más:

dfSummary3=df %>% select(GENDER, 
                      CORT_Awak_rest, CORT_30_rest, 
                      CORT_awak_comp, CORT_30_comp) %>% 
  pivot_longer(-c(GENDER)) %>% 
  group_by(GENDER,name) %>% 
  summarise(mean=mean(value),se=sd(value)/sqrt(n()), n=n(),.groups = 'drop') %>% 
  mutate(Moment=ifelse(str_detect(name,"wak"),0,1),
         Day=ifelse(str_detect(name,"comp"),1,0)) %>% 
  mutate(Moment=ifelse(Moment==1,"30 min","Awake"),
         Moment=forcats::fct_relevel(Moment,"Awake","30 min"),
         Day=ifelse(Day==1,"Comp.","Rest")) %>% 
  select(GENDER,Moment,Day,everything())
  

dfSummary3
# A tibble: 8 × 7
  GENDER Moment Day   name            mean    se     n
  <fct>  <fct>  <chr> <chr>          <dbl> <dbl> <int>
1 Female 30 min Comp. CORT_30_comp   11.1  0.643    58
2 Female 30 min Rest  CORT_30_rest    6.71 0.347    58
3 Female Awake  Rest  CORT_Awak_rest  5.60 0.345    58
4 Female Awake  Comp. CORT_awak_comp  5.66 0.391    58
5 Male   30 min Comp. CORT_30_comp   10.5  0.590   132
6 Male   30 min Rest  CORT_30_rest    5.77 0.225   132
7 Male   Awake  Rest  CORT_Awak_rest  5.03 0.277   132
8 Male   Awake  Comp. CORT_awak_comp  6.16 0.376   132

Comparacion por sexos, pero solo en los deportes donde haya a la vez en nuestro estudio hombres y mujeres:

dfSummary4=df %>% filter( Sport %in% c("Swimming","Athletism","Judo","Badminton")) %>%
  select(GENDER, 
                      CORT_Awak_rest, CORT_30_rest, 
                      CORT_awak_comp, CORT_30_comp) %>% 
  pivot_longer(-c(GENDER)) %>% 
  group_by(GENDER,name) %>% 
  summarise(mean=mean(value),se=sd(value)/sqrt(n()), n=n(),.groups = 'drop') %>% 
  mutate(Moment=ifelse(str_detect(name,"wak"),0,1),
         Day=ifelse(str_detect(name,"comp"),1,0)) %>% 
  mutate(Moment=ifelse(Moment==1,"30 min","Awake"),
         Moment=forcats::fct_relevel(Moment,"Awake","30 min"),
         Day=ifelse(Day==1,"Comp.","Rest")) %>% 
  select(GENDER,Moment,Day,everything())
  

dfSummary4
# A tibble: 8 × 7
  GENDER Moment Day   name            mean    se     n
  <fct>  <fct>  <chr> <chr>          <dbl> <dbl> <int>
1 Female 30 min Comp. CORT_30_comp   11.1  0.805    44
2 Female 30 min Rest  CORT_30_rest    7.33 0.393    44
3 Female Awake  Rest  CORT_Awak_rest  6.32 0.385    44
4 Female Awake  Comp. CORT_awak_comp  6.19 0.476    44
5 Male   30 min Comp. CORT_30_comp   10.8  0.817    41
6 Male   30 min Rest  CORT_30_rest    6.45 0.490    41
7 Male   Awake  Rest  CORT_Awak_rest  5.35 0.561    41
8 Male   Awake  Comp. CORT_awak_comp  6.07 0.537    41

Como en el anterior, no hay nada que diga que merezca gran cosa diferenciar por sexos. Para quitarnos las últimas dudas, vamos a hacer lo mismo que este, pero controlando por el sexo. Nos vamos a quedar con los residuos del modelo, que está en la misma escala que la variable actual, pero centrado en cero.

Comparación de hombres y mujeres, controlando por deporte

df2= df %>% filter( Sport %in% c("Swimming","Athletism","Judo","Badminton")) %>% 
    select(ID,GENDER, Sport, 
                      CORT_Awak_rest, CORT_30_rest, 
                      CORT_awak_comp, CORT_30_comp) %>% 
  pivot_longer(-c(ID,GENDER,Sport)) %>%  
  mutate(Moment=ifelse(str_detect(name,"wak"),0,1),
         Day=ifelse(str_detect(name,"comp"),1,0)) %>% 
  mutate(Moment=ifelse(Moment==1,"30 min","Awake"),
         Moment=forcats::fct_relevel(Moment,"Awake","30 min"),
         Day=ifelse(Day==1,"Comp.","Rest")) %>% select(ID,GENDER,Sport,Moment,Day,value)
df2
# A tibble: 340 × 6
      ID GENDER Sport    Moment Day   value
   <int> <fct>  <fct>    <fct>  <chr> <dbl>
 1    63 Female Swimming Awake  Rest   5.52
 2    63 Female Swimming 30 min Rest   6.46
 3    63 Female Swimming Awake  Comp.  4.26
 4    63 Female Swimming 30 min Comp.  7.12
 5    64 Female Swimming Awake  Rest   6.72
 6    64 Female Swimming 30 min Rest   6.79
 7    64 Female Swimming Awake  Comp.  7.02
 8    64 Female Swimming 30 min Comp.  9.12
 9    65 Female Swimming Awake  Rest   4.37
10    65 Female Swimming 30 min Rest   3.95
# ℹ 330 more rows
modelo_mixto=lme4::lmer(value ~  + (1|ID) +(1|Sport) , data=df2)




df2[["Residual"]]=resid(modelo_mixto)
df2
# A tibble: 340 × 7
      ID GENDER Sport    Moment Day   value Residual
   <int> <fct>  <fct>    <fct>  <chr> <dbl>    <dbl>
 1    63 Female Swimming Awake  Rest   5.52   -0.242
 2    63 Female Swimming 30 min Rest   6.46    0.698
 3    63 Female Swimming Awake  Comp.  4.26   -1.50 
 4    63 Female Swimming 30 min Comp.  7.12    1.36 
 5    64 Female Swimming Awake  Rest   6.72    0.313
 6    64 Female Swimming 30 min Rest   6.79    0.383
 7    64 Female Swimming Awake  Comp.  7.02    0.613
 8    64 Female Swimming 30 min Comp.  9.12    2.71 
 9    65 Female Swimming Awake  Rest   4.37   -1.25 
10    65 Female Swimming 30 min Rest   3.95   -1.67 
# ℹ 330 more rows
dfSummary5=df2 %>% group_by(GENDER,Moment,Day) %>% 
  summarise(mean=mean(Residual),se=sd(Residual)/sqrt(n()), n=n(),.groups = 'drop')


dfSummary5
# A tibble: 8 × 6
  GENDER Moment Day     mean    se     n
  <fct>  <fct>  <chr>  <dbl> <dbl> <int>
1 Female Awake  Comp. -1.52  0.330    44
2 Female Awake  Rest  -1.39  0.245    44
3 Female 30 min Comp.  3.43  0.604    44
4 Female 30 min Rest  -0.383 0.341    44
5 Male   Awake  Comp. -1.14  0.336    41
6 Male   Awake  Rest  -1.86  0.323    41
7 Male   30 min Comp.  3.62  0.557    41
8 Male   30 min Rest  -0.765 0.347    41

Aquí el eje Y representa lo de siempre pero de forma que 0 es el valor esperado para cada deporte para un dia aleatorio (sea de competición o descanso) y una persona aleatoria (hombre o mujer). Si el valor es positivo, es que el valor observado es mayor que el esperado, y si es negativo, es que es menor. Si acaso diría que parece que un hombre que practique undeporte parece despertar los dias de descanso con un nivel de cortisol algo más bajo que su equivalente del mismo deporte mujer. Pero tampoco es que llame mucho la atención y también podrían decir que hemos mirado mucho para que nos salga algo.

Por mí solo destacaría que al estudiar deportes donde hay hombres y mujeres, no parece que el sexo, tras controlar por deporte valga mucho la pena. En deportista de este nivel lo que importa es la competición.

Cosas antiguas pero que no borramos

Deportes individuales

dfOrden %>% filter(IT=="Individual") %>% pull(grafico) %>% keep(negate(is.null)) %>%  gridExtra::grid.arrange(grobs=.,ncol=2)

Calculos anteriores a partir de aquí

Vamos a representar gráficamente los datos en el formato tidy:

grafico=dfLong %>% ggplot(aes(x=time,y=Cortisol,fill=activity,color=activity))+
  geom_jitter(width=0.25,alpha=0.5)+
  geom_boxplot(alpha=0.25)+
  facet_wrap(GENDER~Clasificacion+Sport,nrow=2)

grafico

Vamos a poner la escala del cortisol en logaritmica para evitar falta de normalidad

grafico+ scale_y_log10()

Cuestiones previas para la tabla 1

Es interesante antes de ir a por los objetivos del estudio chequear si los valores al despertar los dias de competición son como los dias normales. Si lo fuesen podríamos plantearnos tomar como valores de referencia (“00”) la media de los dos. SI no lo fuesen deberíamos tomar como valores de referencia los del despertar de cada día. Haremos los dos análisis y ya veremos cual nos cuenta una historia más interesante.

dfPar= dfLong %>% filter(time=="m00") %>% pivot_wider(names_from="activity",values_from="Cortisol") %>% 
  mutate(dif=comp-rest)
dfPar %>% head() %>% knitr::kable()
ID Cluster Sport IT GENDER Clasificacion CORTinc_rest CORTinc_comp CORTincDif IMC time rest comp dif
1 1_NA Hockey Team Male Team 0.40 4.11 3.71 20.08 m00 4.00 5.59 1.59
2 1_NA Hockey Team Male Team 1.13 4.28 3.15 24.55 m00 2.32 2.50 0.18
3 1_NA Hockey Team Male Team 2.43 4.42 1.99 22.20 m00 2.90 4.23 1.33
4 1_NA Hockey Team Male Team 2.17 6.76 4.59 23.21 m00 4.30 4.74 0.44
5 1_NA Hockey Team Male Team 0.57 6.57 6.00 21.89 m00 4.80 2.97 -1.83
6 1_NA Hockey Team Male Team 2.93 8.56 5.63 24.95 m00 2.50 3.45 0.95
dfPar %>% ggplot(aes(y=dif,x=GENDER,color=IT))+
  geom_jitter(width=0.25,alpha=0.5)+
  geom_boxplot(alpha=0.25)+
  geom_hline(yintercept = 0)+
 facet_wrap(~Clasificacion+Sport,nrow =2) 

Aparentemente se levantan bastante igual sea cual sea el deporte y sexo, y donde aparece una pequeña diferencia la submuestra es pequeña. Sería posible si quisiésemos controlar cierta variabilidad tomar como valor de referencia la media de los dos días. Al menos sabemos que la posibilidad existe.

Cambios entre tiempo m00 y m30mm (diferencias), entre dias de competición y de descanso

dfPar= dfLong %>% mutate(name=str_c(time,"_",activity)) %>%
  select(-activity,-time) %>% 
  pivot_wider(names_from="name",values_from="Cortisol") %>% 
  mutate(dif_comp=m30_comp-m00_comp,
         dif_rest=m30_rest-m00_rest, 
         dif_comprest=dif_comp-dif_rest)
dfPar %>% head() %>% knitr::kable()
ID Cluster Sport IT GENDER Clasificacion CORTinc_rest CORTinc_comp CORTincDif IMC m00_rest m30_rest m00_comp m30_comp dif_comp dif_rest dif_comprest
1 1_NA Hockey Team Male Team 0.40 4.11 3.71 20.08 4.00 4.40 5.59 9.70 4.11 0.40 3.71
2 1_NA Hockey Team Male Team 1.13 4.28 3.15 24.55 2.32 3.45 2.50 6.78 4.28 1.13 3.15
3 1_NA Hockey Team Male Team 2.43 4.42 1.99 22.20 2.90 5.33 4.23 8.65 4.42 2.43 1.99
4 1_NA Hockey Team Male Team 2.17 6.76 4.59 23.21 4.30 6.47 4.74 11.50 6.76 2.17 4.59
5 1_NA Hockey Team Male Team 0.57 6.57 6.00 21.89 4.80 5.37 2.97 9.54 6.57 0.57 6.00
6 1_NA Hockey Team Male Team 2.93 8.56 5.63 24.95 2.50 5.43 3.45 12.01 8.56 2.93 5.63

En formato tidy, estas son las diferencias que podemos estudiar:

dfLongDif=dfPar %>% select(ID:IMC,starts_with("dif")) %>% pivot_longer(-c(ID:IMC)) %>% 
  mutate(name=factor(name,levels=c("dif_rest","dif_comp","dif_comprest"),labels=c("Rest","Competition","Competing - Rest")))
dfLongDif %>% head() %>% knitr::kable()
ID Cluster Sport IT GENDER Clasificacion CORTinc_rest CORTinc_comp CORTincDif IMC name value
1 1_NA Hockey Team Male Team 0.40 4.11 3.71 20.08 Competition 4.11
1 1_NA Hockey Team Male Team 0.40 4.11 3.71 20.08 Rest 0.40
1 1_NA Hockey Team Male Team 0.40 4.11 3.71 20.08 Competing - Rest 3.71
2 1_NA Hockey Team Male Team 1.13 4.28 3.15 24.55 Competition 4.28
2 1_NA Hockey Team Male Team 1.13 4.28 3.15 24.55 Rest 1.13
2 1_NA Hockey Team Male Team 1.13 4.28 3.15 24.55 Competing - Rest 3.15
dfDifAgr0=dfLongDif %>% group_by(Clasificacion,Sport,IT,name) %>% 
  summarise(n=length(value),
            media=mean(value),
            dt=sd(value),
            ee=dt/n,
            ic1=media-qt(0.975,df=n-1)*ee,
            ic2=media+qt(0.975,df=n-1)*ee)%>% ungroup()
`summarise()` has grouped output by 'Clasificacion', 'Sport', 'IT'. You can
override using the `.groups` argument.
dfReferencia1=dfDifAgr0 %>% select(Sport,name,media) %>% filter(name %in% c("Rest")) %>%
  select(-name) %>% 
  group_by(Sport) %>% 
  summarise(vReferencia1=mean(media,na.rm=T)) %>% 
  mutate(vReferencia1=as.integer(ordered(vReferencia1))) %>% 
  arrange(vReferencia1)

dfReferencia2=dfDifAgr0 %>% select(Sport,name,media) %>% filter(name %in% c("Competition")) %>%
  select(-name) %>% 
  group_by(Sport) %>% 
  summarise(vReferencia2=mean(media,na.rm=T)) %>% 
  mutate(vReferencia2=as.integer(ordered(vReferencia2))) %>% 
  arrange(vReferencia2)

dfReferencia3=dfDifAgr0 %>% select(Sport,name,media) %>% filter(name %in% c("Comp-Rest")) %>%
  select(-name) %>% 
  group_by(Sport) %>% 
  summarise(vReferencia3=mean(media,na.rm=T)) %>% 
  mutate(vReferencia3=as.integer(ordered(vReferencia3))) %>% 
  arrange(vReferencia3)


dfDifAgr=dfDifAgr0%>% left_join(dfReferencia1) %>% left_join(dfReferencia2) %>% left_join(dfReferencia3)
Joining with `by = join_by(Sport)`
Joining with `by = join_by(Sport)`
Joining with `by = join_by(Sport)`
dfDifAgr$Sport1=dfDifAgr$Sport %>% forcats::fct_relevel(as.character(dfReferencia1$Sport))
dfDifAgr$Sport2=dfDifAgr$Sport %>% forcats::fct_relevel(as.character(dfReferencia2$Sport))
dfDifAgr$Sport3=dfDifAgr$Sport %>% forcats::fct_relevel(as.character(dfReferencia3$Sport))
dfDifAgr%>% mutate_if(is_double,round %>% partial(digits=3) ) %>% knitr::kable()
Clasificacion Sport IT name n media dt ee ic1 ic2 vReferencia1 vReferencia2 vReferencia3 Sport1 Sport2 Sport3
Individual Swimming Individual Rest 12 1.399 2.023 0.169 1.028 1.770 3 1 NA Swimming Swimming Swimming
Individual Swimming Individual Competition 12 3.592 2.298 0.192 3.170 4.013 3 1 NA Swimming Swimming Swimming
Individual Swimming Individual Competing - Rest 12 2.193 2.462 0.205 1.741 2.644 3 1 NA Swimming Swimming Swimming
Individual Athletism Individual Rest 24 1.789 1.438 0.060 1.665 1.913 7 2 NA Athletism Athletism Athletism
Individual Athletism Individual Competition 24 3.647 1.941 0.081 3.480 3.814 7 2 NA Athletism Athletism Athletism
Individual Athletism Individual Competing - Rest 24 1.858 2.800 0.117 1.617 2.100 7 2 NA Athletism Athletism Athletism
Individual Judo Individual Rest 15 1.461 1.103 0.074 1.303 1.618 5 4 NA Judo Judo Judo
Individual Judo Individual Competition 15 4.526 2.082 0.139 4.228 4.824 5 4 NA Judo Judo Judo
Individual Judo Individual Competing - Rest 15 3.065 2.145 0.143 2.759 3.372 5 4 NA Judo Judo Judo
Individual Badminton Individual Rest 34 0.223 2.416 0.071 0.079 0.368 1 6 NA Badminton Badminton Badminton
Individual Badminton Individual Competition 34 6.321 3.961 0.116 6.084 6.558 1 6 NA Badminton Badminton Badminton
Individual Badminton Individual Competing - Rest 34 6.097 4.433 0.130 5.832 6.362 1 6 NA Badminton Badminton Badminton
Team Football Team Rest 77 0.355 2.877 0.037 0.280 0.429 2 3 NA Football Football Football
Team Football Team Competition 77 3.880 7.535 0.098 3.685 4.075 2 3 NA Football Football Football
Team Football Team Competing - Rest 77 3.525 8.463 0.110 3.306 3.744 2 3 NA Football Football Football
Team Hockey Team Rest 14 1.775 1.262 0.090 1.580 1.970 6 5 NA Hockey Hockey Hockey
Team Hockey Team Competition 14 5.664 2.286 0.163 5.312 6.017 6 5 NA Hockey Hockey Hockey
Team Hockey Team Competing - Rest 14 3.889 1.992 0.142 3.582 4.197 6 5 NA Hockey Hockey Hockey
Team Handball Team Rest 14 1.439 1.111 0.079 1.268 1.611 4 7 NA Handball Handball Handball
Team Handball Team Competition 14 6.837 3.558 0.254 6.288 7.386 4 7 NA Handball Handball Handball
Team Handball Team Competing - Rest 14 5.398 4.418 0.316 4.716 6.080 4 7 NA Handball Handball Handball
dfLongDif %>% ggplot(aes(y=value,x=name,color=name,fill=name))+
geom_jitter(width=0.25,alpha=0.15)+
  geom_boxplot(alpha=0.25)+
  geom_hline(yintercept = 0)+
  facet_grid(rows=vars(IT),cols=vars(Sport))  +
   theme(axis.text.x = element_text(angle = 90, vjust = 1, hjust=1),legend.title=element_blank(),legend.position="top")

dfDifAgr0=dfLongDif %>% group_by(Clasificacion,Sport,IT,name) %>% 
  summarise(n=length(value),
            media=mean(value),
            dt=sd(value),
            ee=dt/n,
            ic1=media-qt(0.975,df=n-1)*ee,
            ic2=media+qt(0.975,df=n-1)*ee)%>% ungroup()
`summarise()` has grouped output by 'Clasificacion', 'Sport', 'IT'. You can
override using the `.groups` argument.
dfReferencia1=dfDifAgr0 %>% select(Sport,name,media) %>% filter(name %in% c("Rest")) %>%
  select(-name) %>% 
  group_by(Sport) %>% 
  summarise(vReferencia1=mean(media,na.rm=T)) %>% 
  mutate(vReferencia1=as.integer(ordered(vReferencia1))) %>% 
  arrange(vReferencia1)

dfReferencia2=dfDifAgr0 %>% select(Sport,name,media) %>% filter(name %in% c("Competition")) %>%
  select(-name) %>% 
  group_by(Sport) %>% 
  summarise(vReferencia2=mean(media,na.rm=T)) %>% 
  mutate(vReferencia2=as.integer(ordered(vReferencia2))) %>% 
  arrange(vReferencia2)

dfReferencia3=dfDifAgr0 %>% select(Sport,name,media) %>% filter(!name %in% c("Competition", "Rest")) %>%
  select(-name) %>% 
  group_by(Sport) %>% 
  summarise(vReferencia3=mean(media,na.rm=T)) %>% 
  mutate(vReferencia3=as.integer(ordered(vReferencia3))) %>% 
  arrange(vReferencia3)


dfDifAgr=dfDifAgr0%>% left_join(dfReferencia1) %>% left_join(dfReferencia2) %>% left_join(dfReferencia3)
Joining with `by = join_by(Sport)`
Joining with `by = join_by(Sport)`
Joining with `by = join_by(Sport)`
dfDifAgr$Sport1=dfDifAgr$Sport %>% forcats::fct_relevel(as.character(dfReferencia1$Sport))
dfDifAgr$Sport2=dfDifAgr$Sport %>% forcats::fct_relevel(as.character(dfReferencia2$Sport))
dfDifAgr$Sport3=dfDifAgr$Sport %>% forcats::fct_relevel(as.character(dfReferencia3$Sport))

dfLongDif=dfLongDif%>% left_join(dfReferencia1) %>% left_join(dfReferencia2) %>% left_join(dfReferencia3)
Joining with `by = join_by(Sport)`
Joining with `by = join_by(Sport)`
Joining with `by = join_by(Sport)`
dfLongDif$Sport1=dfLongDif$Sport %>% forcats::fct_relevel(as.character(dfReferencia1$Sport))
dfLongDif$Sport2=dfLongDif$Sport %>% forcats::fct_relevel(as.character(dfReferencia2$Sport))
dfLongDif$Sport3=dfLongDif$Sport %>% forcats::fct_relevel(as.character(dfReferencia3$Sport))

dfDifAgr%>% mutate_if(is_double,round %>% partial(digits=3) ) %>% knitr::kable()
Clasificacion Sport IT name n media dt ee ic1 ic2 vReferencia1 vReferencia2 vReferencia3 Sport1 Sport2 Sport3
Individual Swimming Individual Rest 12 1.399 2.023 0.169 1.028 1.770 3 1 2 Swimming Swimming Swimming
Individual Swimming Individual Competition 12 3.592 2.298 0.192 3.170 4.013 3 1 2 Swimming Swimming Swimming
Individual Swimming Individual Competing - Rest 12 2.193 2.462 0.205 1.741 2.644 3 1 2 Swimming Swimming Swimming
Individual Athletism Individual Rest 24 1.789 1.438 0.060 1.665 1.913 7 2 1 Athletism Athletism Athletism
Individual Athletism Individual Competition 24 3.647 1.941 0.081 3.480 3.814 7 2 1 Athletism Athletism Athletism
Individual Athletism Individual Competing - Rest 24 1.858 2.800 0.117 1.617 2.100 7 2 1 Athletism Athletism Athletism
Individual Judo Individual Rest 15 1.461 1.103 0.074 1.303 1.618 5 4 3 Judo Judo Judo
Individual Judo Individual Competition 15 4.526 2.082 0.139 4.228 4.824 5 4 3 Judo Judo Judo
Individual Judo Individual Competing - Rest 15 3.065 2.145 0.143 2.759 3.372 5 4 3 Judo Judo Judo
Individual Badminton Individual Rest 34 0.223 2.416 0.071 0.079 0.368 1 6 7 Badminton Badminton Badminton
Individual Badminton Individual Competition 34 6.321 3.961 0.116 6.084 6.558 1 6 7 Badminton Badminton Badminton
Individual Badminton Individual Competing - Rest 34 6.097 4.433 0.130 5.832 6.362 1 6 7 Badminton Badminton Badminton
Team Football Team Rest 77 0.355 2.877 0.037 0.280 0.429 2 3 4 Football Football Football
Team Football Team Competition 77 3.880 7.535 0.098 3.685 4.075 2 3 4 Football Football Football
Team Football Team Competing - Rest 77 3.525 8.463 0.110 3.306 3.744 2 3 4 Football Football Football
Team Hockey Team Rest 14 1.775 1.262 0.090 1.580 1.970 6 5 5 Hockey Hockey Hockey
Team Hockey Team Competition 14 5.664 2.286 0.163 5.312 6.017 6 5 5 Hockey Hockey Hockey
Team Hockey Team Competing - Rest 14 3.889 1.992 0.142 3.582 4.197 6 5 5 Hockey Hockey Hockey
Team Handball Team Rest 14 1.439 1.111 0.079 1.268 1.611 4 7 6 Handball Handball Handball
Team Handball Team Competition 14 6.837 3.558 0.254 6.288 7.386 4 7 6 Handball Handball Handball
Team Handball Team Competing - Rest 14 5.398 4.418 0.316 4.716 6.080 4 7 6 Handball Handball Handball
dfLongDif %>% ggplot(aes(y=value,x=Sport2,color=IT,fill=IT))+
geom_jitter(width=0.25,alpha=0.15)+
  geom_boxplot(alpha=0.25)+
  geom_hline(yintercept = 0)+
  facet_wrap(~name,ncol=1)+
   theme(axis.text.x = element_text(angle = 90, vjust = 1, hjust=1),legend.position="top",legend.title=element_blank())

Aparentemente la variabilidad que existe intradia (m00 a m30) es muy pequeña los dias de descanso. En general se produce un aumento de Cortisol desde m00 a m30 los dias de competición. Si comparamos el aumento desde m00 a m30 entre los dias de competición y dias de descanso, se suele ver un aumento.

Se observa una heterogeneidad relacionada con el tipo de deporte. Aparentemente vamos a tener que separar los resultados por ellos. En los deportes donde compiten hombres y mujeres no parece que haya gran diferencias por sexos. Posiblemente tengamos derecho a no considerar el sexo, o si acaso considerarlo como una variable de control.

dfDifAgr=dfLongDif %>% 
  group_by(Sport2,IT,Clasificacion,name) %>% 
  summarise(n=length(value),
            media=mean(value),
            dt=sd(value),
            ee=dt/n,
            ic1=media-qt(0.975,df=n-1)*ee,
            ic2=media+qt(0.975,df=n-1)*ee
            ) %>% ungroup()
`summarise()` has grouped output by 'Sport2', 'IT', 'Clasificacion'. You can
override using the `.groups` argument.
dfDifAgr %>% mutate_if(is_double,round %>% partial(digits=3) )%>%  knitr::kable()
Sport2 IT Clasificacion name n media dt ee ic1 ic2
Swimming Individual Individual Rest 12 1.399 2.023 0.169 1.028 1.770
Swimming Individual Individual Competition 12 3.592 2.298 0.192 3.170 4.013
Swimming Individual Individual Competing - Rest 12 2.193 2.462 0.205 1.741 2.644
Athletism Individual Individual Rest 24 1.789 1.438 0.060 1.665 1.913
Athletism Individual Individual Competition 24 3.647 1.941 0.081 3.480 3.814
Athletism Individual Individual Competing - Rest 24 1.858 2.800 0.117 1.617 2.100
Football Team Team Rest 77 0.355 2.877 0.037 0.280 0.429
Football Team Team Competition 77 3.880 7.535 0.098 3.685 4.075
Football Team Team Competing - Rest 77 3.525 8.463 0.110 3.306 3.744
Judo Individual Individual Rest 15 1.461 1.103 0.074 1.303 1.618
Judo Individual Individual Competition 15 4.526 2.082 0.139 4.228 4.824
Judo Individual Individual Competing - Rest 15 3.065 2.145 0.143 2.759 3.372
Hockey Team Team Rest 14 1.775 1.262 0.090 1.580 1.970
Hockey Team Team Competition 14 5.664 2.286 0.163 5.312 6.017
Hockey Team Team Competing - Rest 14 3.889 1.992 0.142 3.582 4.197
Badminton Individual Individual Rest 34 0.223 2.416 0.071 0.079 0.368
Badminton Individual Individual Competition 34 6.321 3.961 0.116 6.084 6.558
Badminton Individual Individual Competing - Rest 34 6.097 4.433 0.130 5.832 6.362
Handball Team Team Rest 14 1.439 1.111 0.079 1.268 1.611
Handball Team Team Competition 14 6.837 3.558 0.254 6.288 7.386
Handball Team Team Competing - Rest 14 5.398 4.418 0.316 4.716 6.080
dfDifAgr   %>% ggplot(aes(x=Sport2,y=media,color=name))+
  geom_errorbar(aes(ymin=ic1,ymax=ic2),position = "dodge2",width=0.25)+
#  geom_col(position = "dodge2",fill="white",alpha=0.1,color="#00000033") +
    geom_point( position = position_dodge(width=0.25)) +
   geom_hline(yintercept = 0,lty=2,alpha=0.5)+
   theme(axis.text.x = element_text(angle = 90, vjust = 1, hjust=1),legend.position = "top",legend.title=element_blank())

dfDifAgr   %>% ggplot(aes(x=Sport2,y=media,color=name))+
  geom_errorbar(aes(ymin=ic1,ymax=ic2),position = "dodge2",width=0.25)+
#  geom_col(position = "dodge2",fill="white",alpha=0.1,color="#00000033") +
    geom_point( position = position_dodge(width=0.25)) +
   geom_hline(yintercept = 0,lty=2,alpha=0.5)+
  facet_wrap(~name,ncol=1)+
   theme(axis.text.x = element_text(angle = 90, vjust = 1, hjust=1),legend.position = "none")