Analysis code for SOC-XSIT project.

Load libraries.

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

Read in data.

#set path for reading data
read_path <- file.path("/Users", "kmacdonald", "Documents", 
                       "Projects", "SOC_XSIT", "processed_data", 
                       "adult-looks/")

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

d <- tbl_df(read.csv(paste(read_path, 
                           "soc_xsit_looks_pilot.csv", sep="")))
d1 <- tbl_df(read.csv(paste(read_path, 
                            "soc_xsit_looks_pilot_2.csv", sep="")))
d2 <- tbl_df(read.csv(paste(read_path, 
                            "soc_xsit_looks_pilot_3_withinsubs.csv", sep="")))
d3 <- tbl_df(read.csv(paste(read_path, 
                            "soc_xsit_looks_pilot_4_thisone_btw.csv", sep="")))
d4 <- tbl_df(read.csv(paste(read_path_fyp,
                            "aggregate_soc_xsit.csv", sep="")))

Merge data sets, tracking experiment version.

#remove samepos and random "X" column from d/d1
#rename example, exposure, and test columns in d/d1
d <- d %>%
        select(-X, -samePos, 
               example_trial = exampleTrial, 
               exposure_trial = exposureTrial,
               test_trial = testTrial,
               matches(".")
               )

d1 <- d1 %>%
        select(-X, -samePos, 
               example_trial = exampleTrial, 
               exposure_trial = exposureTrial,
               test_trial = testTrial,
               matches(".")
               )

#add experiment tracking variable to each data frame
d <- mutate(d, experiment = "look-length")
d1 <- mutate(d1, experiment = "soc_vs_no-soc_btw")
d2 <- mutate(d2, experiment = "soc_vs_no_soc_within")
d3 <- mutate(d3, experiment = "this_one")

# wrap in list 
d.list <- list(d, d1, d2, d3)

#join all 4 data frames
d.all_df <- ldply(.data = d.list, .fun = rbind())

#check for people who participated more than once
temp <- d.all_df %>%
                group_by(subid) %>%
                summarise(
                        n = n(),
                        n_unique = n_distinct(subid)
                        )

#anonymize subids
d.all_df <- anonymize.sids(d.all_df, "subid")
d.all_df$experiment <- as.factor(d.all_df$experiment)

Get the number of subjects in each experiment and condition.

## Source: local data frame [9 x 4]
## Groups: experiment, condition
## 
##             experiment      condition gazeLength n_subs
## 1          look-length         Social       Long     48
## 2          look-length         Social     Medium     50
## 3          look-length         Social      Short     46
## 4 soc_vs_no_soc_within No-socialFirst      Short     46
## 5 soc_vs_no_soc_within    SocialFirst      Short     47
## 6    soc_vs_no-soc_btw         Social      Short     47
## 7    soc_vs_no-soc_btw      No-social      Short     51
## 8             this_one            One      Short     49
## 9             this_one           This      Short     48

Flag whether participants chose target of eye gaze on exposure.

#change values of faceIdx to correspond to values of chosenIdx 
#(LU = 0, RU = 1, LD = 2, RD = 3, striaight = -1)
d.all_df$faceIdx <- revalue(d.all_df$face, 
                         c("silentLUlong"= 0, "silentLUmedium" = 0,
                           "silentLUshort"= 0, "LUkidslonger" = 0,
                           "silentRUlong" = 1, "silentRUmedium"= 1,
                           "silentRUshort" = 1, "RUkidslonger" = 1,
                           "silentLDlong" = 2, "silentLDmedium" = 2,
                           "silentLDshort" = 2, "LDkidslonger" = 2,
                           "silentRDlong" = 3, "silentRDmedium" = 3,
                           "silentRDshort" = 3, "RDkidslonger" = 3, 
                           "straightahead" = -1, "straightaheadlonger" = -1))

#flag trial, if subs chose target of gaze
d.expo_df <- d.all_df %>%
                filter(exposure_trial == 1) %>%
                mutate(correct_exposure = faceIdx == chosenIdx) %>%
                select(subids, itemNum, correct_exposure)

Get test trials and merge exposure trial information.

d.test_df <- d.all_df %>%
                filter(test_trial == 1)

d.test_df <- join(d.expo_df, d.test_df, match = "all")
## Joining by: subids, itemNum

Flag subs who got <25% of test trials correct.

d.test_df <- d.test_df %>%
                group_by(subids) %>%
                summarise(mean_acc_exp = mean(correct_exposure)) %>%
                mutate(include_expo = ifelse(mean_acc_exp > 0.25,1,0)) %>%
                join(d.test_df, by = "subids")

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)
                       )

Summarize data set: means for acc on exposure and test

