1 Introducción a los TFGs

Álvaro Alonso Fernández
Departamento de Ciencias de la Vida
Universidad de Alcalá (España)


ASIGNATURA: Introducción a los TFGs orientados a la investigación
Transversal Ciencias Ambientales




Se puede reproducir íntegro para usos no comerciales, sin modificar y citando a los autores. Sugerencia de cita:

Alonso A (2025) Introducción TFGs-Ejercicio de memoria. RPubs. https://rpubs.com/aafernandez1976

2 RESULTADOS DE NUESTRO ESTUDIO

Hemos seguido el método científico. Ahora toca explorar nuestros datos y ver si tenemos alguna tendencia clara.


Veamos que ocurre con nuestra memoria


3 NUESTROS DATOS

setwd(dir = "G:/R/MARKDOWN-Clases/IntroTFG24-25/")
datos<-read.table("results_digital_paper.csv", sep = ";", header = TRUE, dec = ".")
datos
##   individuo      fecha  hora   estudios edad mujer hombre AD_DA DA_AD por_A_t1
## 1        S1 02/12/2024 17:30 biol_sanit   21     0      1     1     0       50
## 2        B2 02/12/2024 17:30      biolo   22     1      0     0     1       60
## 3        B1 02/12/2024 17:30      biolo   22     0      1     1     0       50
## 4        E1 02/12/2024 17:45      econo   24     0      1     0     1       70
## 5        Q3 02/12/2024 18:00       quim   22     0      1     0     1       80
## 6        Q4 02/12/2024 17:30       quim   22     0      1     1     0       60
## 7        Q1 02/12/2024 17:30       quim   22     0      1     1     0       50
## 8        Q2 02/12/2024 17:30       quim   23     0      1     0     1       50
##   por_D_t1 por_D_t2 por_A_t2 dif_A_D_t1 dif_A_D_t2
## 1       60       90       80        -10        -10
## 2       30       60       70         30         10
## 3       70       60       60        -20          0
## 4       50       50       60         20         10
## 5       60       80       90         20         10
## 6       50       60       50         10        -10
## 7       50       60       70          0         10
## 8       90       70       60        -40        -10
str(datos)
## 'data.frame':    8 obs. of  15 variables:
##  $ individuo : chr  "S1" "B2" "B1" "E1" ...
##  $ fecha     : chr  "02/12/2024" "02/12/2024" "02/12/2024" "02/12/2024" ...
##  $ hora      : chr  "17:30" "17:30" "17:30" "17:45" ...
##  $ estudios  : chr  "biol_sanit" "biolo" "biolo" "econo" ...
##  $ edad      : int  21 22 22 24 22 22 22 23
##  $ mujer     : int  0 1 0 0 0 0 0 0
##  $ hombre    : int  1 0 1 1 1 1 1 1
##  $ AD_DA     : int  1 0 1 0 0 1 1 0
##  $ DA_AD     : int  0 1 0 1 1 0 0 1
##  $ por_A_t1  : int  50 60 50 70 80 60 50 50
##  $ por_D_t1  : int  60 30 70 50 60 50 50 90
##  $ por_D_t2  : int  90 60 60 50 80 60 60 70
##  $ por_A_t2  : int  80 70 60 60 90 50 70 60
##  $ dif_A_D_t1: int  -10 30 -20 20 20 10 0 -40
##  $ dif_A_D_t2: int  -10 10 0 10 10 -10 10 -10

4 BOXPLOT de las variables dependientes

library(ggplot2)
gr00<-ggplot(datos, aes(x=0, y=por_A_t1))+ geom_boxplot(color="red", fill="orange")+
  labs(x='Tratamiento Papel t1', y='Porcentaje de recuerdo')

gr11<-ggplot(datos, aes(x=0, y=por_D_t1))+ geom_boxplot(color="darkgreen", fill="green")+
  labs(x='Tratamiento Móvil t1', y='Porcentaje de recuerdo')

gr12<-ggplot(datos, aes(x=0, y=por_A_t2))+ geom_boxplot(color="red", fill="orange")+
  labs(x='Tratamiento Papel t2', y='Porcentaje de recuerdo')

gr13<-ggplot(datos, aes(x=0, y=por_D_t2))+ geom_boxplot(color="darkgreen", fill="green")+
  labs(x='Tratamiento Móvil t2', y='Porcentaje de recuerdo')

