Code
cat('\014') # clean terminalCode
rm(list = ls()) # clean workspace
library(tidyverse)
library(readxl)
library(afex)
library(emmeans)
library(easystats)Tarea de detección de latidos usando teclado
cat('\014') # clean terminalrm(list = ls()) # clean workspace
library(tidyverse)
library(readxl)
library(afex)
library(emmeans)
library(easystats)my_dodge <- .3
my_jitter <- .2
theme_set(theme_minimal())
a_posteriori_aov_ez <- function(aov_ez_object, sig_level = .05) {
factors <- as.list(rownames(aov_ez_object$anova_table))
for (j in 1:length(factors)) {
if (grepl(':', factors[[j]])) {
factors[[j]] <- unlist(strsplit(factors[[j]], ':'))
}
}
p_values <- aov_ez_object$anova_table$`Pr(>F)`
for (i in 1:length(p_values)) {
if (p_values[i] <= sig_level) {
cat(rep('_', 60), '\n', sep = '')
print(emmeans(aov_ez_object, factors[[i]], contr = 'pairwise'))
}
}
}
a_posteriori_lmer <- function(lmer_obj, sig_level = .05) {
anova_lmer <- anova(lmer_obj)
factors <- as.list(row.names(anova_lmer))
for (j in 1:length(factors)) {
if (grepl(':', factors[[j]])) {
factors[[j]] <- unlist(strsplit(factors[[j]], ':'))
}
}
p_values <- anova_lmer$`Pr(>F)`
for (i in 1:length(p_values)) {
if (p_values[i] <= sig_level) {
cat(rep('_', 60), '\n', sep = '')
print(emmeans(lmer_obj, factors[[i]], contr = 'pairwise'))
}
}
}rho_df <- read_csv('rho_wide.csv', show_col_types = FALSE)
struct_df <- read_excel('ESTRATEGIAS FENO DE INTERO CARDIACA edit.xlsx') |>
mutate(Participante = parse_number(ID),
Grupo = case_match(substring(ID, 1, 1), 'N' ~ 'normopeso', 'O' ~ 'obeso'))Warning: There was 1 warning in `mutate()`.
ℹ In argument: `Grupo = case_match(substring(ID, 1, 1), "N" ~ "normopeso", "O"
~ "obeso")`.
Caused by warning:
! `case_match()` was deprecated in dplyr 1.2.0.
ℹ Please use `recode_values()` instead.
intero_df <- merge(struct_df, rho_df[c('Participante', 'Intero1', 'Sexo')], by = 'Participante') |>
mutate(log_rho = log(Intero1),
Participante = factor(Participante),
Grupo = relevel(factor(Grupo), 'obeso')) |>
mutate_if(is.character, as.factor)
write.csv(intero_df, 'structures_and_intero_rho.csv', row.names = FALSE)addmargins(xtabs(~ Estructura + Grupo + Sexo, data = intero_df)), , Sexo = Femenino
Grupo
Estructura obeso normopeso Sum
extension 12 5 17
imaginativa 11 11 22
pecho 6 4 10
Sum 29 20 49
, , Sexo = Masculino
Grupo
Estructura obeso normopeso Sum
extension 3 5 8
imaginativa 4 5 9
pecho 4 3 7
Sum 11 13 24
, , Sexo = Sum
Grupo
Estructura obeso normopeso Sum
extension 15 10 25
imaginativa 15 16 31
pecho 10 7 17
Sum 40 33 73
summary(intero_df) Participante ID Estructura Grupo Intero1
101 : 1 N101 : 1 extension :25 obeso :40 Min. :0.007103
102 : 1 N102 : 1 imaginativa:31 normopeso:33 1st Qu.:0.026686
103 : 1 N103 : 1 pecho :17 Median :0.046123
104 : 1 N104 : 1 Mean :0.061715
105 : 1 N105 : 1 3rd Qu.:0.080124
106 : 1 N106 : 1 Max. :0.241604
(Other):67 (Other):67
Sexo log_rho
Femenino :49 Min. :-4.947
Masculino:24 1st Qu.:-3.624
Median :-3.076
Mean :-3.071
3rd Qu.:-2.524
Max. :-1.420
setdiff(rho_df$Participante, struct_df$Participante)[1] 130
setdiff(struct_df$Participante, rho_df$Participante)[1] 136 137 226 242
struct_anova <- aov_ez('Participante', 'log_rho', intero_df, between = c('Estructura', 'Grupo', 'Sexo'))
afex_plot(
struct_anova,
x = 'Estructura',
trace = 'Grupo',
panel = 'Sexo',
error_arg = list(width = .25),
dodge = .3,
data_arg = list(
position =
position_jitterdodge(
jitter.width = .1,
jitter.height = 0,
dodge.width = 0.3 ## needs to be same as dodge
)),
mapping = c('color'),
point_arg = list(size = 3)
)summary(struct_anova)Anova Table (Type 3 tests)
Response: log_rho
num Df den Df MSE F ges Pr(>F)
Estructura 2 61 0.49046 1.5447 0.048206 0.221596
Grupo 1 61 0.49046 0.0277 0.000454 0.868314
Sexo 1 61 0.49046 9.7472 0.137775 0.002745 **
Estructura:Grupo 2 61 0.49046 0.7129 0.022839 0.494267
Estructura:Sexo 2 61 0.49046 1.7172 0.053300 0.188138
Grupo:Sexo 1 61 0.49046 0.8134 0.013159 0.370670
Estructura:Grupo:Sexo 2 61 0.49046 1.4087 0.044149 0.252291
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
a_posteriori_lmer(struct_anova)____________________________________________________________
NOTE: Results may be misleading due to involvement in interactions
$emmeans
Sexo emmean SE df lower.CL upper.CL
Femenino -3.28 0.110 61 -3.5 -3.06
Masculino -2.71 0.146 61 -3.0 -2.42
Results are averaged over the levels of: Estructura, Grupo
Confidence level used: 0.95
$contrasts
contrast estimate SE df t.ratio p.value
Femenino - Masculino -0.57 0.183 61 -3.122 0.0027
Results are averaged over the levels of: Estructura, Grupo