Code
cat("\014") # clean terminalCode
rm(list = ls()) # clean workspace
graphics.off()
library(tidyverse)
library(emmeans)
library(afex)
library(performance)Physiological signals synchrony
cat("\014") # clean terminalrm(list = ls()) # clean workspace
graphics.off()
library(tidyverse)
library(emmeans)
library(afex)
library(performance)my_dodge <- .3
theme_set(
theme_minimal()
)
signals <- c('RSA_P2T', 'RSA_Gates', 'CSI', 'CPI', 'LF', 'HF', 'ECG_Rate', 'RSP_Clean')signal <- signals[1]
sync_df <- read_csv(paste0('../data/sync_physynch_', signal, '.csv'), col_types = cols()) |>
filter(sync_type == 'copresence') |>
mutate(signal = signal, .before = pair) |>
separate_wider_delim(
code_1,
delim = '_',
names = c('duo1', 'subject1', 'sex1', 'task1')) |>
separate_wider_delim(
code_2,
delim = '_',
names = c('duo2', 'subject2', 'sex2', 'task2')) |>
relocate(duo2 , .after = duo1) |>
relocate(subject2, .after = subject1) |>
relocate(sex2 , .after = sex1) |>
relocate(task2 , .after = task1) |>
mutate(
duo_sex = case_when(
sex1 == sex2 & sex1 == 'f' ~ 'female',
sex1 == sex2 & sex1 == 'm' ~ 'male',
sex1 != sex2 ~ 'mix'),
duo_task = case_when(
task1 == task2 & task1 == 'humanity' ~ 'humanity',
task1 == task2 & task1 == 'mindfulness' ~ 'mindfulness',
task1 != task2 ~ 'different'),
sync_group = case_when(
sync_type == 'surrogate' & duo_task == 'different' ~ 'diff_surrogate',
sync_type == 'stimulus' & duo_task == 'different' ~ 'diff_signal',
sync_type == 'surrogate' & duo_task != 'different' ~ 'surrogate_same',
sync_type == 'stimulus' & duo_task == 'humanity' ~ 'apart_humanity',
sync_type == 'stimulus' & duo_task == 'mindfulness' ~ 'apart_mindful',
sync_type == 'copresence' & duo_task == 'humanity' ~ 'together_humanity',
sync_type == 'copresence' & duo_task == 'mindfulness' ~ 'together_mindful'),
) |>
mutate_if(is.character, as.factor) |>
mutate(across(starts_with("member_"), as.factor))options(width = 90)
summary(sync_df) signal pair sync_type sync member_1 member_2
RSA_P2T:32 odd_even:32 copresence:32 Min. :-0.05658 0 : 1 0 : 1
1st Qu.: 0.07323 1 : 1 1 : 1
Median : 0.15719 2 : 1 2 : 1
Mean : 0.13473 3 : 1 3 : 1
3rd Qu.: 0.19003 4 : 1 4 : 1
Max. : 0.28809 5 : 1 5 : 1
(Other):26 (Other):26
duo1 duo2 subject1 subject2 sex1 sex2 task1
d01 : 1 d01 : 1 s01 : 1 s02 : 1 f:16 f:16 humanity :16
d02 : 1 d02 : 1 s03 : 1 s04 : 1 m:16 m:16 mindfulness:16
d03 : 1 d03 : 1 s05 : 1 s06 : 1
d04 : 1 d04 : 1 s07 : 1 s08 : 1
d05 : 1 d05 : 1 s09 : 1 s10 : 1
d06 : 1 d06 : 1 s11 : 1 s12 : 1
(Other):26 (Other):26 (Other):26 (Other):26
task2 duo_sex duo_task sync_group
humanity :16 female:16 humanity :16 together_humanity:16
mindfulness:16 male :16 mindfulness:16 together_mindful :16
sync_lm <- lm(sync ~ duo_task * duo_sex, sync_df[sync_df$sync_type == 'copresence', ])
sync_afex_plot <-
afex_plot(
sync_lm,
x = 'duo_sex',
trace = 'duo_task',
error_arg = list(width = .15),
dodge = .3,
data_arg = list(
position =
position_jitterdodge(
jitter.width = .1,
dodge.width = 0.3 ## needs to be same as dodge
)),
mapping = c('color'),
point_arg = list(size = 4)
)dv column detected: sync
No id column passed. Assuming all rows are independent samples.
suppressWarnings(print(sync_afex_plot))anova(sync_lm)Analysis of Variance Table
Response: sync
Df Sum Sq Mean Sq F value Pr(>F)
duo_task 1 0.000005 0.000005 0.0007 0.97956
duo_sex 1 0.047369 0.047369 6.4172 0.01719 *
duo_task:duo_sex 1 0.019924 0.019924 2.6991 0.11159
Residuals 28 0.206685 0.007382
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
emmeans(sync_lm, specs = pairwise ~ duo_sex)NOTE: Results may be misleading due to involvement in interactions
$emmeans
duo_sex emmean SE df lower.CL upper.CL
female 0.1732 0.0215 28 0.1292 0.217
male 0.0963 0.0215 28 0.0523 0.140
Results are averaged over the levels of: duo_task
Confidence level used: 0.95
$contrasts
contrast estimate SE df t.ratio p.value
female - male 0.0769 0.0304 28 2.533 0.0172
Results are averaged over the levels of: duo_task
check_model(sync_lm)signal <- signals[2]
sync_df <- read_csv(paste0('../data/sync_physynch_', signal, '.csv'), col_types = cols()) |>
filter(sync_type == 'copresence') |>
mutate(signal = signal, .before = pair) |>
separate_wider_delim(
code_1,
delim = '_',
names = c('duo1', 'subject1', 'sex1', 'task1')) |>
separate_wider_delim(
code_2,
delim = '_',
names = c('duo2', 'subject2', 'sex2', 'task2')) |>
relocate(duo2 , .after = duo1) |>
relocate(subject2, .after = subject1) |>
relocate(sex2 , .after = sex1) |>
relocate(task2 , .after = task1) |>
mutate(
duo_sex = case_when(
sex1 == sex2 & sex1 == 'f' ~ 'female',
sex1 == sex2 & sex1 == 'm' ~ 'male',
sex1 != sex2 ~ 'mix'),
duo_task = case_when(
task1 == task2 & task1 == 'humanity' ~ 'humanity',
task1 == task2 & task1 == 'mindfulness' ~ 'mindfulness',
task1 != task2 ~ 'different'),
sync_group = case_when(
sync_type == 'surrogate' & duo_task == 'different' ~ 'diff_surrogate',
sync_type == 'stimulus' & duo_task == 'different' ~ 'diff_signal',
sync_type == 'surrogate' & duo_task != 'different' ~ 'surrogate_same',
sync_type == 'stimulus' & duo_task == 'humanity' ~ 'apart_humanity',
sync_type == 'stimulus' & duo_task == 'mindfulness' ~ 'apart_mindful',
sync_type == 'copresence' & duo_task == 'humanity' ~ 'together_humanity',
sync_type == 'copresence' & duo_task == 'mindfulness' ~ 'together_mindful'),
) |>
mutate_if(is.character, as.factor) |>
mutate(across(starts_with("member_"), as.factor))options(width = 90)
summary(sync_df) signal pair sync_type sync member_1
RSA_Gates:32 odd_even:32 copresence:32 Min. :-0.13738 0 : 1
1st Qu.: 0.01843 1 : 1
Median : 0.11238 2 : 1
Mean : 0.09214 3 : 1
3rd Qu.: 0.14770 4 : 1
Max. : 0.23911 5 : 1
(Other):26
member_2 duo1 duo2 subject1 subject2 sex1 sex2
0 : 1 d01 : 1 d01 : 1 s01 : 1 s02 : 1 f:16 f:16
1 : 1 d02 : 1 d02 : 1 s03 : 1 s04 : 1 m:16 m:16
2 : 1 d03 : 1 d03 : 1 s05 : 1 s06 : 1
3 : 1 d04 : 1 d04 : 1 s07 : 1 s08 : 1
4 : 1 d05 : 1 d05 : 1 s09 : 1 s10 : 1
5 : 1 d06 : 1 d06 : 1 s11 : 1 s12 : 1
(Other):26 (Other):26 (Other):26 (Other):26 (Other):26
task1 task2 duo_sex duo_task sync_group
humanity :16 humanity :16 female:16 humanity :16 together_humanity:16
mindfulness:16 mindfulness:16 male :16 mindfulness:16 together_mindful :16
sync_lm <- lm(sync ~ duo_task * duo_sex, sync_df[sync_df$sync_type == 'copresence', ])
sync_afex_plot <-
afex_plot(
sync_lm,
x = 'duo_sex',
trace = 'duo_task',
error_arg = list(width = .15),
dodge = .3,
data_arg = list(
position =
position_jitterdodge(
jitter.width = .1,
dodge.width = 0.3 ## needs to be same as dodge
)),
mapping = c('color'),
point_arg = list(size = 4)
)dv column detected: sync
No id column passed. Assuming all rows are independent samples.
suppressWarnings(print(sync_afex_plot))anova(sync_lm)Analysis of Variance Table
Response: sync
Df Sum Sq Mean Sq F value Pr(>F)
duo_task 1 0.005180 0.005180 0.7919 0.38109
duo_sex 1 0.042611 0.042611 6.5141 0.01644 *
duo_task:duo_sex 1 0.004948 0.004948 0.7564 0.39185
Residuals 28 0.183158 0.006541
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
emmeans(sync_lm, specs = pairwise ~ duo_sex)NOTE: Results may be misleading due to involvement in interactions
$emmeans
duo_sex emmean SE df lower.CL upper.CL
female 0.1286 0.0202 28 0.0872 0.1701
male 0.0557 0.0202 28 0.0142 0.0971
Results are averaged over the levels of: duo_task
Confidence level used: 0.95
$contrasts
contrast estimate SE df t.ratio p.value
female - male 0.073 0.0286 28 2.552 0.0164
Results are averaged over the levels of: duo_task
check_model(sync_lm)signal <- signals[3]
sync_df <- read_csv(paste0('../data/sync_physynch_', signal, '.csv'), col_types = cols()) |>
filter(sync_type == 'copresence') |>
mutate(signal = signal, .before = pair) |>
separate_wider_delim(
code_1,
delim = '_',
names = c('duo1', 'subject1', 'sex1', 'task1')) |>
separate_wider_delim(
code_2,
delim = '_',
names = c('duo2', 'subject2', 'sex2', 'task2')) |>
relocate(duo2 , .after = duo1) |>
relocate(subject2, .after = subject1) |>
relocate(sex2 , .after = sex1) |>
relocate(task2 , .after = task1) |>
mutate(
duo_sex = case_when(
sex1 == sex2 & sex1 == 'f' ~ 'female',
sex1 == sex2 & sex1 == 'm' ~ 'male',
sex1 != sex2 ~ 'mix'),
duo_task = case_when(
task1 == task2 & task1 == 'humanity' ~ 'humanity',
task1 == task2 & task1 == 'mindfulness' ~ 'mindfulness',
task1 != task2 ~ 'different'),
sync_group = case_when(
sync_type == 'surrogate' & duo_task == 'different' ~ 'diff_surrogate',
sync_type == 'stimulus' & duo_task == 'different' ~ 'diff_signal',
sync_type == 'surrogate' & duo_task != 'different' ~ 'surrogate_same',
sync_type == 'stimulus' & duo_task == 'humanity' ~ 'apart_humanity',
sync_type == 'stimulus' & duo_task == 'mindfulness' ~ 'apart_mindful',
sync_type == 'copresence' & duo_task == 'humanity' ~ 'together_humanity',
sync_type == 'copresence' & duo_task == 'mindfulness' ~ 'together_mindful'),
) |>
mutate_if(is.character, as.factor) |>
mutate(across(starts_with("member_"), as.factor))options(width = 90)
summary(sync_df) signal pair sync_type sync member_1 member_2
CSI:32 odd_even:32 copresence:32 Min. :-0.19359 0 : 1 0 : 1
1st Qu.:-0.02251 1 : 1 1 : 1
Median : 0.08421 2 : 1 2 : 1
Mean : 0.09928 3 : 1 3 : 1
3rd Qu.: 0.19844 4 : 1 4 : 1
Max. : 0.47948 5 : 1 5 : 1
(Other):26 (Other):26
duo1 duo2 subject1 subject2 sex1 sex2 task1
d01 : 1 d01 : 1 s01 : 1 s02 : 1 f:16 f:16 humanity :16
d02 : 1 d02 : 1 s03 : 1 s04 : 1 m:16 m:16 mindfulness:16
d03 : 1 d03 : 1 s05 : 1 s06 : 1
d04 : 1 d04 : 1 s07 : 1 s08 : 1
d05 : 1 d05 : 1 s09 : 1 s10 : 1
d06 : 1 d06 : 1 s11 : 1 s12 : 1
(Other):26 (Other):26 (Other):26 (Other):26
task2 duo_sex duo_task sync_group
humanity :16 female:16 humanity :16 together_humanity:16
mindfulness:16 male :16 mindfulness:16 together_mindful :16
sync_lm <- lm(sync ~ duo_task * duo_sex, sync_df[sync_df$sync_type == 'copresence', ])
sync_afex_plot <-
afex_plot(
sync_lm,
x = 'duo_sex',
trace = 'duo_task',
error_arg = list(width = .15),
dodge = .3,
data_arg = list(
position =
position_jitterdodge(
jitter.width = .1,
dodge.width = 0.3 ## needs to be same as dodge
)),
mapping = c('color'),
point_arg = list(size = 4)
)dv column detected: sync
No id column passed. Assuming all rows are independent samples.
suppressWarnings(print(sync_afex_plot))anova(sync_lm)Analysis of Variance Table
Response: sync
Df Sum Sq Mean Sq F value Pr(>F)
duo_task 1 0.05086 0.050858 1.8794 0.18129
duo_sex 1 0.09185 0.091847 3.3942 0.07604 .
duo_task:duo_sex 1 0.00304 0.003045 0.1125 0.73979
Residuals 28 0.75768 0.027060
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
check_model(sync_lm)signal <- signals[4]
sync_df <- read_csv(paste0('../data/sync_physynch_', signal, '.csv'), col_types = cols()) |>
filter(sync_type == 'copresence') |>
mutate(signal = signal, .before = pair) |>
separate_wider_delim(
code_1,
delim = '_',
names = c('duo1', 'subject1', 'sex1', 'task1')) |>
separate_wider_delim(
code_2,
delim = '_',
names = c('duo2', 'subject2', 'sex2', 'task2')) |>
relocate(duo2 , .after = duo1) |>
relocate(subject2, .after = subject1) |>
relocate(sex2 , .after = sex1) |>
relocate(task2 , .after = task1) |>
mutate(
duo_sex = case_when(
sex1 == sex2 & sex1 == 'f' ~ 'female',
sex1 == sex2 & sex1 == 'm' ~ 'male',
sex1 != sex2 ~ 'mix'),
duo_task = case_when(
task1 == task2 & task1 == 'humanity' ~ 'humanity',
task1 == task2 & task1 == 'mindfulness' ~ 'mindfulness',
task1 != task2 ~ 'different'),
sync_group = case_when(
sync_type == 'surrogate' & duo_task == 'different' ~ 'diff_surrogate',
sync_type == 'stimulus' & duo_task == 'different' ~ 'diff_signal',
sync_type == 'surrogate' & duo_task != 'different' ~ 'surrogate_same',
sync_type == 'stimulus' & duo_task == 'humanity' ~ 'apart_humanity',
sync_type == 'stimulus' & duo_task == 'mindfulness' ~ 'apart_mindful',
sync_type == 'copresence' & duo_task == 'humanity' ~ 'together_humanity',
sync_type == 'copresence' & duo_task == 'mindfulness' ~ 'together_mindful'),
) |>
mutate_if(is.character, as.factor) |>
mutate(across(starts_with("member_"), as.factor))options(width = 90)
summary(sync_df) signal pair sync_type sync member_1 member_2
CPI:32 odd_even:32 copresence:32 Min. :-0.229466 0 : 1 0 : 1
1st Qu.:-0.002515 1 : 1 1 : 1
Median : 0.101327 2 : 1 2 : 1
Mean : 0.091871 3 : 1 3 : 1
3rd Qu.: 0.181570 4 : 1 4 : 1
Max. : 0.316338 5 : 1 5 : 1
(Other):26 (Other):26
duo1 duo2 subject1 subject2 sex1 sex2 task1
d01 : 1 d01 : 1 s01 : 1 s02 : 1 f:16 f:16 humanity :16
d02 : 1 d02 : 1 s03 : 1 s04 : 1 m:16 m:16 mindfulness:16
d03 : 1 d03 : 1 s05 : 1 s06 : 1
d04 : 1 d04 : 1 s07 : 1 s08 : 1
d05 : 1 d05 : 1 s09 : 1 s10 : 1
d06 : 1 d06 : 1 s11 : 1 s12 : 1
(Other):26 (Other):26 (Other):26 (Other):26
task2 duo_sex duo_task sync_group
humanity :16 female:16 humanity :16 together_humanity:16
mindfulness:16 male :16 mindfulness:16 together_mindful :16
sync_lm <- lm(sync ~ duo_task * duo_sex, sync_df[sync_df$sync_type == 'copresence', ])
sync_afex_plot <-
afex_plot(
sync_lm,
x = 'duo_sex',
trace = 'duo_task',
error_arg = list(width = .15),
dodge = .3,
data_arg = list(
position =
position_jitterdodge(
jitter.width = .1,
dodge.width = 0.3 ## needs to be same as dodge
)),
mapping = c('color'),
point_arg = list(size = 4)
)dv column detected: sync
No id column passed. Assuming all rows are independent samples.
suppressWarnings(print(sync_afex_plot))anova(sync_lm)Analysis of Variance Table
Response: sync
Df Sum Sq Mean Sq F value Pr(>F)
duo_task 1 0.01552 0.015522 0.9967 0.3267
duo_sex 1 0.04294 0.042935 2.7569 0.1080
duo_task:duo_sex 1 0.03486 0.034862 2.2385 0.1458
Residuals 28 0.43606 0.015574
check_model(sync_lm)signal <- signals[5]
sync_df <- read_csv(paste0('../data/sync_physynch_', signal, '.csv'), col_types = cols()) |>
filter(sync_type == 'copresence') |>
mutate(signal = signal, .before = pair) |>
separate_wider_delim(
code_1,
delim = '_',
names = c('duo1', 'subject1', 'sex1', 'task1')) |>
separate_wider_delim(
code_2,
delim = '_',
names = c('duo2', 'subject2', 'sex2', 'task2')) |>
relocate(duo2 , .after = duo1) |>
relocate(subject2, .after = subject1) |>
relocate(sex2 , .after = sex1) |>
relocate(task2 , .after = task1) |>
mutate(
duo_sex = case_when(
sex1 == sex2 & sex1 == 'f' ~ 'female',
sex1 == sex2 & sex1 == 'm' ~ 'male',
sex1 != sex2 ~ 'mix'),
duo_task = case_when(
task1 == task2 & task1 == 'humanity' ~ 'humanity',
task1 == task2 & task1 == 'mindfulness' ~ 'mindfulness',
task1 != task2 ~ 'different'),
sync_group = case_when(
sync_type == 'surrogate' & duo_task == 'different' ~ 'diff_surrogate',
sync_type == 'stimulus' & duo_task == 'different' ~ 'diff_signal',
sync_type == 'surrogate' & duo_task != 'different' ~ 'surrogate_same',
sync_type == 'stimulus' & duo_task == 'humanity' ~ 'apart_humanity',
sync_type == 'stimulus' & duo_task == 'mindfulness' ~ 'apart_mindful',
sync_type == 'copresence' & duo_task == 'humanity' ~ 'together_humanity',
sync_type == 'copresence' & duo_task == 'mindfulness' ~ 'together_mindful'),
) |>
mutate_if(is.character, as.factor) |>
mutate(across(starts_with("member_"), as.factor))options(width = 90)
summary(sync_df) signal pair sync_type sync member_1 member_2
LF:32 odd_even:32 copresence:32 Min. :-0.20840 0 : 1 0 : 1
1st Qu.: 0.05293 1 : 1 1 : 1
Median : 0.24261 2 : 1 2 : 1
Mean : 0.20168 3 : 1 3 : 1
3rd Qu.: 0.33118 4 : 1 4 : 1
Max. : 0.65627 5 : 1 5 : 1
(Other):26 (Other):26
duo1 duo2 subject1 subject2 sex1 sex2 task1
d01 : 1 d01 : 1 s01 : 1 s02 : 1 f:16 f:16 humanity :16
d02 : 1 d02 : 1 s03 : 1 s04 : 1 m:16 m:16 mindfulness:16
d03 : 1 d03 : 1 s05 : 1 s06 : 1
d04 : 1 d04 : 1 s07 : 1 s08 : 1
d05 : 1 d05 : 1 s09 : 1 s10 : 1
d06 : 1 d06 : 1 s11 : 1 s12 : 1
(Other):26 (Other):26 (Other):26 (Other):26
task2 duo_sex duo_task sync_group
humanity :16 female:16 humanity :16 together_humanity:16
mindfulness:16 male :16 mindfulness:16 together_mindful :16
sync_lm <- lm(sync ~ duo_task * duo_sex, sync_df[sync_df$sync_type == 'copresence', ])
sync_afex_plot <-
afex_plot(
sync_lm,
x = 'duo_sex',
trace = 'duo_task',
error_arg = list(width = .15),
dodge = .3,
data_arg = list(
position =
position_jitterdodge(
jitter.width = .1,
dodge.width = 0.3 ## needs to be same as dodge
)),
mapping = c('color'),
point_arg = list(size = 4)
)dv column detected: sync
No id column passed. Assuming all rows are independent samples.
suppressWarnings(print(sync_afex_plot))anova(sync_lm)Analysis of Variance Table
Response: sync
Df Sum Sq Mean Sq F value Pr(>F)
duo_task 1 0.03428 0.034283 0.7840 0.3835
duo_sex 1 0.03090 0.030903 0.7067 0.4077
duo_task:duo_sex 1 0.02114 0.021135 0.4833 0.4927
Residuals 28 1.22442 0.043729
check_model(sync_lm)signal <- signals[6]
sync_df <- read_csv(paste0('../data/sync_physynch_', signal, '.csv'), col_types = cols()) |>
filter(sync_type == 'copresence') |>
mutate(signal = signal, .before = pair) |>
separate_wider_delim(
code_1,
delim = '_',
names = c('duo1', 'subject1', 'sex1', 'task1')) |>
separate_wider_delim(
code_2,
delim = '_',
names = c('duo2', 'subject2', 'sex2', 'task2')) |>
relocate(duo2 , .after = duo1) |>
relocate(subject2, .after = subject1) |>
relocate(sex2 , .after = sex1) |>
relocate(task2 , .after = task1) |>
mutate(
duo_sex = case_when(
sex1 == sex2 & sex1 == 'f' ~ 'female',
sex1 == sex2 & sex1 == 'm' ~ 'male',
sex1 != sex2 ~ 'mix'),
duo_task = case_when(
task1 == task2 & task1 == 'humanity' ~ 'humanity',
task1 == task2 & task1 == 'mindfulness' ~ 'mindfulness',
task1 != task2 ~ 'different'),
sync_group = case_when(
sync_type == 'surrogate' & duo_task == 'different' ~ 'diff_surrogate',
sync_type == 'stimulus' & duo_task == 'different' ~ 'diff_signal',
sync_type == 'surrogate' & duo_task != 'different' ~ 'surrogate_same',
sync_type == 'stimulus' & duo_task == 'humanity' ~ 'apart_humanity',
sync_type == 'stimulus' & duo_task == 'mindfulness' ~ 'apart_mindful',
sync_type == 'copresence' & duo_task == 'humanity' ~ 'together_humanity',
sync_type == 'copresence' & duo_task == 'mindfulness' ~ 'together_mindful'),
) |>
mutate_if(is.character, as.factor) |>
mutate(across(starts_with("member_"), as.factor))options(width = 90)
summary(sync_df) signal pair sync_type sync member_1 member_2
HF:32 odd_even:32 copresence:32 Min. :-0.36551 0 : 1 0 : 1
1st Qu.:-0.09444 1 : 1 1 : 1
Median : 0.05782 2 : 1 2 : 1
Mean : 0.05085 3 : 1 3 : 1
3rd Qu.: 0.21971 4 : 1 4 : 1
Max. : 0.48689 5 : 1 5 : 1
(Other):26 (Other):26
duo1 duo2 subject1 subject2 sex1 sex2 task1
d01 : 1 d01 : 1 s01 : 1 s02 : 1 f:16 f:16 humanity :16
d02 : 1 d02 : 1 s03 : 1 s04 : 1 m:16 m:16 mindfulness:16
d03 : 1 d03 : 1 s05 : 1 s06 : 1
d04 : 1 d04 : 1 s07 : 1 s08 : 1
d05 : 1 d05 : 1 s09 : 1 s10 : 1
d06 : 1 d06 : 1 s11 : 1 s12 : 1
(Other):26 (Other):26 (Other):26 (Other):26
task2 duo_sex duo_task sync_group
humanity :16 female:16 humanity :16 together_humanity:16
mindfulness:16 male :16 mindfulness:16 together_mindful :16
sync_lm <- lm(sync ~ duo_task * duo_sex, sync_df[sync_df$sync_type == 'copresence', ])
sync_afex_plot <-
afex_plot(
sync_lm,
x = 'duo_sex',
trace = 'duo_task',
error_arg = list(width = .15),
dodge = .3,
data_arg = list(
position =
position_jitterdodge(
jitter.width = .1,
dodge.width = 0.3 ## needs to be same as dodge
)),
mapping = c('color'),
point_arg = list(size = 4)
)dv column detected: sync
No id column passed. Assuming all rows are independent samples.
suppressWarnings(print(sync_afex_plot))anova(sync_lm)Analysis of Variance Table
Response: sync
Df Sum Sq Mean Sq F value Pr(>F)
duo_task 1 0.01923 0.019230 0.4386 0.5132
duo_sex 1 0.06214 0.062138 1.4172 0.2439
duo_task:duo_sex 1 0.08633 0.086328 1.9689 0.1716
Residuals 28 1.22765 0.043845
check_model(sync_lm)signal <- signals[7]
sync_df <- read_csv(paste0('../data/sync_physynch_', signal, '.csv'), col_types = cols()) |>
filter(sync_type == 'copresence') |>
mutate(signal = signal, .before = pair) |>
separate_wider_delim(
code_1,
delim = '_',
names = c('duo1', 'subject1', 'sex1', 'task1')) |>
separate_wider_delim(
code_2,
delim = '_',
names = c('duo2', 'subject2', 'sex2', 'task2')) |>
relocate(duo2 , .after = duo1) |>
relocate(subject2, .after = subject1) |>
relocate(sex2 , .after = sex1) |>
relocate(task2 , .after = task1) |>
mutate(
duo_sex = case_when(
sex1 == sex2 & sex1 == 'f' ~ 'female',
sex1 == sex2 & sex1 == 'm' ~ 'male',
sex1 != sex2 ~ 'mix'),
duo_task = case_when(
task1 == task2 & task1 == 'humanity' ~ 'humanity',
task1 == task2 & task1 == 'mindfulness' ~ 'mindfulness',
task1 != task2 ~ 'different'),
sync_group = case_when(
sync_type == 'surrogate' & duo_task == 'different' ~ 'diff_surrogate',
sync_type == 'stimulus' & duo_task == 'different' ~ 'diff_signal',
sync_type == 'surrogate' & duo_task != 'different' ~ 'surrogate_same',
sync_type == 'stimulus' & duo_task == 'humanity' ~ 'apart_humanity',
sync_type == 'stimulus' & duo_task == 'mindfulness' ~ 'apart_mindful',
sync_type == 'copresence' & duo_task == 'humanity' ~ 'together_humanity',
sync_type == 'copresence' & duo_task == 'mindfulness' ~ 'together_mindful'),
) |>
mutate_if(is.character, as.factor) |>
mutate(across(starts_with("member_"), as.factor))options(width = 90)
summary(sync_df) signal pair sync_type sync member_1 member_2
ECG_Rate:32 odd_even:32 copresence:32 Min. :-0.04987 0 : 1 0 : 1
1st Qu.: 0.03558 1 : 1 1 : 1
Median : 0.09916 2 : 1 2 : 1
Mean : 0.09970 3 : 1 3 : 1
3rd Qu.: 0.15375 4 : 1 4 : 1
Max. : 0.31270 5 : 1 5 : 1
(Other):26 (Other):26
duo1 duo2 subject1 subject2 sex1 sex2 task1
d01 : 1 d01 : 1 s01 : 1 s02 : 1 f:16 f:16 humanity :16
d02 : 1 d02 : 1 s03 : 1 s04 : 1 m:16 m:16 mindfulness:16
d03 : 1 d03 : 1 s05 : 1 s06 : 1
d04 : 1 d04 : 1 s07 : 1 s08 : 1
d05 : 1 d05 : 1 s09 : 1 s10 : 1
d06 : 1 d06 : 1 s11 : 1 s12 : 1
(Other):26 (Other):26 (Other):26 (Other):26
task2 duo_sex duo_task sync_group
humanity :16 female:16 humanity :16 together_humanity:16
mindfulness:16 male :16 mindfulness:16 together_mindful :16
sync_lm <- lm(sync ~ duo_task * duo_sex, sync_df[sync_df$sync_type == 'copresence', ])
sync_afex_plot <-
afex_plot(
sync_lm,
x = 'duo_sex',
trace = 'duo_task',
error_arg = list(width = .15),
dodge = .3,
data_arg = list(
position =
position_jitterdodge(
jitter.width = .1,
dodge.width = 0.3 ## needs to be same as dodge
)),
mapping = c('color'),
point_arg = list(size = 4)
)dv column detected: sync
No id column passed. Assuming all rows are independent samples.
suppressWarnings(print(sync_afex_plot))anova(sync_lm)Analysis of Variance Table
Response: sync
Df Sum Sq Mean Sq F value Pr(>F)
duo_task 1 0.013803 0.0138028 1.8413 0.1856
duo_sex 1 0.020996 0.0209959 2.8009 0.1053
duo_task:duo_sex 1 0.000014 0.0000143 0.0019 0.9655
Residuals 28 0.209888 0.0074960
check_model(sync_lm)signal <- signals[8]
sync_df <- read_csv(paste0('../data/sync_physynch_', signal, '.csv'), col_types = cols()) |>
filter(sync_type == 'copresence') |>
mutate(signal = signal, .before = pair) |>
separate_wider_delim(
code_1,
delim = '_',
names = c('duo1', 'subject1', 'sex1', 'task1')) |>
separate_wider_delim(
code_2,
delim = '_',
names = c('duo2', 'subject2', 'sex2', 'task2')) |>
relocate(duo2 , .after = duo1) |>
relocate(subject2, .after = subject1) |>
relocate(sex2 , .after = sex1) |>
relocate(task2 , .after = task1) |>
mutate(
duo_sex = case_when(
sex1 == sex2 & sex1 == 'f' ~ 'female',
sex1 == sex2 & sex1 == 'm' ~ 'male',
sex1 != sex2 ~ 'mix'),
duo_task = case_when(
task1 == task2 & task1 == 'humanity' ~ 'humanity',
task1 == task2 & task1 == 'mindfulness' ~ 'mindfulness',
task1 != task2 ~ 'different'),
sync_group = case_when(
sync_type == 'surrogate' & duo_task == 'different' ~ 'diff_surrogate',
sync_type == 'stimulus' & duo_task == 'different' ~ 'diff_signal',
sync_type == 'surrogate' & duo_task != 'different' ~ 'surrogate_same',
sync_type == 'stimulus' & duo_task == 'humanity' ~ 'apart_humanity',
sync_type == 'stimulus' & duo_task == 'mindfulness' ~ 'apart_mindful',
sync_type == 'copresence' & duo_task == 'humanity' ~ 'together_humanity',
sync_type == 'copresence' & duo_task == 'mindfulness' ~ 'together_mindful'),
) |>
mutate_if(is.character, as.factor) |>
mutate(across(starts_with("member_"), as.factor))options(width = 90)
summary(sync_df) signal pair sync_type sync member_1
RSP_Clean:32 odd_even:32 copresence:32 Min. :0.001547 0 : 1
1st Qu.:0.029767 1 : 1
Median :0.047256 2 : 1
Mean :0.070275 3 : 1
3rd Qu.:0.101480 4 : 1
Max. :0.229147 5 : 1
(Other):26
member_2 duo1 duo2 subject1 subject2 sex1 sex2
0 : 1 d01 : 1 d01 : 1 s01 : 1 s02 : 1 f:16 f:16
1 : 1 d02 : 1 d02 : 1 s03 : 1 s04 : 1 m:16 m:16
2 : 1 d03 : 1 d03 : 1 s05 : 1 s06 : 1
3 : 1 d04 : 1 d04 : 1 s07 : 1 s08 : 1
4 : 1 d05 : 1 d05 : 1 s09 : 1 s10 : 1
5 : 1 d06 : 1 d06 : 1 s11 : 1 s12 : 1
(Other):26 (Other):26 (Other):26 (Other):26 (Other):26
task1 task2 duo_sex duo_task sync_group
humanity :16 humanity :16 female:16 humanity :16 together_humanity:16
mindfulness:16 mindfulness:16 male :16 mindfulness:16 together_mindful :16
sync_lm <- lm(sync ~ duo_task * duo_sex, sync_df[sync_df$sync_type == 'copresence', ])
sync_afex_plot <-
afex_plot(
sync_lm,
x = 'duo_sex',
trace = 'duo_task',
error_arg = list(width = .15),
dodge = .3,
data_arg = list(
position =
position_jitterdodge(
jitter.width = .1,
dodge.width = 0.3 ## needs to be same as dodge
)),
mapping = c('color'),
point_arg = list(size = 4)
)dv column detected: sync
No id column passed. Assuming all rows are independent samples.
suppressWarnings(print(sync_afex_plot))anova(sync_lm)Analysis of Variance Table
Response: sync
Df Sum Sq Mean Sq F value Pr(>F)
duo_task 1 0.006939 0.0069388 2.0004 0.1683
duo_sex 1 0.001271 0.0012710 0.3664 0.5498
duo_task:duo_sex 1 0.002287 0.0022871 0.6594 0.4236
Residuals 28 0.097124 0.0034687
check_model(sync_lm)