library(patchwork)
(gr00|gr11)

(gr12|gr13)

grDifs<-ggplot(datos, aes(x=0, y=dif_A_D_t1))+ geom_boxplot(width = 0.10, color="black", fill="orange")+
  xlim(-0.5, 0.5) +
  labs(x='Población de estudio', y='Diferencias de recuerdo A_D_t1')+
  geom_hline(yintercept = 0,            # Línea horizontal en y = 0
             linetype = "dashed",       # Tipo de línea
             color = "red",             # Color de la línea
             size = 0.8)
grDifs

grDifs2<-ggplot(datos, aes(x=0, y=dif_A_D_t2))+ geom_boxplot(width = 0.10, color="black", fill="green")+
  xlim(-0.5, 0.5)+
  labs(x='Población de estudio', y='Diferencias de recuerdo A_D_t2')+
  geom_hline(yintercept = 0,            # Línea horizontal en y = 0
             linetype = "dashed",       # Tipo de línea
             color = "red",             # Color de la línea
             size = 0.8)
grDifs2

5 GRÁFICO DE DISPERSIÓN de las variables dependientes y significación del modelo

###Grafico de dispersión Papel vs movil
plot(por_A_t1~por_D_t1,data=datos,pch=16)
abline(lm(por_A_t1~por_D_t1,data=datos),col="red")

plot(por_A_t2~por_D_t2,data=datos,pch=16)
abline(lm(por_A_t2~por_D_t2,data=datos),col="red")

###Veamos la regresión lineal
model_t1<-lm(por_A_t1~por_D_t1,data=datos)
summary(model_t1)
## 
## Call:
## lm(formula = por_A_t1 ~ por_D_t1, data = datos)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -10.233  -6.773  -3.256   2.267  21.744 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)   
## (Intercept)  70.1163    14.9222   4.699  0.00333 **
## por_D_t1     -0.1977     0.2496  -0.792  0.45849   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 11.57 on 6 degrees of freedom
## Multiple R-squared:  0.09466,    Adjusted R-squared:  -0.05623 
## F-statistic: 0.6274 on 1 and 6 DF,  p-value: 0.4585
model_t2<-lm(por_A_t2~por_D_t2,data=datos)
summary(model_t2)
## 
## Call:
## lm(formula = por_A_t2 ~ por_D_t2, data = datos)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -13.1579  -5.5263   0.3158   6.8421  12.9474 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)  
## (Intercept)  21.4737    19.1666   1.120   0.3054  
## por_D_t2      0.6947     0.2845   2.442   0.0504 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 9.805 on 6 degrees of freedom
## Multiple R-squared:  0.4984, Adjusted R-squared:  0.4148 
## F-statistic: 5.962 on 1 and 6 DF,  p-value: 0.05036

6 MODELO LIBRE de las variables dependientes

library(ggplot2)
qplot(datos$por_A_t1,datos$por_D_t1,geom = c("point", "smooth"))+
  xlim(0, 100) +  # Limitar el eje X entre 00 y 100
  ylim(0, 100)    # Limitar el eje Y entre 00 y 100
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'

qplot(datos$por_A_t2,datos$por_D_t2,geom = c("point", "smooth"))+
  xlim(0, 100) +  # Limitar el eje X entre 00 y 100
  ylim(0, 100)    # Limitar el eje Y entre 00 y 100
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'

7 ESTADÍSTICA

7.1 Normalidad

###NORMALIDAD DE LAS VARIABLES
shapiro.test(datos$por_A_t1)
## 
##  Shapiro-Wilk normality test
## 
## data:  datos$por_A_t1
## W = 0.80891, p-value = 0.03563
shapiro.test(datos$por_D_t1)
## 
##  Shapiro-Wilk normality test
## 
## data:  datos$por_D_t1
## W = 0.93959, p-value = 0.607
shapiro.test(datos$por_A_t2)
## 
##  Shapiro-Wilk normality test
## 
## data:  datos$por_A_t2
## W = 0.93805, p-value = 0.592
shapiro.test(datos$por_D_t2)
## 
##  Shapiro-Wilk normality test
## 
## data:  datos$por_D_t2
## W = 0.87745, p-value = 0.178
shapiro.test(datos$dif_A_D_t1)
## 
##  Shapiro-Wilk normality test
## 
## data:  datos$dif_A_D_t1
## W = 0.95167, p-value = 0.7281
shapiro.test(datos$dif_A_D_t2)
## 
##  Shapiro-Wilk normality test
## 
## data:  datos$dif_A_D_t2
## W = 0.73599, p-value = 0.005711

