library(cli)
Warning: package ‘cli’ was built under R version 4.2.3
library(rlang)
Warning: package ‘rlang’ was built under R version 4.2.3
library(dplyr)
Warning: package ‘dplyr’ was built under R version 4.2.3
Attaching package: ‘dplyr’
The following objects are masked from ‘package:stats’:
filter, lag
The following objects are masked from ‘package:base’:
intersect, setdiff, setequal, union
library(tidyr)
Warning: package ‘tidyr’ was built under R version 4.2.3
# install.packages("datarium")
# cargar los datos
data("selfesteem", package = "datarium")
datos = selfesteem
boxplot(datos[,-1])
#CONVERTIR FORMATO ANCHO DE TRES COLUMNAS EN LARGO DE UNA SOLA COLUMNA
datos = datos %>%
gather(key = "tiempo",
value = "rto",
t1, t2, t3) %>%
mutate_at(vars(id, tiempo), as.factor)
head(datos)
#RESUMEN ESTADISTICO Numérico
datos %>%
group_by(tiempo) %>%
summarise(media = mean(rto),
desv = sd(rto),
n = n(),
cv = 100*desv/media)
#RESUMEN ESTADISTICO Gráfico
boxplot(datos$rto ~ datos$tiempo)
#BUSQUEDA DE DATOS ATÍPICOS
library(outliers)
library(rstatix)
Warning: package ‘rstatix’ was built under R version 4.2.3
Attaching package: ‘rstatix’
The following object is masked from ‘package:stats’:
filter
datos %>%
group_by(tiempo) %>%
identify_outliers(rto)
#SUPUESTOS DE NORMALIDAD
datos %>%
group_by(tiempo) %>%
shapiro_test(rto)
NA
determinar si existe la varianza entre los datos de los tiempos sucesivos
#ANALISIS DE VARIANZA
res.aov <- anova_test(data = datos,
dv = rto,
wid = id,
within = tiempo)
get_anova_table(res.aov)
ANOVA Table (type III tests)
Effect DFn DFd F p p<.05 ges
1 tiempo 2 18 55.469 2.01e-08 * 0.829
#SUPUESTO DE ESFERICIDAD (igualdad de varianzas)
res.aov$`Mauchly's Test for Sphericity`
get_anova_table(res.aov)
ANOVA Table (type III tests)
Effect DFn DFd F p p<.05 ges
1 tiempo 2 18 55.469 2.01e-08 * 0.829
p valoes es 2.01e-08 <5% se rechaza la hipótesis nula, el rendimiento no es el mismo en todos los cortes, aparentemente el tercer corte tiene mejores resultados.
#COMPARANDO ENTRE TIEMPOS BONFERRONI (pruebas de comparación)
datos %>%
pairwise_t_test(
rto ~ tiempo,
paired = TRUE,
p.adjust.method = "bonferroni")
NA
Los valores que se usan para las conslusiones son los que están en la columna de p.adj
data("selfesteem2", package = "datarium")
datos2 = selfesteem2
datos2$treatment = gl(2,12,24, c('con fert', 'sin fert'))
head(datos2)
El factor adicional es el uso de fertilizante, control sin fertilizante otras medidas con la aplicación de fertilizante.
#CONVERTIR FORMATO ANCHO DE TRES COLUMNAS EN LARGO DE UNA SOLA COLUMNA
datos2 = datos2 %>%
gather(key = 'tiempo' , value = 'rto',
t1, t2, t3)
head(datos2)
#RESUMEN ESTADISTICO Numérico
datos2 %>%
group_by(treatment, tiempo) %>%
summarise(media = mean(rto),
mediana = median(rto),
desv = sd(rto),
n = n(),
cv = 100*desv/media)
`summarise()` has grouped output by 'treatment'. You can override using the `.groups` argument.
#RESUMEN ESTADISTICO Gráfico
library(ggplot2)
ggplot(datos2)+
aes(tiempo, rto, fill=treatment)+
geom_boxplot()
NA
#BUSQUEDA DE DATOS ATÍPICOS
datos2 %>%
group_by(treatment, tiempo) %>%
identify_outliers(rto)
datos2 %>%
group_by(treatment, tiempo) %>%
shapiro_test(rto)
res.aov <- anova_test(
data = datos2,
dv = rto,
wid = id,
within = c(treatment,
tiempo)
)
get_anova_table(res.aov)
ANOVA Table (type III tests)
Effect DFn DFd F p p<.05 ges
1 treatment 1.00 11.00 15.541 2.00e-03 * 0.059
2 tiempo 1.31 14.37 27.369 5.03e-05 * 0.049
3 treatment:tiempo 2.00 22.00 30.424 4.63e-07 * 0.050
Primer valor a interpretar es la interacción 4.63e-07 < 5% se rechaza la hipótesis nula, hay interacción.
Las comparaciones POST_HOC se hacen únicamente cuando no hay interacción.
#GRÁFICO DE INTERACIÓN
interaction.plot(datos2$tiempo,
datos2$treatment,
datos2$rto)
# LO MISMO CON GGPLOT
datos2 %>%
group_by(tiempo, treatment) %>%
summarise(mean_rto = mean(rto)) %>%
ggplot()+
aes(tiempo, mean_rto,
color=treatment,
group=treatment)+
geom_point(size=5)+
geom_line(linewidth=3)
`summarise()` has grouped output by 'tiempo'. You can override using the `.groups` argument.Warning: Ignoring unknown parameters: linewidth
Interacción porque la lineas se cruzan
#SUPUESTO DE ESFERICIDAD (igualdad de varianzas)
res.aov$`Mauchly's Test for Sphericity`
NA