Experiment 1: Look-length manipulation.

Accuracy on exposure trials.

ms_exp_looks <- d.test_df %>%
                        filter(experiment == "look-length", include_good_rt == 1, 
                               include_expo == 1) %>%
                        group_by(gazeLength) %>%
                        summarise(accuracy_exposure = mean(correct_exposure),
                                  ci_low = ci.low(correct_exposure),
                                  ci_high = ci.high(correct_exposure))

ms_exp_looks$gazeLength <- factor(ms_exp_looks$gazeLength, 
                                  levels = c("Short", "Medium", "Long"))

ggplot(data=ms_exp_looks, 
       aes(x=gazeLength, y=accuracy_exposure,
           fill=gazeLength)) + 
        geom_bar(stat="identity") +
        geom_errorbar(aes(ymin=accuracy_exposure-ci_low, 
                      ymax=accuracy_exposure+ci_high), width = .1) +
        geom_hline(yintercept=0.25, linetype = "dashed") +
        scale_y_continuous(limits=c(0,1))

plot of chunk look-length exposure

Accuracy on test trials: same/switch

ms_test_looks <- d.test_df %>%
                        filter(experiment == "look-length", include_good_rt == 1, 
                               include_expo == 1, correct_exposure == TRUE) %>%
                        group_by(gazeLength, trialType) %>%
                        summarise(accuracy = mean(correct),
                                  ci_low = ci.low(correct),
                                  ci_high = ci.high(correct))

ms_test_looks$gazeLength <- factor(ms_test_looks$gazeLength, 
                                  levels = c("Short", "Medium", "Long"))

ggplot(ms_test_looks, 
       aes(x=gazeLength, y=accuracy, 
           group=trialType, colour=trialType)) +
        geom_point(size=2) +
        geom_line() +
        geom_errorbar(aes(ymin=accuracy - ci_low,
                          ymax=accuracy + ci_high), width = .1) +
        geom_hline(yintercept=0.25, linetype = "dashed") +
        scale_y_continuous(limits=c(0,1))

plot of chunk look-length acc test

Experiment 2: Social vs. No-Social between subjects.

Only used the short gaze length condition.

Accuracy on exposure trials.

ms_exp_btw <- d.test_df %>%
                        filter(experiment == "soc_vs_no-soc_btw", condition == "Social",
                               include_good_rt == 1, include_expo == 1) %>%
                        summarise(accuracy_exposure = mean(correct_exposure),
                                  ci_low = ci.low(correct_exposure),
                                  ci_high = ci.high(correct_exposure))
ms_exp_btw
##   accuracy_exposure  ci_low ci_high
## 1            0.8775 0.03974 0.03642

Accuracy on test trials

ms_test_btw <- d.test_df %>%
                        filter(experiment == "soc_vs_no-soc_btw", 
                               include_good_rt == 1, 
                               include_expo == 1 | condition == "No-social") %>%
                        group_by(condition, trialType) %>%
                        summarise(accuracy_test = mean(correct),
                                  ci_low = ci.low(correct),
                                  ci_high = ci.high(correct))

#now plot
ggplot(ms_test_btw, 
       aes(x=condition, y=accuracy_test, 
           group=trialType, colour=trialType)) +
        geom_point(size=2.5) +
        geom_line() +
        geom_errorbar(aes(ymin=accuracy_test - ci_low,
                          ymax=accuracy_test + ci_high), width = .1) +
        geom_hline(yintercept=0.25, linetype = "dashed") +
        scale_y_continuous(limits=c(0,1)) +
        xlab("Condition") +
        ylab("Proportion Correct") +
        labs(colour = "Trial Type")

plot of chunk soc-no-soc test

Experiment 3: Within Subjects Social vs. No-social

Replicate the social effect on switch trials with a within subjects manipulation.

Flag social vs. no-social trials

When we switched to within subjects, we tracked which block came first, but didn’t track social vs. no-social. So we create a column to track this information

Accuracy on exposure trials

Replot fyp data

d4$condition <- factor(d4$condition, 
                                  levels = c("Social", "No-Social"))

ggplot(data=filter(d4, intervalNum==0, numPicN==4),
       aes(x=condition, y=correct, colour=trialType, group=trialType)) +
        geom_point(size = 2.5) +
        geom_line() +
        geom_errorbar(aes(ymin=correct - corr.cil,
                          ymax=correct + corr.cih), width = .1) +
        geom_hline(yintercept=0.25, linetype = "dashed") +
        scale_y_continuous(limits=c(0,1)) +
        xlab("Condition") +
        ylab("Proportion Correct") +
        labs(colour = "Trial Type")

plot of chunk replot fyp