I hope all is well. I recently developed a code (with the help of the wonderful stack overflow community) to calculate time to first fixation, first fixation duration, and total visit duration to areas of interest. I now want to update this so it can adjust based on the stimuli being presented. Specifically the x and y coordinates vary ever so slightly between each stimuli. I have an example spreadsheet of the stimuli coordinates. It would be great if I could read those in. Match it to the Stimuli in the Final_Label data and be able to calculate and summarize these metrics across all trials. So I need something within the code that essentially says - if it is this stimuli (e.g., A1 use these coordinates etc).
Thank you for your help and please let me know if I can provide any further information at this time.
Take care and stay well,
Caroline
Face_AOI <- Final_Labels %>%
mutate(AOI_face = (mean_x >= .100 & mean_x <= .500 & mean_y >= .100 & mean_y <= .800), #These numbers are FAKE ###) %>%
filter(AOI_face) %>%
group_by(SubjectID, Trial) %>%
summarize(Face_totalfixationduration = sum(Duration), Face_firstfixationduration = first(Duration), Face_timetofirstfixation = first(Start))
Mouth_AOI <- Final_Labels %>%
mutate(AOI_mouth = (mean_x >= .200 & mean_x <= .300 & mean_y >= .500 & mean_y <= .600)) %>%
filter(AOI_mouth) %>%
group_by(SubjectID, Trial) %>%
summarize(Mouth_totalfixationduration = sum(Duration), Mouth_firstfixationduration = first(Duration), Mouth_timetofirstfixation = first(Start))
Mouth_AOI$SubjectID <- NULL
Eyes_AOI <- Final_Labels %>%
mutate(
AOI_eyes = (mean_x >= .200 & mean_x <= .300 & mean_y >= .500 & mean_y <= .600)) %>%
filter(AOI_eyes) %>%
group_by(SubjectID, Trial) %>%
summarize(Eyes_totalfixationduration = sum(Duration), Eyes_firstfixationduration = first(Duration), Eyes_timetofirstfixation = first(Start))
Example of a list of stimuli with different coordinates to integrate into the above code.
Df2 <- data.frame(Stimuli = c("A1", "A1", "A1", "A2", "A2", "A2"),
AOI = C("Face", "Eyes", "Mouth", "Face", "Eyes", "Mouth"),
X1 = c(0, 300, 301, 0, 305, 306),
X2 = c(1022, 600, 600, 0, 604, 604),
Y1 = c(0, 30, 31, 0, 30, 38),
Y2 = c(0, 300, 301, 6, 305, 306))
Here is an example of the Final_Labels dataframe
Final_Labels <- data.frame(Stimuli = c("A1.jpg", "A2.jpg", "A3.jpg", "A4.jpg", "A5.jpg", "H1.jpg"), ##note we will need .jpg to be removed to match the files
Duration = c(300, NA, 300, 60, NA, NA),
Start = c(100, NA, 1, 100, NA, NA),
End = c(160, NA, 301, 160, NA, NA),
mean_x = c(.3, NA, .50, .40, NA, NA),
mean_y = c(.5, NA, .4, .5, NA, NA))