7.2 Homocedasticidad

###VARIANZAS
var.test(datos$por_A_t1,datos$por_D_t1)
## 
##  F test to compare two variances
## 
## data:  datos$por_A_t1 and datos$por_D_t1
## F = 0.41279, num df = 7, denom df = 7, p-value = 0.2659
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
##  0.08264228 2.06185206
## sample estimates:
## ratio of variances 
##          0.4127907
var.test(datos$por_A_t2,datos$por_D_t2)
## 
##  F test to compare two variances
## 
## data:  datos$por_A_t2 and datos$por_D_t2
## F = 0.96842, num df = 7, denom df = 7, p-value = 0.9673
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
##  0.1938816 4.8371752
## sample estimates:
## ratio of variances 
##          0.9684211
#Se cumplen todos los requisitos

7.3 t-test no pareado

Para esta figura haremos un test no pareado, es decir se compararán todos los valores de una variable con todos los valores de la otra:

library(patchwork)
(gr00|gr11)

###Test de t-student no pareada:
t.test(datos$por_A_t1,datos$por_D_t1, var.equal=TRUE, paired=FALSE)
## 
##  Two Sample t-test
## 
## data:  datos$por_A_t1 and datos$por_D_t1
## t = 0.16973, df = 14, p-value = 0.8677
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -14.54604  17.04604
## sample estimates:
## mean of x mean of y 
##     58.75     57.50
(gr12|gr13)

###Test de t-student no pareada:
t.test(datos$por_A_t2,datos$por_D_t2, var.equal=TRUE, paired=FALSE)
## 
##  Two Sample t-test
## 
## data:  datos$por_A_t2 and datos$por_D_t2
## t = 0.19348, df = 14, p-value = 0.8494
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -12.60689  15.10689
## sample estimates:
## mean of x mean of y 
##     67.50     66.25

7.4 t-test pareado

Ahora haremos lo mismo pero con un test pareado, es decir se compara el resultado de cada individuo:

###Test de t-student pareada:

t.test(datos$por_A_t1,datos$por_D_t1, var.equal=TRUE, paired=TRUE)
## 
##  Paired t-test
## 
## data:  datos$por_A_t1 and datos$por_D_t1
## t = 0.15003, df = 7, p-value = 0.885
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
##  -18.45168  20.95168
## sample estimates:
## mean difference 
##            1.25
###Test de t-student pareada:
t.test(datos$por_A_t2,datos$por_D_t2, var.equal=TRUE, paired=TRUE)
## 
##  Paired t-test
## 
## data:  datos$por_A_t2 and datos$por_D_t2
## t = 0.35675, df = 7, p-value = 0.7318
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
##  -7.035228  9.535228
## sample estimates:
## mean difference 
##            1.25

7.5 t-test diferencias cero

Para esta figura haremos una comparación entre los valores y cero, es decir se compararán si ese conjunto de datos difiere de cero o no:

grDifs

grDifs2

###Test t-student diferencias igual a cero
t.test(datos$dif_A_D_t1)
## 
##  One Sample t-test
## 
## data:  datos$dif_A_D_t1
## t = 0.15003, df = 7, p-value = 0.885
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -18.45168  20.95168
## sample estimates:
## mean of x 
##      1.25
t.test(datos$dif_A_D_t2)
## 
##  One Sample t-test
## 
## data:  datos$dif_A_D_t2
## t = 0.35675, df = 7, p-value = 0.7318
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -7.035228  9.535228
## sample estimates:
## mean of x 
##      1.25

8 ¿Qué podemos discutir? ¿Conclusiones?

ahora toca pensar, ¿qué se puede discutir? ¿es correcto lo que hemos hecho? ¿se puede sacar alguna conclusión?

9 CRÉDITOS

Álvaro Alonso Fernández

mi Web de R

Departamento de Ciencias de la Vida

Universidad de Alcalá (España)