Script to visualize and analyze social-xsl experiment

Load libraries

library(plyr)
library(dplyr)
library(bootstrap)
library(lme4)
library(ggplot2)
source("/Users/kmacdonald/Documents/Projects/SOC_XSIT/XSIT-MIN/analysis/Ranalysis/useful.R")

Read in the data.

read_path_fyp <- file.path("/Users", "kmacdonald", "Documents", 
                       "Projects", "SOC_XSIT", "processed_data", 
                       "adult-fyp/")

d_df <- tbl_df(read.csv(paste(read_path_fyp,
                            "soc_xsit_expt1_master.csv", sep="")))

Get the number of subjects in each condition.

d_df %>%
        group_by(condition, intervalNum, numPicN) %>%
        summarise(n_subs = n_distinct(subid))
## Source: local data frame [32 x 4]
## Groups: condition, intervalNum
## 
##    condition intervalNum numPicN n_subs
## 1  No-Social           0       2    127
## 2  No-Social           0       4    114
## 3  No-Social           0       6     39
## 4  No-Social           0       8    117
## 5  No-Social           1       2    120
## 6  No-Social           1       4    118
## 7  No-Social           1       6     35
## 8  No-Social           1       8    114
## 9  No-Social           3       2    115
## 10 No-Social           3       4    117
## 11 No-Social           3       6     36
## 12 No-Social           3       8    114
## 13 No-Social           7       2    129
## 14 No-Social           7       4    115
## 15 No-Social           7       6     34
## 16 No-Social           7       8    114
## 17    Social           0       2     48
## 18    Social           0       4     82
## 19    Social           0       6     37
## 20    Social           0       8     43
## 21    Social           1       2     44
## 22    Social           1       4     88
## 23    Social           1       6     44
## 24    Social           1       8     44
## 25    Social           3       2     47
## 26    Social           3       4     87
## 27    Social           3       6     40
## 28    Social           3       8     43
## 29    Social           7       2     47
## 30    Social           7       4     90
## 31    Social           7       6     38
## 32    Social           7       8     38

Exclude subjects who were choosing randomly during exposure trials

Flag trials on which subs chose the target of eye gaze.

#revalue face vid to match chosen indices
d_df$faceIdx6 <- revalue(d_df$face, c("eyes_left_90"=0, "eyes_right_90"=1, 
                                        "eyes_left"=2, "eyes_down_left"=3,
                                        "eyes_down_right"=4, "eyes_right"=5, 
                                        "eyescenter"=-1))
d.expo_df <- d_df %>%
                filter(exposureTrial == 1) %>%
                mutate(correct_exposure = ifelse(numPic == 6, 
                                                 chosenIdx == faceIdx6,
                                                 chosenIdx == faceIdx)) %>%
                select(subid, itemNum, correct_exposure)

Get test trials and merge with exposure trial information.

d.test_df <- d_df %>%
                filter(testTrial == 1)

d.test_df <- join(d.expo_df, d.test_df, type = "full")
## Joining by: subid, itemNum

Flag subs in the social condition who performed worse than chance on exposure trials.

d.test_df <- d.test_df %>%
                filter(condition == "Social") %>%
                group_by(subid, numPic) %>%
                summarise(mean_acc_exp = mean(correct_exposure)) %>%
                mutate(include_expo = ifelse(numPic == 2 & mean_acc_exp > 0.5, 1, 
                                      ifelse(numPic == 4 & mean_acc_exp > 0.25, 1,
                                      ifelse(numPic == 6 & mean_acc_exp > 0.17, 1, 
                                      ifelse(numPic == 8 & mean_acc_exp > 0.125, 1, 
                                             0))))) %>%
                join(d.test_df, by = "subid", type = "full")

Flag trials with extremely slow or fast RTs (+/- 2SD).

d.test_df <- d.test_df %>%
                mutate(include_good_rt = ifelse(log(rt) > mean(log(rt)) + 2 * sd(log(rt)) |
                                                log(rt) < mean(log(rt)) - 2 * sd(log(rt)),
                                                0, 1))

Experiment FYP: Social vs. No-social, Different delays, Different number of referents

Accuracy on exposure trials.

plot of chunk acc exposure

Accuracy on test trials, filtering out subjects who performed below chance on exposure trials.

ms_test_looks_filtered <- d.test_df %>%
                        filter(include_good_rt == 1, 
                               (condition == "No-Social") | 
                                       (include_expo == 1 & correct_exposure == TRUE)
                               ) %>%
                        group_by(condition, intervalNum, numPic, trialType) %>%
                        summarise(accuracy = mean(correct),
                                  ci_low = ci.low(correct),
                                  ci_high = ci.high(correct),
                                  exclusionary_criteria = "subject-level")

acc_test_1 <- ggplot(data=ms_test_looks_filtered, aes(x=intervalNum, y=accuracy, 
                               colour = condition)) + 
                        geom_line(aes(linetype = trialType)) +
                        geom_errorbar(aes(ymin=accuracy - ci_low, 
                                      ymax=accuracy + ci_high), width = .1) +
                        geom_hline(aes(yintercept=1/numPic), linetype = "dashed") +
                        scale_x_continuous(limits=c(-0.5, 7.5), breaks=c(0,1,3,7)) +
                        scale_y_continuous(limits=c(0,1)) +
                        scale_colour_manual(values=c("firebrick1", "dodgerblue")) +
                        facet_grid(. ~ numPic) + 
                        xlab("Intervening Trials") + 
                        ylab("Proportion Correct") +
                        labs(colour = "Condition") +
                        labs(linetype = "Trial Type")

Accuracy on test trials, without filtering subjects (only trial level filtering)

ms_test_looks_unfiltered <- d.test_df %>%
                        filter(include_good_rt == 1, 
                               condition == "No-Social" | correct_exposure == TRUE) %>%
                        group_by(condition, intervalNum, numPic, trialType) %>%
                        summarise(accuracy = mean(correct),
                                  ci_low = ci.low(correct),
                                  ci_high = ci.high(correct),
                                  exclusionary_criteria = "trial-level")

acc_test_2 <- ggplot(data=ms_test_looks_unfiltered, aes(x=intervalNum, y=accuracy, 
                               colour = condition)) + 
                        geom_line(aes(linetype = trialType)) +
                        geom_errorbar(aes(ymin=accuracy - ci_low, 
                                      ymax=accuracy + ci_high), width = .1) +
                        geom_hline(aes(yintercept=1/numPic), linetype = "dashed") +
                        scale_x_continuous(limits=c(-0.5, 7.5), breaks=c(0,1,3,7)) +
                        scale_y_continuous(limits=c(0,1)) +
                        scale_colour_manual(values=c("firebrick1", "dodgerblue")) +
                        facet_grid(. ~ numPic) + 
                        xlab("Intervening Trials") + 
                        ylab("Proportion Correct") +
                        labs(colour = "Condition") +
                        labs(linetype = "Trial Type")

Now put both plots together.

plot of chunk joint plot