So here's a reproducible sample of my dataset.
set.seed(42)
n <- 100
dat <- data.frame(Participant=1:20,
Environment=rep(LETTERS[1:2], n/2),
Condition=rep(LETTERS[25:26], n/2),
Gate= sample(1:5, n, replace=TRUE),
Block = sample(1:2, n, replace=TRUE),
Sound=rep(LETTERS[3:4], n/2),
Correct=sample(0:1, n, replace=TRUE)
)
When I calculate the standard error of this table,
dat %>%
group_by(Condition, Gate, Sound) %>%
summarize(Accuracy = mean(Correct),
se = sd(Correct)/sqrt(length(Correct)))
it analyzes at the item-level(trial). I was hoping to transform the dataset to a more condensed version, where it groups data for each participant. For example, I would want to be able to see each participant's individual performance on Gate 1 in Condition Y with C sound. Here is an example to make it less abstract:
Here is an example of the code I use for graphs:
dat %>%
group_by(Condition, Gate, Sound) %>%
summarize(Accuracy = mean(Correct),
se = sd(Correct)/sqrt(length(Correct)))%>%
ggplot(aes(x = Gate, y = Accuracy, color = Sound, group = Sound)) +
geom_line() +
geom_errorbar(aes(ymin = Accuracy - se, ymax = Accuracy + se), color = "Black", size = .15, width = .3) +
geom_point(size = 2)+
scale_y_continuous(labels = scales::percent)+
theme_minimal()+
scale_color_brewer(palette = "Set1")
and I get a graph like this:
If I group by participant with this code:
dat %>%
group_by(Condition, Gate, Sound,Participant) %>%
summarize(Accuracy = mean(Correct),
se = sd(Correct)/sqrt(length(Correct)))%>%
ggplot(aes(x = Gate, y = Accuracy, color = Sound, group = Sound)) +
geom_line() +
geom_errorbar(aes(ymin = Accuracy - se, ymax = Accuracy + se), color = "Black", size = .15, width = .3) +
geom_point(size = 2)+
scale_y_continuous(labels = scales::percent)+
theme_minimal()+
scale_color_brewer(palette = "Set1")
I get a graph like this:
Which does not work. So I think I need to create a new dataset in R like the sample above(image 1), before conducting analysis. Maybe I could use the subset function to accomplish this somehow, like this:
participant_dat = subset(dat, ...) #Not sure where to go from here.


