#corr <- round(cor(dfBAdif %>% select(-CODE) %>% rename(SODIO=`NA`)),1)
#ggcorrplot(corr, hc.order = TRUE, type = "lower",
# lab = TRUE)
Hay tres Ʃpocas especialmente interesantes:
E1 => 20/9
E2 => 25/1
E3 => Hasta final
Se quieren comparar los valores principalmente hormonas en las tres Ʃpocas. ANOVA de medidas repetidas
Idem para lesiones de tipo MUSCULAR.
Idem para mecanismos de la lesión (SOBRECARGA, etc,ā¦)
Como las lesiones aparecen en fechas concretas, vamos en primer lugar a convertir la base de datos con datos de cortisol a un formato tidy donde la fecha de la medida de Cortisol sea muy aparente.
Formato Actual
dfC %>% select(1:7) %>% head()
## # A tibble: 6 Ć 7
## CODE C_basal_temporada C_pre_18_8 C_post_18_8 C_pre_26_8 C_pre_30_8 C_pre_7_9
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 COD1 4.8 3.99 2.88 3.23 4.3 5.6
## 2 COD10 3.36 3.61 3.08 2.87 5.72 5.69
## 3 COD11 7 4.32 3.96 2.87 7.38 4.86
## 4 COD12 11.9 6.37 4.97 4.63 5.95 9.16
## 5 COD13 8.4 3.21 3.26 3.18 8.14 6.32
## 6 COD16 5.8 3.92 3 3.15 5.8 5.79
dfClong=dfC %>% rename(C_pre_12_8=C_basal_temporada) %>% select(CODE,contains("_pre_")) %>% pivot_longer(-CODE) %>%
mutate(mesDia=str_replace(name,"C_pre_([0-9]+)_([0-9]+)","\\2-\\1")) %>%
separate(col = "mesDia",into = c("mes","dia"),sep = "-") %>%
mutate(mes=as.integer(mes),dia=as.integer(dia),ano=as.integer(ifelse(mes>=7,2022,2023))) %>%
mutate(Fecha=make_date(month = mes,day = dia, year=ano)) %>%
select(CODE,Fecha,Cortisol=value) %>% filter(complete.cases(.))
dfClong %>% head()
## # A tibble: 6 Ć 3
## CODE Fecha Cortisol
## <chr> <date> <dbl>
## 1 COD1 2022-08-12 4.8
## 2 COD1 2022-08-18 3.99
## 3 COD1 2022-08-26 3.23
## 4 COD1 2022-08-30 4.3
## 5 COD1 2022-09-07 5.6
## 6 COD1 2022-09-15 6.29
dfTlong=dfT %>% rename(T_pre_12_8=T_basal_temporada) %>% select(CODE,contains("_pre_")) %>% pivot_longer(-CODE) %>%
mutate(mesDia=str_replace(name,"T_pre_([0-9]+)_([0-9]+)","\\2-\\1")) %>%
separate(col = "mesDia",into = c("mes","dia"),sep = "-") %>%
mutate(mes=as.integer(mes),dia=as.integer(dia),ano=as.integer(ifelse(mes>=7,2022,2023))) %>%
mutate(Fecha=make_date(month = mes,day = dia, year=ano)) %>%
select(CODE,Fecha,Testosterona=value) %>% filter(complete.cases(.))
dfTlong %>% head()
## # A tibble: 6 Ć 3
## CODE Fecha Testosterona
## <chr> <date> <dbl>
## 1 COD1 2022-08-12 298
## 2 COD1 2022-08-18 254
## 3 COD1 2022-08-26 277
## 4 COD1 2022-08-30 287
## 5 COD1 2022-09-07 267
## 6 COD1 2022-09-15 250
Una vez tenemos los datos en formato tidy, los exploramos visualmente, teniendo en cuenta que hay tres ĆPOCAS:
fechasCorte=ymd(c("2022-07-01","2022-09-20","2023-01-25","2023-07-01"))
#dfClong$Epoca=str_c("E",dfClong$Fecha %>% cut(breaks=fechasCorte,labels=FALSE,right=T,left=T))
#dfTlong$Epoca=str_c("E",dfTlong$Fecha %>% cut(breaks=fechasCorte,labels=FALSE,right=T,left=T))
ultimaFecha=max(dfClong$Fecha,dfTlong$Fecha)+20
dfClong %>% ggplot(aes(x=Fecha,y=Cortisol,color=CODE)) +
geom_line()+
geom_vline(data=data.frame(xintercept=fechasCorte),aes(xintercept=xintercept), linetype="dashed", color = "red")+
scale_x_date(date_breaks = "1 week", date_labels = "%Y-%m-%d") +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
guides(color = guide_legend(ncol = 15))+
theme(legend.position = "top")
dfTlong %>% ggplot(aes(x=Fecha,y=Testosterona,color=CODE)) +
geom_line()+
geom_vline(data=data.frame(xintercept=fechasCorte),aes(xintercept=xintercept), linetype="dashed", color = "red")+
scale_x_date(date_breaks = "1 week", date_labels = "%Y-%m-%d") +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
guides(color = guide_legend(ncol = 15))+
theme(legend.position = "top")
Ahora vamos a tomar nota de las lesiones y vamos a emparejarlos con los valores de cortisol mĆ”s cercanos. AquĆ habrĆa varias posibilidades, pero comencemos por ahĆ.
dfInj$RECUPARATED[is.na(dfInj$RECUPARATED)]=ultimaFecha
dfInjCortisol=dfInj %>% mutate(Cortisol=pmap_dbl(.,function(CODE,DATE,...){
Codigo=CODE
solucion=dfClong %>% filter(CODE==Codigo) %>% filter(Fecha<=DATE) %>% select(Cortisol) %>% pull() %>% last()
if(is.na(solucion)){
solucion=dfClong %>% filter(CODE==Codigo) %>% filter(Fecha>=DATE) %>% select(Cortisol) %>% pull() %>% first()
}
solucion
}
)) %>% select(CODE,Cortisol,everything())
dfInjTestosterona=dfInj %>% mutate(Testosterona=pmap_dbl(.,function(CODE,DATE,...){
Codigo=CODE
solucion=dfTlong %>% filter(CODE==Codigo) %>% filter(Fecha<=DATE) %>% select(Testosterona) %>% pull() %>% last()
if(is.na(solucion)){
solucion=dfTlong %>% filter(CODE==Codigo) %>% filter(Fecha>=DATE) %>% select(Testosterona) %>% pull() %>% first()
}
solucion
}
)) %>% select(CODE,Testosterona,everything())
dfCortisolDuranteLesion=dfClong %>% left_join(dfInj,by = "CODE",multiple="all") %>%
filter(!is.na(DATE)) %>%
filter(as.numeric(difftime(Fecha,DATE,units="days"))>=-7,
as.numeric(difftime(Fecha,RECUPARATED,units="days"))<=7) %>%
select(CODE,DATE,RECUPARATED,Fecha,everything()) %>% arrange(CODE,DATE,Fecha) %>%
group_by(CODE,Fecha) %>% summarise_all(first) %>%
ungroup() %>%
mutate(idLesion=as.integer(as.factor(str_c(CODE,"-",DATE))))
dfTestosteronaDuranteLesion=dfTlong %>% left_join(dfInj,by = "CODE",multiple="all") %>%
filter(!is.na(DATE)) %>%
filter(as.numeric(difftime(Fecha,DATE,units="days"))>=-7,
as.numeric(difftime(Fecha,RECUPARATED,units="days"))<=7) %>%
select(CODE,DATE,RECUPARATED,Fecha,everything()) %>% arrange(CODE,DATE,Fecha) %>%
group_by(CODE,Fecha) %>% summarise_all(first) %>%
ungroup() %>%
mutate(idLesion=as.integer(as.factor(str_c(CODE,"-",DATE))))
Representamos lesiones y cortisol
# dfCortisolLesion=dfClong %>%
# left_join(dfCortisolDuranteLesion) %>%
# mutate(Lesionado=!is.na(DATE) & DATE<=Fecha)
#dfCortisolLesion %>% filter(CODE=="COD4")
dfCortisolLesionAltPre=dfClong %>% bind_rows(dfInjCortisol %>% mutate(Fecha=DATE)) %>%
arrange(CODE,Fecha,DATE) %>% group_by(CODE,Fecha) %>% summarise_all(first)%>% ungroup()
dfCortisolDuranteLesionAlt=dfCortisolLesionAltPre %>% select(CODE,Fecha,Cortisol) %>% left_join(dfInj,by = "CODE",multiple="all") %>%
filter(!is.na(DATE)) %>%
filter(as.numeric(difftime(Fecha,DATE,units="days"))>=-7*0,
as.numeric(difftime(Fecha,RECUPARATED,units="days"))<=7) %>%
select(CODE,DATE,RECUPARATED,Fecha,everything()) %>% arrange(CODE,DATE,Fecha) %>%
group_by(CODE,Fecha) %>% summarise_all(first) %>%
ungroup() %>%
mutate(idLesion=as.integer(as.factor(str_c(CODE,"-",DATE))))
dfCortisolLesion=dfCortisolDuranteLesionAlt %>% bind_rows(dfCortisolLesionAltPre) %>%
arrange(CODE,Fecha,DATE) %>% group_by(CODE,Fecha) %>% summarise_all(first) %>% ungroup() %>%
mutate(Lesionado=(!is.na(DATE)))
dfTestosteronaLesionAltPre=dfTlong %>% bind_rows(dfInjTestosterona %>% mutate(Fecha=DATE)) %>%
arrange(CODE,Fecha,DATE) %>% group_by(CODE,Fecha) %>% summarise_all(first)%>% ungroup()
dTestosteronaDuranteLesionAlt=dfTestosteronaLesionAltPre %>% select(CODE,Fecha,Testosterona) %>% left_join(dfInj,by = "CODE",multiple="all") %>%
filter(!is.na(DATE)) %>%
filter(as.numeric(difftime(Fecha,DATE,units="days"))>=-7*0,
as.numeric(difftime(Fecha,RECUPARATED,units="days"))<=7) %>%
select(CODE,DATE,RECUPARATED,Fecha,everything()) %>% arrange(CODE,DATE,Fecha) %>%
group_by(CODE,Fecha) %>% summarise_all(first) %>%
ungroup() %>%
mutate(idLesion=as.integer(as.factor(str_c(CODE,"-",DATE))))
dfTestosteronaLesion=dTestosteronaDuranteLesionAlt %>% bind_rows(dfTestosteronaLesionAltPre) %>%
arrange(CODE,Fecha,DATE) %>% group_by(CODE,Fecha) %>% summarise_all(first) %>% ungroup() %>%
mutate(Lesionado=(!is.na(DATE)))
dfGPS_C=dfGPS %>% select(CODE,Fecha,Sesion,Puesto)
dfGPS_N=dfGPS %>% select(-Sesion,-Puesto)
dfGPS_Nlong=dfGPS_N %>% pivot_longer(-c(CODE,Fecha,Repeticion)) %>%
group_by(name) %>% mutate(Z=as.numeric(scale(value))) %>%
group_by(name,CODE) %>%
mutate(ZP=as.numeric(scale(value))) %>%
ungroup()
Este es el historial de todas las lesiones registradas segĆŗn que la variabilidad en Cortisol (alta o baja):
dfCortisolLesion %>% ggplot(aes(x=Fecha,y=Cortisol)) +
geom_line(aes(color=CODE),alpha=0.5)+
geom_vline(data=data.frame(xintercept=fechasCorte),aes(xintercept=xintercept), linetype="dashed", color = "red")+
geom_line(data=dfCortisolDuranteLesion,aes(group=as.factor(idLesion),color=CODE),linewidth=2,alpha=0.5)+
geom_point(data=dfCortisolDuranteLesion,size=3,alpha=0.5)+
scale_x_date(date_breaks = "1 week", date_labels = "%Y-%m-%d") +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
guides(color = guide_legend(ncol = 15))+
theme(legend.position = "top")
dfTestosteronaLesion %>% ggplot(aes(x=Fecha,y=Testosterona)) +
geom_line(aes(color=CODE),alpha=0.5)+
geom_vline(data=data.frame(xintercept=fechasCorte),aes(xintercept=xintercept), linetype="dashed", color = "red")+
geom_line(data=dfTestosteronaDuranteLesion,aes(group=as.factor(idLesion),color=CODE),linewidth=2,alpha=0.5)+
geom_point(data=dfTestosteronaDuranteLesion,size=3,alpha=0.5)+
scale_x_date(date_breaks = "1 week", date_labels = "%Y-%m-%d") +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
guides(color = guide_legend(ncol = 15))+
theme(legend.position = "top")
Y ahora las lesiones para cada individuo, indicando Mecanismo y EtiologĆa
dfCortisolLesion %>% ggplot(aes(x=Fecha,y=Cortisol)) +
geom_line(alpha=0.5)+
geom_point(alpha=0.5)+
geom_vline(data=data.frame(xintercept=fechasCorte),aes(xintercept=xintercept), linetype="dashed", color = "red")+
geom_line(data=dfCortisolDuranteLesionAlt,aes(color=MECHANISM,group=idLesion),linewidth=2,alpha=0.5)+
geom_point(data=dfCortisolDuranteLesionAlt,aes(pch=ETHIOLOGY,color=MECHANISM),size=3,alpha=0.5)+
facet_wrap(~CODE,ncol=1)+
scale_x_date(date_breaks = "1 week", date_labels = "%Y-%m-%d") +
theme_minimal()+
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
guides(color = guide_legend(ncol = 5))+
theme(legend.position = "top")
dfTestosteronaLesion %>% ggplot(aes(x=Fecha,y=Testosterona)) +
geom_line(alpha=0.5)+
geom_point(alpha=0.5)+
geom_vline(data=data.frame(xintercept=fechasCorte),aes(xintercept=xintercept), linetype="dashed", color = "red")+
geom_line(data=dfTestosteronaDuranteLesion,aes(color=MECHANISM,group=idLesion),linewidth=2,alpha=0.5)+
geom_point(data=dfTestosteronaDuranteLesion,aes(pch=ETHIOLOGY,color=MECHANISM),size=3,alpha=0.5)+
facet_wrap(~CODE,ncol=1)+
scale_x_date(date_breaks = "1 week", date_labels = "%Y-%m-%d") +
theme_minimal()+
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
guides(color = guide_legend(ncol = 5))+
theme(legend.position = "top")
## `geom_line()`: Each group consists of only one observation.
## ā¹ Do you need to adjust the group aesthetic?
dfCortisolLesionSano=dfCortisolLesion %>% filter(Lesionado==FALSE) %>% bind_rows(
dfCortisolLesion %>% arrange(CODE,Fecha) %>% filter(Lesionado==TRUE) %>% group_by(idLesion) %>%
summarise_all(first)) %>%
arrange(CODE,Fecha)
dfTestosteronaLesionSano=dfCortisolLesion %>% filter(Lesionado==FALSE) %>% bind_rows(
dfTestosteronaLesion %>% arrange(CODE,Fecha) %>% filter(Lesionado==TRUE) %>% group_by(idLesion) %>%
summarise_all(first)) %>%
arrange(CODE,Fecha)
dfCortisolLesionSano=dfCortisolLesion%>% filter(!Lesionado) %>% bind_rows(
dfCortisolLesion %>% filter(Lesionado) %>% group_by(idLesion) %>% summarise_all(first)) %>%
arrange(CODE,Fecha) %>%
# filter((!Lesionado & is.na(idLesion)) | Lesionado) %>%
ungroup() %>%
arrange(CODE,Fecha) %>%
mutate(racha=DATE) %>%
fill(racha,.direction="up") %>%
mutate(racha=as.integer(as.factor(str_c(CODE,"-",racha)))) %>%
select(CODE,Fecha,DATE,Lesionado,racha,everything())
dfTestosteronaLesionSano=dfTestosteronaLesion%>% filter(!Lesionado) %>% bind_rows(
dfTestosteronaLesion %>% filter(Lesionado) %>% group_by(idLesion) %>% summarise_all(first)) %>%
arrange(CODE,Fecha) %>%
# filter((!Lesionado & is.na(idLesion)) | Lesionado) %>%
ungroup() %>%
arrange(CODE,Fecha) %>%
mutate(racha=DATE) %>%
fill(racha,.direction="up") %>%
mutate(racha=as.integer(as.factor(str_c(CODE,"-",racha)))) %>%
select(CODE,Fecha,DATE,Lesionado,racha,everything())
Y esto deberĆan ser los periodos de cada jugador que terminan o no con Lesión.
dfCortisolLesionSano %>% ggplot(aes(x=Fecha,y=Cortisol,group=racha)) +
geom_line(alpha=0.5)+
geom_point(alpha=0.5)+
geom_text(data=dfPartidos %>% mutate(racha=1,Cortisol=15), aes(x=Fecha,y=Cortisol,label=Resultado))+
geom_vline(data=data.frame(xintercept=fechasCorte),aes(xintercept=xintercept), linetype="dashed", color = "red")+
geom_point(data=dfCortisolLesionSano %>% filter(Lesionado),aes(pch=ETHIOLOGY,color=MECHANISM),size=3,alpha=0.5)+
facet_wrap(~CODE,ncol=1)+
scale_x_date(date_breaks = "1 week", date_labels = "%Y-%m-%d") +
theme_minimal()+
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
guides(color = guide_legend(ncol = 5))+
theme(legend.position = "top")
dfTestosteronaLesionSano %>% ggplot(aes(x=Fecha,y=Testosterona,group=racha)) +
geom_line(alpha=0.5)+
geom_point(alpha=0.5)+
geom_text(data=dfPartidos %>% mutate(racha=1,Testosterona=500), aes(x=Fecha,y=Testosterona,label=Resultado))+
geom_vline(data=data.frame(xintercept=fechasCorte),aes(xintercept=xintercept), linetype="dashed", color = "red")+
geom_point(data=dfTestosteronaLesionSano %>% filter(Lesionado),aes(pch=ETHIOLOGY,color=MECHANISM),size=3,alpha=0.5)+
facet_wrap(~CODE,ncol=1)+
scale_x_date(date_breaks = "1 week", date_labels = "%Y-%m-%d") +
theme_minimal()+
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
guides(color = guide_legend(ncol = 5))+
theme(legend.position = "top")
Algunos aĆ”lisis de regresión logĆstica en bruto. En estos se busca asociación entre valores altos de Cortisol y lesión, donde en lo de āaltoā no se tiene en cuenta que cada jugador tal vez tenga su propios valores āaltosā. No se considera el nivel medio de cada jugador ni se extraen periodos difĆciles para ellos.
dfCortisolTestosterona=dfCortisolLesionSano %>% inner_join(dfTestosteronaLesionSano %>% select(CODE,Fecha,Testosterona))
## Joining with `by = join_by(CODE, Fecha)`
glm(Lesionado ~ Cortisol+Testosterona,data=dfCortisolTestosterona) %>% summary()
##
## Call:
## glm(formula = Lesionado ~ Cortisol + Testosterona, data = dfCortisolTestosterona)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -0.18840 -0.06735 -0.05213 -0.04455 0.96436
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.718e-02 3.280e-02 0.524 0.6007
## Cortisol 7.283e-03 3.086e-03 2.360 0.0185 *
## Testosterona 4.726e-06 9.265e-05 0.051 0.9593
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for gaussian family taken to be 0.05668437)
##
## Null deviance: 40.396 on 709 degrees of freedom
## Residual deviance: 40.076 on 707 degrees of freedom
## AIC: -17.996
##
## Number of Fisher Scoring iterations: 2
glm(Lesionado ~ Cortisol+Testosterona,data=dfCortisolTestosterona %>% filter(MECHANISM=="SOBRECARGA")) %>% summary()
##
## Call:
## glm(formula = Lesionado ~ Cortisol + Testosterona, data = dfCortisolTestosterona %>%
## filter(MECHANISM == "SOBRECARGA"))
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -1.332e-15 -1.110e-15 -1.110e-15 -8.882e-16 -4.441e-16
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.000e+00 1.078e-15 9.275e+14 <2e-16 ***
## Cortisol -1.509e-17 9.172e-17 -1.650e-01 0.871
## Testosterona 2.198e-18 3.194e-18 6.880e-01 0.501
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for gaussian family taken to be 1.339903e-30)
##
## Null deviance: 0.0000e+00 on 19 degrees of freedom
## Residual deviance: 2.2778e-29 on 17 degrees of freedom
## AIC: -1314.2
##
## Number of Fisher Scoring iterations: 1
glm(Lesionado ~ Cortisol,data=dfCortisolLesionSano %>% filter(ETHIOLOGY=="LIGAMENTOSA")) %>% summary()
##
## Call:
## glm(formula = Lesionado ~ Cortisol, data = dfCortisolLesionSano %>%
## filter(ETHIOLOGY == "LIGAMENTOSA"))
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -2.22e-16 -2.22e-16 -2.22e-16 0.00e+00 0.00e+00
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.000e+00 2.004e-16 4.991e+15 <2e-16 ***
## Cortisol 4.039e-17 2.912e-17 1.387e+00 0.215
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for gaussian family taken to be 4.108651e-32)
##
## Null deviance: 0.0000e+00 on 7 degrees of freedom
## Residual deviance: 2.4652e-31 on 6 degrees of freedom
## AIC: -551.76
##
## Number of Fisher Scoring iterations: 1
glm(Lesionado ~ Cortisol+Testosterona,data=dfCortisolTestosterona %>% filter(ETHIOLOGY=="MUSCULAR")) %>% summary()
##
## Call:
## glm(formula = Lesionado ~ Cortisol + Testosterona, data = dfCortisolTestosterona %>%
## filter(ETHIOLOGY == "MUSCULAR"))
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## 4.441e-16 7.494e-16 8.327e-16 9.159e-16 1.110e-15
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.000e+00 6.331e-16 1.58e+15 <2e-16 ***
## Cortisol 9.431e-19 5.005e-17 1.90e-02 0.985
## Testosterona -1.624e-18 1.718e-18 -9.46e-01 0.352
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for gaussian family taken to be 7.803602e-31)
##
## Null deviance: 0.000e+00 on 31 degrees of freedom
## Residual deviance: 2.263e-29 on 29 degrees of freedom
## AIC: -2122.8
##
## Number of Fisher Scoring iterations: 1
glm(Lesionado ~ Cortisol+Testosterona,data=dfCortisolTestosterona %>% filter(ETHIOLOGY %in% c("MUSCULAR","LIGAMENTOSA") )) %>% summary()
##
## Call:
## glm(formula = Lesionado ~ Cortisol + Testosterona, data = dfCortisolTestosterona %>%
## filter(ETHIOLOGY %in% c("MUSCULAR", "LIGAMENTOSA")))
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## 1.110e-15 1.332e-15 1.443e-15 1.665e-15 1.887e-15
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.000e+00 9.987e-16 1.001e+15 <2e-16 ***
## Cortisol -9.694e-18 8.255e-17 -1.170e-01 0.907
## Testosterona -1.770e-18 2.405e-18 -7.360e-01 0.466
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for gaussian family taken to be 2.443203e-30)
##
## Null deviance: 0.0000e+00 on 39 degrees of freedom
## Residual deviance: 9.0399e-29 on 37 degrees of freedom
## AIC: -2609
##
## Number of Fisher Scoring iterations: 1
list(RachasCortisolLesion=dfCortisolTestosterona %>% select(CODE,Fecha,Cortisol,Testosterona,Lesionado,everything())) %>% openxlsx::write.xlsx("CortisolTestosteronaLesiones.xlsx")
ggplot(dfCortisolTestosterona,aes(x=Cortisol,y=Testosterona,color=CODE))+geom_point(alpha=0.2)+
geom_smooth(method="lm",se=FALSE)
## `geom_smooth()` using formula = 'y ~ x'
ggplot(dfCortisolTestosterona,aes(y=Cortisol,x=Testosterona,color=CODE))+geom_point(alpha=0.2)+
geom_smooth(method="lm",se=FALSE)
## `geom_smooth()` using formula = 'y ~ x'
ggplot(dfCortisolTestosterona,aes(x=Cortisol,y=Testosterona,color=!is.na(DATE)))+geom_point()+
geom_smooth(method="lm",se=FALSE)+
facet_wrap(~CODE,ncol=5)
## `geom_smooth()` using formula = 'y ~ x'
El número de variables es enorme cada una con sus propias unidades, asà que una buena primera idea es tipificarlas todas poniendo su media en cero y desviación en uno.
Por otro lado si lo que nos interesa es comparar Ć©pocas, podrĆa ser interesante tomar los cambios en los individuos con respecto a sĆ mismos, es decir, estandarizar dentro de los propios individuos. Esto no es necesario, pero puede aƱadir algo mĆ”s de claridad.
gfC=dfCortisolLesionSano %>% select(CODE,Fecha,Cortisol) %>% mutate(name="Cortisol",value=Cortisol) %>% select(-Cortisol)
gfT=dfTestosteronaLesionSano %>% select(CODE,Fecha,Testosterona) %>% mutate(name="Testosterona",value=Testosterona) %>% select(-Testosterona)
gfCC=dfCC %>% pivot_longer(-c(CODE,Fecha))
gfRaw=gfC %>% bind_rows(gfT) %>% bind_rows(gfCC) %>% filter(!name %in% c("ALTURA","MUĆECA","FEMUR","P.GEMELO12","P.MUSLO14","P.MUSLO4","P.MUSLO5","P.MUSLO9","P.OSEO","P.MEDIAL MUSLO","P.MEDIAL MUSLO10",
"P.GEMELO","P.MEDIAL MUSLO6","P.VASTO","P.VASTO7","P.VASTO11",
"P.GEMELO8","P.VASTO 11","P.VASTO 7"))
gfZ=gfRaw %>% group_by(name) %>% mutate(Z=as.numeric(scale(value))) %>%
group_by(name,CODE) %>% mutate(ZP=as.numeric(scale(value))) %>% ungroup() %>%
mutate(Fecha=as.Date(Fecha)) %>%
mutate(Epoca=str_c("E",Fecha %>% cut(breaks=fechasCorte,labels=FALSE,right=T,left=T)))
gfZ %>% ggplot(aes(y=ZP,x=Epoca,fill=Epoca)) +
geom_jitter(alpha=0.25,pch=".")+
geom_boxplot(alpha=0.5)+
geom_signif(comparisons = list(c("E1", "E2"),c("E2", "E3")),map_signif_level = TRUE)+
facet_wrap(~name,ncol=5)
## Warning: Removed 93 rows containing non-finite values (`stat_boxplot()`).
## Warning: Removed 93 rows containing non-finite values (`stat_signif()`).
## Warning: Removed 93 rows containing missing values (`geom_point()`).
Esto se puede interpretar de dos modos, dependiendo de que nos refiramos a los entrenamientos antes del partido o después del partido. También hay que saber qué es carga de entrenamiento. ¿Testosterona? ¿Cortisol? ¿Las variables %Agua?
De momento va con testosterona y Cortisol.
dgPost <- fuzzy_left_join(dfPartidos, gfZ,
by = c("Fecha","Fecha"),
match_fun = list(`<`)) %>%
group_by(Fecha.x,CODE,name) %>%
filter(Fecha.y == min(Fecha.y)) %>%
ungroup() %>% rename(Fecha=Fecha.x,FechaPost=Fecha.y)
dgPre <- fuzzy_left_join(dfPartidos, gfZ,
by = c("Fecha","Fecha"),
match_fun = list(`>=`)) %>%
group_by(Fecha.x,CODE,name) %>%
filter(Fecha.y == max(Fecha.y)) %>%
ungroup()%>% rename(Fecha=Fecha.x,FechaPre=Fecha.y)
dgDif=dgPre %>% inner_join(dgPost,by=c("Fecha","Resultado","Puntos","Acumulado","CODE","name","Epoca")) %>%
filter(as.numeric(FechaPost-FechaPre)<=14) %>%
mutate(ZPdif=ZP.y-ZP.x)
dhPre <- fuzzy_left_join(dfPartidos, dfGPS_Nlong,
by = c("Fecha","Fecha"),
match_fun = list(`>=`)) %>%
group_by(Fecha.x,CODE,name) %>%
filter(Fecha.y == max(Fecha.y)) %>%
ungroup()%>%
rename(Fecha=Fecha.x,FechaPre=Fecha.y) %>%
mutate(Epoca=str_c("E",Fecha %>% cut(breaks=fechasCorte,labels=FALSE,right=T,left=T)))
Tras cada partido hay una primera medición de Testosterona y Cortisol cuando el jugador no se ha lesionado. Esta es la distribución de los valores, indicÔndose en color el resultado de ese partido justo anterior.
dgPost %>% filter(name %in%c("Testosterona","Cortisol")) %>% ggplot(aes(x=Fecha,y=ZP,group=Fecha,fill=Resultado)) +
geom_boxplot()+
facet_wrap(~name,ncol=1)+
geom_vline(data=data.frame(xintercept=fechasCorte),aes(xintercept=xintercept), linetype="dashed", color = "red")+
scale_x_date(date_breaks = "1 week", date_labels = "%Y-%m-%d") +
scale_fill_manual(values=c("D"="Gray","L"="darkred","W"="darkgreen"))+
theme_minimal()+
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
guides(color = guide_legend(ncol = 5))+
theme(legend.position = "top")
Lo mismo pero observando los valores justo antes del partido. El color representa el resultado del partido.
dgPre %>% filter(name %in%c("Testosterona","Cortisol")) %>% ggplot(aes(x=Fecha,y=ZP,group=Fecha,fill=Resultado)) +
geom_boxplot()+
facet_wrap(~name,ncol=1)+
geom_vline(data=data.frame(xintercept=fechasCorte),aes(xintercept=xintercept), linetype="dashed", color = "red")+
scale_x_date(date_breaks = "1 week", date_labels = "%Y-%m-%d") +
scale_fill_manual(values=c("D"="Gray","L"="darkred","W"="darkgreen"))+
theme_minimal()+
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
guides(color = guide_legend(ncol = 5))+
theme(legend.position = "top")
AquĆ miramos la diferencia que hay entre la medida anterior y posterior del partido para jugadores que no se han lesionado.
dgDif %>% filter(name %in%c("Testosterona","Cortisol")) %>% ggplot(aes(x=Fecha,y=ZPdif,group=Fecha,fill=Resultado)) +
geom_boxplot()+
facet_wrap(~name,ncol=1)+
geom_vline(data=data.frame(xintercept=fechasCorte),aes(xintercept=xintercept), linetype="dashed", color = "red")+
scale_x_date(date_breaks = "1 week", date_labels = "%Y-%m-%d") +
scale_fill_manual(values=c("D"="Gray","L"="darkred","W"="darkgreen"))+
theme_minimal()+
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
guides(color = guide_legend(ncol = 5))+
theme(legend.position = "top")
dgPre %>% ggplot(aes(x=Resultado,y=ZP,fill=Resultado))+
geom_jitter(alpha=0.25,pch=".")+
geom_boxplot(alpha=0.5)+
facet_wrap(~name,ncol=4)+
scale_fill_manual(values=c("D"="gray","L"="darkred","W"="darkgreen"))+
theme(legend.position = "top")+
geom_signif(comparisons = list(c("L", "W")),map_signif_level = TRUE,y_position=4)
## Warning: Removed 86 rows containing non-finite values (`stat_boxplot()`).
## Warning: Removed 86 rows containing non-finite values (`stat_signif()`).
## Warning: Removed 86 rows containing missing values (`geom_point()`).
dgPost %>% ggplot(aes(x=Resultado,y=ZP,fill=Resultado))+
geom_jitter(alpha=0.25,pch=".")+
geom_boxplot(alpha=0.5)+
facet_wrap(~name,ncol=4)+
scale_fill_manual(values=c("D"="gray","L"="darkred","W"="darkgreen"))+
theme(legend.position = "top")+
geom_signif(comparisons = list(c("L", "W")),map_signif_level = TRUE,y_position=4)
## Warning: Removed 98 rows containing non-finite values (`stat_boxplot()`).
## Warning: Removed 98 rows containing non-finite values (`stat_signif()`).
## Warning: Removed 98 rows containing missing values (`geom_point()`).
Lo pongo por que lo tenemos. Es dificil de interpretar aquĆ por que todo āPREā es tambiĆ©n un āPOSTā de otro partido.
dgDif %>% ggplot(aes(x=Resultado,y=ZPdif,fill=Resultado))+
geom_jitter(alpha=0.25,pch=".")+
geom_boxplot(alpha=0.5)+
facet_wrap(~name,ncol=4)+
scale_fill_manual(values=c("D"="gray","L"="darkred","W"="darkgreen"))+
theme(legend.position = "top")+
geom_signif(comparisons = list(c("L", "W")),map_signif_level = TRUE,y_position=4)
## Warning: Removed 72 rows containing non-finite values (`stat_boxplot()`).
## Warning: Removed 72 rows containing non-finite values (`stat_signif()`).
## Warning: Removed 72 rows containing missing values (`geom_point()`).
Esto estĆ” hecho anteriormente. Lo interpretaremos como que queremos aƱadir las comparaciones entre entrenadores segĆŗn el tipo de resultado. AquĆ habrĆa que ver quĆ© comparaciones realmente nos interesa hacer, por que habrĆa dos factores a estudiar, el entrenador y el resultado del partido.
dgPre %>% ggplot(aes(x=Epoca,y=ZP,fill=Resultado))+
#geom_jitter(alpha=0.25,pch=".")+
geom_boxplot(alpha=0.5,position = "dodge2")+
facet_wrap(~name,ncol=4)+
scale_fill_manual(values=c("D"="gray","L"="darkred","W"="darkgreen"))+
theme(legend.position = "top")
## Warning: Removed 86 rows containing non-finite values (`stat_boxplot()`).
#geom_signif(comparisons = list(c("L", "W")),map_signif_level = TRUE,y_position=4)
dgPost %>% ggplot(aes(x=Epoca,y=ZP,fill=Resultado))+
#geom_jitter(alpha=0.25,pch=".")+
geom_boxplot(alpha=0.5,position = "dodge2")+
facet_wrap(~name,ncol=4)+
scale_fill_manual(values=c("D"="gray","L"="darkred","W"="darkgreen"))+
theme(legend.position = "top")
## Warning: Removed 98 rows containing non-finite values (`stat_boxplot()`).
#geom_signif(comparisons = list(c("L", "W")),map_signif_level = TRUE,y_position=4)
A lo largo de la temporada esta es lo que se ha recogido, estandarizando la variable dentro de cada jugador. HabrĆa que ver si serĆa bueno sacar a los porteros de aquĆ y quĆ© hacer cuando tenemos dos mediciones de un jugador en el mismo dia (Quedarnos solo con la primera?). Esta es la primera aproximación:
dhPre %>% ggplot(aes(x=Fecha,y=ZP,group=Fecha,fill=Resultado)) +
geom_boxplot()+
facet_wrap(~name,ncol=1)+
geom_vline(data=data.frame(xintercept=fechasCorte),aes(xintercept=xintercept), linetype="dashed", color = "red")+
scale_x_date(date_breaks = "1 week", date_labels = "%Y-%m-%d") +
scale_fill_manual(values=c("D"="Gray","L"="darkred","W"="darkgreen"))+
theme_minimal()+
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
guides(color = guide_legend(ncol = 5))+
theme(legend.position = "top")
## Warning: Removed 280 rows containing non-finite values (`stat_boxplot()`).
Simplifiquémolo a la relación con resultados del partido, ignorando las fechas:
dhPre %>% ggplot(aes(x=Resultado,y=ZP,fill=Resultado))+
geom_jitter(alpha=0.25,pch=".")+
geom_boxplot(alpha=0.5)+
facet_wrap(~name,ncol=4)+
scale_fill_manual(values=c("D"="gray","L"="darkred","W"="darkgreen"))+
theme(legend.position = "top")+
geom_signif(comparisons = list(c("L", "W")),map_signif_level = TRUE,y_position=4)
## Warning: Removed 280 rows containing non-finite values (`stat_boxplot()`).
## Warning: Removed 280 rows containing non-finite values (`stat_signif()`).
## Warning: Removed 280 rows containing missing values (`geom_point()`).
Desglosemos los resultados anteriores según épocas de entrenador:
dhPre %>% ggplot(aes(x=Epoca,y=ZP,fill=Resultado))+
#geom_jitter(alpha=0.25,pch=".")+
geom_boxplot(alpha=0.5,position = "dodge2")+
facet_wrap(~name,ncol=4)+
scale_fill_manual(values=c("D"="gray","L"="darkred","W"="darkgreen"))+
theme(legend.position = "top")
## Warning: Removed 280 rows containing non-finite values (`stat_boxplot()`).
#geom_signif(comparisons = list(c("L", "W")),map_signif_level = TRUE,y_position=4)
Hay dias con dos tipos de entrenamiento diferente. Promediar no es evidente que sea la solución con ellos. Voy a quedarme con los dias en los que solo hay un entrenamiento, que son la inmensa mayorĆa:
dfGPS_C1=dfGPS_C %>% count(CODE,Fecha) %>% filter(n==1)
dfGPS_C1 %>% nrow()
## [1] 2925
dfGPS_CT=dfGPS_C1 %>% inner_join(dfGPS_C) %>%
inner_join(gfZ %>% filter(name %in% c("Testosterona","Cortisol")),by = join_by(CODE, Fecha))
## Joining with `by = join_by(CODE, Fecha)`
## Warning in inner_join(., gfZ %>% filter(name %in% c("Testosterona", "Cortisol")), : Each row in `x` is expected to match at most 1 row in `y`.
## ā¹ Row 25 of `x` matches multiple rows.
## ā¹ If multiple matches are expected, set `multiple = "all"` to silence this
## warning.
Nos hemos quedado con muchas menos mediciones por no coincidir en el mismo dia las mediciones. MÔs adelante haremos una unión permitiendo ciertas distancia hacia delante y detrÔs.
Vamos a explorar tipo de entrenamiento y hormonas cuando se hacen las mediciones el mismo dia y solo hay un tipo de entrenamiento ese dia:
dfGPS_CT
## # A tibble: 955 Ć 10
## CODE Fecha n Sesion Puesto name value Z ZP Epoca
## <chr> <date> <int> <chr> <chr> <chr> <dbl> <dbl> <dbl> <chr>
## 1 COD10 2022-08-18 1 Técnico-tÔc⦠Pivote Cort⦠3.61 -0.740 -0.373 E1
## 2 COD10 2022-08-18 1 Técnico-tÔc⦠Pivote Test⦠302 0.0245 -0.760 E1
## 3 COD10 2022-08-26 1 Prepartido Pivote Cort⦠2.87 -0.994 -0.869 E1
## 4 COD10 2022-08-26 1 Prepartido Pivote Test⦠340 0.417 -0.233 E1
## 5 COD10 2022-08-30 1 Preventivo-⦠Pivote Cort⦠5.72 -0.0147 1.04 E1
## 6 COD10 2022-08-30 1 Preventivo-⦠Pivote Test⦠320 0.210 -0.511 E1
## 7 COD10 2022-09-07 1 F.dirigida-⦠Pivote Cort⦠5.69 -0.0250 1.02 E1
## 8 COD10 2022-09-07 1 F.dirigida-⦠Pivote Test⦠352 0.540 -0.0665 E1
## 9 COD10 2022-09-15 1 Técnico-tÔc⦠Pivote Cort⦠6.37 0.209 1.47 E1
## 10 COD10 2022-09-15 1 Técnico-tÔc⦠Pivote Test⦠330 0.313 -0.372 E1
## # ⦠with 945 more rows
dfGPS_CT %>% ggplot(aes(x=name,y=ZP,fill=name))+
geom_jitter(alpha=0.25,pch=".")+
geom_boxplot(alpha=0.5)+
facet_wrap(~Sesion,ncol=4)+
# scale_fill_manual(values=c("D"="gray","L"="darkred","W"="darkgreen"))+
theme(legend.position = "top")
Hay tantos tipos de entrenamiento que tal vez deberĆamos recodificarlos en otras categorĆas.
Vamos a empezar viendo la descriptiva por posición centrÔndonos en el entrenamiento antes del partido. No es la única posibilidad, pero por mantener el que la posición se le asigna al jugador en GPS, y buscamos la mÔs cercana para hormonas.
dfGPSHormonasLong=dfGPS_Nlong %>% left_join(dfGPS_C,by = join_by(CODE, Fecha)) %>%
bind_rows(dfGPS_CT)
## Warning in left_join(., dfGPS_C, by = join_by(CODE, Fecha)): Each row in `x` is expected to match at most 1 row in `y`.
## ā¹ Row 9 of `x` matches multiple rows.
## ā¹ If multiple matches are expected, set `multiple = "all"` to silence this
## warning.
dfGPSHormonasLong %>% ggplot(aes(x=Puesto,y=Z,fill=Puesto))+
geom_jitter(alpha=0.1)+
coord_cartesian(ylim=c(-4,4))+
geom_boxplot(alpha=0.5)+
facet_wrap(~name,ncol=3)+
theme(legend.position = "top")
qq=dfGPSHormonasLong %>% filter(Repeticion==0 | is.na(Repeticion)) %>%
filter(name %in% c("Duration","Testosterona","Cortisol")) %>% arrange(CODE,Fecha,name)
ww=qq %>% count(CODE,Fecha) %>% filter(n==3) %>% select(-n) %>%
inner_join( qq %>% select(CODE,Fecha,name,ZP)) %>%
arrange(CODE,Fecha,name) %>%
select(CODE,Fecha,name,ZP) %>%
pivot_wider(names_from="name",values_from = "ZP",id_cols = c("CODE","Fecha"))
## Joining with `by = join_by(CODE, Fecha)`
## Warning in inner_join(., qq %>% select(CODE, Fecha, name, ZP)): Each row in `x` is expected to match at most 1 row in `y`.
## ā¹ Row 1 of `x` matches multiple rows.
## ā¹ If multiple matches are expected, set `multiple = "all"` to silence this
## warning.
corr=cor(ww %>% select(-CODE,-Fecha))
p.mat=cor_pmat(ww %>% select(-CODE,-Fecha))
La matriz de correlaciones:
corr
## Cortisol Duration Testosterona
## Cortisol 1.00000000 -0.06438283 0.06389939
## Duration -0.06438283 1.00000000 0.03551336
## Testosterona 0.06389939 0.03551336 1.00000000
Y la de los āpā:
p.mat
## Cortisol Duration Testosterona
## Cortisol 0.0000000 0.1603457 0.1635150
## Duration 0.1603457 0.0000000 0.4390298
## Testosterona 0.1635150 0.4390298 0.0000000
No es nada interesante