tjmahr / lookr

Scripts for looking-while-listening and visual-world eyetracking experiments
Other
7 stars 2 forks source link

not an issue i just need help! #24

Closed rw247 closed 6 years ago

rw247 commented 6 years ago

I have eye-tracking data from an experiment which was created with eprime and tobii extensions for eprime, where participants looked at faces and had to guess what emotion they were showing. They pressed the space bar when they thought they knew what the emotion was so trial time is not standardised. I set the eprime/tobii script to tell me what area of interest participants were looking in during the trial. i want to calculate fixation times for these AOIS, but unfortunately the time outputs are all cumulative. I was therefore trying to use adjust trial times using trial attributes from this link: https://github.com/tjmahr/lookr/blob/master/R/time.R but I am really struggling because I am so new to this, and I can't work out what my event/x is. Am I even using the right thing?

Please can someone help me! I have attached one participant's eye-tracking output here. P1E.xlsx

thank you so much in advance

tjmahr commented 6 years ago

Okay, disclaimer: The code in this package is custom and messy in a way that makes it hard to extend to new experiments. Also the data has been highly processed by the point where the code in time.R gets used. The tools have gotten a lot better since I first started working with this package in 2012, and nowadays, I do most of my processing of eyetracking data by manipulating dataframes with the dplyr package. So I don't think it's a good idea to try to make your data work with my old code.

Your xlsx appears to have lots of useful information, so I am not sure that you need any fancy coding. Heres's how I would approach this excel file.

library(readxl)
library(curl)
#> Warning: package 'curl' was built under R version 3.4.1

# Download your spreadsheet
f <- tempfile(fileext = ".xlsx")
excel <- curl_download("https://github.com/tjmahr/lookr/files/1190707/P1E.xlsx", f)

d <- read_excel(excel)
d
#> # A tibble: 18,886 x 33
#>    Subject Group    ID  TETTime RTTime CursorX CursorY TimestampSec
#>      <dbl> <dbl> <dbl>    <dbl>  <dbl>   <dbl>   <dbl>        <dbl>
#>  1       1     2     1 99467.29  99013      -1      -1           99
#>  2       1     2     2 99475.57  99021      -1      -1           99
#>  3       1     2     3 99483.84  99029      -1      -1           99
#>  4       1     2     4 99492.17  99037      -1      -1           99
#>  5       1     2     5 99500.53  99046      -1      -1           99
#>  6       1     2     6 99508.88  99054      -1      -1           99
#>  7       1     2     7 99517.25  99062      -1      -1           99
#>  8       1     2     8 99525.52  99071      -1      -1           99
#>  9       1     2     9 99533.83  99079      -1      -1           99
#> 10       1     2    10 99542.20  99087      -1      -1           99
#> # ... with 18,876 more rows, and 25 more variables:
#> #   TimestampMicrosec <dbl>, XGazePosLeftEye <dbl>, YGazePosLeftEye <dbl>,
#> #   XCameraPosLeftEye <dbl>, YCameraPosLeftEye <dbl>,
#> #   DiameterPupilLeftEye <dbl>, DistanceLeftEye <dbl>,
#> #   ValidityLeftEye <dbl>, XGazePosRightEye <dbl>, YGazePosRightEye <dbl>,
#> #   XCameraPosRightEye <dbl>, YCameraPosRightEye <dbl>,
#> #   DiameterPupilRightEye <dbl>, DistanceRightEye <dbl>,
#> #   ValidityRightEye <dbl>, TrialId <dbl>, AOI1 <chr>, AOI2 <lgl>,
#> #   AOI3 <lgl>, AOI5 <lgl>, AOI6 <lgl>, AOI <dbl>, AOIStimulus <chr>,
#> #   RT <dbl>, CurrentObject <chr>

So here's how I would adjust Times in your data.

library(dplyr)
#> Warning: package 'dplyr' was built under R version 3.4.1
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(ggplot2)

# Create a variable of the relative timestamps within each trial
d <- d %>% 
  group_by(TrialId) %>% 
  mutate(Time = RTTime - min(RTTime)) %>% 
  ungroup()

# This compares cumulative time (x) to relative trial time (y). Confirms that
# the adjustment works.
ggplot(d) + aes(x = RTTime, y = Time) + geom_point()

unnamed-chunk-1-1

# I don't know how your data is coded but these plots look useful
ggplot(d) + aes(x = Time, y = AOI) + geom_point() + facet_wrap("TrialId")
#> Warning: Removed 9259 rows containing missing values (geom_point).

unnamed-chunk-1-2

ggplot(d) + aes(x = TrialId, y = RT) + geom_point()

unnamed-chunk-1-3

Hope that helps.

I won't be able to give you anymore support from here on out.

rw247 commented 6 years ago

thank you so much tjmahr I will give it a go! I really appreciate your help!!

It works! you are an r genius thank you :D