This is a basic example of pre-processing VWP data. The data are from a semantic competition experiment where the distractors were either thematically (associate) or taxonomically related to the target (Mirman & Graziano, 2012).

Initial set-up

Load the necessary packages

library(gazer)
library(dplyr)
library(tidyr)
library(ggplot2)

Read in the raw fixation report

# Use a file installed with the package 
gaze_path <- system.file("extdata", "FixData_v1_N15.xls", package = "gazer")
gaze <- readFixationReport(gaze_path, plot_fix_scatter = FALSE)
summary(gaze)

Get some calibration diagnostics, including a figure

cg <- get_gaze_diagnostics(gaze)

Alternatively, a single call will read in the data and generate two diagnostic figures

gaze <- readFixationReport(gaze_path)

Parse areas of interest

The four screen corners (1-4) need to be interpreted and matched to which object is in each location.

First, extract the numbered location of the target and competitor:

gaze$TargetLocation <- as.numeric(substr(gaze$TargetLoc, 6, 6))
gaze$CompLocation <- as.numeric(substr(gaze$CompPort, 6, 6))

Then match fixation locations to AOI based on screen coordinates:

gaze_aoi <- assignAOI(gaze)
summary(gaze_aoi)

Now determine which object was being fixated by matching AOI codes with target and competitor locations:

gaze_aoi$Targ <- gaze_aoi$AOI == gaze_aoi$TargetLocation
gaze_aoi$Comp <- gaze_aoi$AOI == gaze_aoi$CompLocation
gaze_aoi$Unrelated <- ((gaze_aoi$AOI != as.numeric(gaze_aoi$TargetLocation)) &
                         (gaze_aoi$AOI != as.numeric(gaze_aoi$CompLocation)) &
                         (gaze_aoi$AOI != 0) & !is.na(gaze_aoi$AOI))

Fixations to bins

Convert from fixation list to time bins, only keep the columns needed for analysis. Most of the work is done by the binify_fixations() function, it just needs a list columns that should be kept after the bining is done. You can optionally specify a bin size (default is 20ms). Note: this step is slow.

gaze_bins <- binify_fixations(
  gaze = gaze_aoi, 
  keepCols = c(
    "Subject", "Target", "Condition", "ACC", 
    "RT", "Targ", "Comp", "Unrelated"))
summary(gaze_bins)

Gather

The fixation locations are in separate columns and need to be "gathered" into a single column:

gaze_obj <- gather(gaze_bins, 
                   key = "Object", value = "Fix", 
                   Targ, Comp, Unrelated, factor_key = TRUE)

# recode NA as not-fixating
gaze_obj$Fix <- replace(gaze_obj$Fix, is.na(gaze_obj$Fix), FALSE) 
summary(gaze_obj)

Compute fixation proportions

Filter out error and practice trials, and focus on relevant time window. Then group by Subject, Condition, and Object type to calculate number of valid trials in each cell. Then also group by time bin to calculate time course of number of object fixations and mean fixation proportion. These are the subject-by-condition time courses that would go into an analysis.

gaze_subj <- gaze_obj %>% 
  filter(ACC == 1, Condition != "practice", Time < 3500) %>% 
  # calculate number of valid trials for each subject-condition
  group_by(Subject, Condition, Object) %>% 
  mutate(nTrials = length(unique(Target))) %>% ungroup() %>%
  # calculate number of fixations 
  group_by(Subject, Condition, Object, Time) %>%
  summarize(sumFix = sum(Fix), nTrials = unique(nTrials), 
            meanFix = sum(Fix)/unique(nTrials))

# there were two unrelated objects, so divide those proportions by 2
gaze_subj$meanFix[gaze_subj$Object == "Unrelated"] <- 
  gaze_subj$meanFix[gaze_subj$Object == "Unrelated"] / 2

summary(gaze_subj)

Plot fixation time course

ggplot(gaze_subj, aes(Time, meanFix, color = Object)) + 
  facet_wrap(~ Condition) +
  stat_summary(fun.y = mean, geom = "line") +
  geom_vline(xintercept = 1300) +
  annotate("text", x=1300, y=0.9, label="Word onset", hjust=0)


jgeller112/gazer documentation built on Jan. 13, 2020, 1:04 p.m.