── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.5.1 ✔ tibble 3.2.1
✔ lubridate 1.9.3 ✔ tidyr 1.3.1
✔ purrr 1.0.2
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
here() starts at /Users/visuallearninglab/Documents/visvocab
Load data
looking_time_resampled_clean <- read.csv(here("data","processed_data","looking_times_resampled_clean.csv"))
all_looking_times <- read.csv(here("data","processed_data","looking_times_with_exclusion_info.csv"))Overall timecourse plot of proportion target looking
#summarizing within subject for each time point
summarize_subj <- looking_time_resampled_clean %>%
filter(trial_exclusion == 0 & exclude_participant ==0 & exclude_participant_insufficient_data == 0) %>%
group_by(SubjectInfo.subjID, time_normalized_corrected) %>%
summarize(N=n(),
non_na_n = sum(!is.na(accuracy_transformed)),
mean_accuracy=mean(accuracy_transformed,na.rm=TRUE),
sd_accuracy=sd(accuracy_transformed,na.rm=TRUE),
se_accuracy=sd_accuracy/sqrt(non_na_n),
ci=qt(0.975, non_na_n-1)*sd(accuracy_transformed,na.rm=T)/sqrt(non_na_n),
lower_ci=mean_accuracy-ci,
upper_ci=mean_accuracy+ci) %>%
filter(non_na_n > 10) %>%
ungroup()Warning: There were 90 warnings in `summarize()`.
The first warning was:
ℹ In argument: `ci = qt(0.975, non_na_n - 1) * sd(accuracy_transformed, na.rm =
T)/sqrt(non_na_n)`.
ℹ In group 1: `SubjectInfo.subjID = "AWMRW7"` and `time_normalized_corrected =
-3467`.
Caused by warning in `qt()`:
! NaNs produced
ℹ Run `dplyr::last_dplyr_warnings()` to see the 89 remaining warnings.
`summarise()` has grouped output by 'SubjectInfo.subjID'. You can override
using the `.groups` argument.
#summarizing across subjects for each time point
summarize_across_subj <- summarize_subj %>%
group_by(time_normalized_corrected) %>%
dplyr::summarize(n=n(),
accuracy=mean(mean_accuracy,na.rm=TRUE),
sd_accuracy=sd(mean_accuracy,na.rm=TRUE),
se_accuracy=sd_accuracy/sqrt(n)) %>%
filter(n > 2)
looking_times <- ggplot(summarize_across_subj,aes(time_normalized_corrected,accuracy))+
xlim(-2000,4000)+
geom_errorbar(aes(ymin=accuracy-se_accuracy,ymax=accuracy+se_accuracy),width=0, alpha=0.2)+
#geom_point(alpha=0.2)+
geom_smooth(method="gam")+
geom_vline(xintercept=0,size=1.5)+
geom_hline(yintercept=0.5,size=1.2,linetype="dashed")+
geom_vline(xintercept=300,linetype="dotted")+
ylim(0,1)+
xlab("Time (normalized to target word onset) in ms")+
ylab("Proportion Target Looking")Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.
ggsave(here("data","figures","prop_looking_across_time.png"),looking_times,width=9,height=6,bg = "white")`geom_smooth()` using formula = 'y ~ s(x, bs = "cs")'
Warning: Removed 25 rows containing non-finite outside the scale range
(`stat_smooth()`).
Proprtion of target looking for easy vs hard trials
#Overall baseline-corrected proportion target looking by condition
looking_data_summarized <- all_looking_times |>
filter(trial_exclusion == 0 & exclude_participant == 0 & exclude_participant_insufficient_data == 0) |>
distinct(Trials.trialID, SubjectInfo.subjID, .keep_all = TRUE)
avg_corrected_target_looking_by_condition <- looking_data_summarized %>%
group_by(SubjectInfo.subjID, Trials.trialType) %>%
summarize(N=n(),
#mean_age = mean(age),
#mean_age_mo = mean(age_mo),
average_corrected_target_looking=mean(corrected_target_looking,na.rm=TRUE),
se=sd(corrected_target_looking,na.rm=T)/sqrt(N),
ci=qt(0.975, N-1)*sd(corrected_target_looking,na.rm=T)/sqrt(N),
lower_ci=average_corrected_target_looking-ci,
upper_ci=average_corrected_target_looking+ci,
lower_se=average_corrected_target_looking-se,
upper_se=average_corrected_target_looking+se,
average_critical_window_looking=mean(mean_target_looking_critical_window,na.rm=TRUE),
critical_window_ci = qt(0.975, N-1)*sd(mean_target_looking_critical_window,na.rm=T)/sqrt(N),
critical_window_lower_ci=average_critical_window_looking-critical_window_ci,
critical_window_upper_ci=average_critical_window_looking+critical_window_ci)`summarise()` has grouped output by 'SubjectInfo.subjID'. You can override
using the `.groups` argument.
#baseline-corrected target looking summarized overall
overall_corrected_target_looking_by_condition <- avg_corrected_target_looking_by_condition %>%
group_by(Trials.trialType) %>%
summarize(N=n(),
corrected_target_looking=mean(average_corrected_target_looking,na.rm=TRUE),
ci=qt(0.975, N-1)*sd(average_corrected_target_looking,na.rm=T)/sqrt(N),
lower_ci=corrected_target_looking-ci,
upper_ci=corrected_target_looking+ci)
overall_corrected_target_looking_by_condition %>%
knitr::kable()| Trials.trialType | N | corrected_target_looking | ci | lower_ci | upper_ci |
|---|---|---|---|---|---|
| easy | 4 | -0.0603453 | 0.3131527 | -0.3734980 | 0.2528074 |
| easy-distractor | 4 | 0.1480169 | 0.2753286 | -0.1273117 | 0.4233455 |
| hard | 4 | 0.1128454 | 0.1298915 | -0.0170461 | 0.2427368 |
| hard-distractor | 4 | 0.0429219 | 0.3310093 | -0.2880874 | 0.3739312 |
set.seed(2)
avg_corrected_target_looking_by_condition <- avg_corrected_target_looking_by_condition |> filter(Trials.trialType == "easy" | Trials.trialType == "hard")
overall_corrected_target_looking_by_condition <- overall_corrected_target_looking_by_condition |>
filter(Trials.trialType == "easy" | Trials.trialType == "hard")
jitterer <- position_jitter(width = .05,seed=1)
overall_condition_plot <- ggplot(avg_corrected_target_looking_by_condition, aes(x=Trials.trialType,y=average_corrected_target_looking, fill=Trials.trialType))+
geom_half_violin(data=filter(avg_corrected_target_looking_by_condition, Trials.trialType=="easy"),position = position_nudge(x = -.1, y = 0), width=1,trim = FALSE, alpha = .8,color=NA,side="l")+
geom_half_violin(data=filter(avg_corrected_target_looking_by_condition, Trials.trialType=="hard"),position = position_nudge(x = .1, y = 0), width=1,trim = FALSE, alpha = .8,color=NA,side="r")+
geom_path(aes(group=SubjectInfo.subjID),color="black",fill=NA,alpha=0.15,size=0.75,position=jitterer)+ geom_point(aes(color=Trials.trialType,group=SubjectInfo.subjID), size = 2.5, alpha=0.15,position=jitterer)+
geom_point(data=overall_corrected_target_looking_by_condition,aes(y=corrected_target_looking),color="black",size=5)+
geom_line(data=overall_corrected_target_looking_by_condition,aes(y=corrected_target_looking,group=1),color="black",size=3)+
geom_errorbar(data=overall_corrected_target_looking_by_condition,aes(y=corrected_target_looking,ymin=lower_ci,ymax=upper_ci),width=0,size=1.2,color="black")+
geom_hline(yintercept=0,linetype="dashed")+
theme(legend.position="none")+
xlab("Distractor Difficulty Condition")+
ylab("Baseline-Corrected\nProportion Target Looking")+
theme(axis.title.x = element_text(face="bold", size=20),
axis.text.x = element_text(size=14),
axis.title.y = element_text(face="bold", size=20),
axis.text.y = element_text(size=16),
strip.text.x = element_text(size = 16,face="bold"))Warning in geom_path(aes(group = SubjectInfo.subjID), color = "black", fill =
NA, : Ignoring unknown parameters: `fill`
overall_condition_plotggsave(here("data","figures","condition_based_looking.png"),overall_condition_plot,width=9,height=6,bg = "white")Target image difficulty
# summarize average accuracy within participant (by word alone)
condition_based_looking <- looking_data_summarized |>
filter(!grepl("distractor", Trials.trialType)) |>
distinct(SubjectInfo.subjID, Trials.trialID, Trials.targetImage, Trials.leftImage, Trials.rightImage, corrected_target_looking)
target_looking_by_target_word <- looking_data_summarized |>
filter(!grepl("distractor", Trials.trialType)) |>
group_by(SubjectInfo.subjID, Trials.targetImage) |>
summarize(target_looking_diff = corrected_target_looking[match("easy", Trials.trialType)] - corrected_target_looking[match("hard", Trials.trialType)],
baseline_window_looking_diff = mean_target_looking_baseline_window[match("easy", Trials.trialType)] - mean_target_looking_baseline_window[match("hard", Trials.trialType)],
critical_window_looking_diff = mean_target_looking_critical_window[match("easy", Trials.trialType)] - mean_target_looking_critical_window[match("hard", Trials.trialType)])`summarise()` has grouped output by 'SubjectInfo.subjID'. You can override
using the `.groups` argument.
#clean names for individual images for plot
overall_target_looking_by_word <- target_looking_by_target_word %>%
filter(!is.na(target_looking_diff)) %>%
group_by(Trials.targetImage) %>%
summarize(N=n(),
corrected_target_looking=mean(target_looking_diff,na.rm=TRUE),
ci=qt(0.975, N-1)*sd(target_looking_diff,na.rm=T)/sqrt(N),
lower_ci=corrected_target_looking-ci,
upper_ci=corrected_target_looking+ci
)Warning: There was 1 warning in `summarize()`.
ℹ In argument: `ci = qt(0.975, N - 1) * sd(target_looking_diff, na.rm =
T)/sqrt(N)`.
ℹ In group 1: `Trials.targetImage = "acorn"`.
Caused by warning in `qt()`:
! NaNs produced
word_prefs <- ggplot(overall_target_looking_by_word,aes(reorder(Trials.targetImage,corrected_target_looking),corrected_target_looking))+
geom_hline(yintercept=0,linetype="dashed")+
geom_errorbar(aes(ymin=lower_ci,ymax=upper_ci),width=0)+
geom_point(aes(size=N))+
xlab("Target Word")+
ylab("Easy trial prefered target looking")+
theme(axis.title.x = element_text(face="bold", size=15),
axis.text.x = element_text(size=10,angle=90,vjust=0.5,hjust=1),
axis.title.y = element_text(face="bold", size=15),
axis.text.y = element_text(size=10),
strip.text.x = element_text(size = 10,face="bold")
) +
scale_y_continuous(breaks = seq(-1, 1, by = 0.2)) +
scale_size_continuous(name = "Number of participants")
word_prefsggsave(here("data","figures","easy_trial_pref_by_word.png"),word_prefs,width=9,height=6,bg = "white")