Skip to content

Instantly share code, notes, and snippets.

@WillForan
Created September 21, 2020 20:58
Show Gist options
  • Save WillForan/5fb9fb87000f4de69e165d5f063e4b9d to your computer and use it in GitHub Desktop.
Save WillForan/5fb9fb87000f4de69e165d5f063e4b9d to your computer and use it in GitHub Desktop.
library(ggplot2)
library(dplyr)
library(tidyr)
theme_set(cowplot::theme_cowplot())
eog <- read.csv('eog_cal/eeg_data_20200921.csv')
subjData <-
eog %>%
unite(ld8, LunaID, ScanDate) %>% # remove LunaID and scanDate columns. replace with ld8
mutate_at(vars(matches('Error')), abs) %>% # abs delta columns
# made the data long. column meas has calR2, {Position,Displacement}Error, {mgs,vgs}Latency
gather(meas, v, -ld8, -Trial, -Delay) %>%
filter(!is.na(v)) %>%
# group
group_by(ld8, meas, Delay) %>%
summarise(subj_mean=mean(v),
subj_sd=sd(v),
subj_n=n(),
subj_se=subj_sd/sqrt(subj_n))
groupData <- subjData %>% group_by(meas, Delay) %>%
mutate(subj_mean=abs(subj_mean)) %>%
summarize(delay_mean=mean(subj_mean),
delay_sd=sd(subj_mean),
delay_se=delay_sd/n())
groupData %>%
mutate(Delay=as.factor(Delay),
mtype=gsub("^[A-Z]?[a-z]*"," ", meas)) %>%
ggplot() +
aes(x=meas, fill=Delay, y=delay_mean) +
geom_bar(stat='identity',position='dodge') +
geom_errorbar(position='dodge',
aes(ymax=delay_mean+delay_se,ymin=delay_mean-delay_se)) +
facet_wrap(~mtype, scales="free")
@WillForan
Copy link
Author

longfmt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment