jwdink / eyetrackingR

This package is designed to make dealing with eye-tracking data easier. It addresses tasks along the pipeline from raw data to analysis and visualization.
http://eyetrackingr.com
Other
82 stars 20 forks source link

time cluster'-type analysis using a 1-sample t-test #65

Open mmb951 opened 6 years ago

mmb951 commented 6 years ago

Hi

First of all, thanks for the useful EytrackingR website. I would like to run a 'time cluster'-type analysis using a 1-sample t-test to test when the bias to a target AOI significantly exceeds chance (in our experiment .25; with time as a continuous variable in 50ms bins). Is this possible in the current functions, please?

Many thanks Mahsa

respatte commented 6 years ago

Hi,

I agree that this feature would be really useful. In the meantime, I have a little work-around that I'm pretty confidence isn't statistically bad. The idea is to trick eyetrackingR by creating a chance-level dataset to compare the actual data to:

response_time <- response_window_clean %>%
  mutate(Chance = F) %>% # This is the actual data, not the chance level
  make_time_sequence_data(time_bin_size = 100,
                          aois = "YourAOI",
                          predictor_columns="Chance",
                          summarize_by = "ParticipantName")

# Create the chance-level data
response_time.chance <-  response_time %>%
  mutate(Chance = T, # This is the chance data
         Participant = paste0("Chance", Participant),
         # This is so eyetrackingR is okay with within_part = F
         Prop = .5) # Change with your actual chance level
  # If you use a DV other than Prop in your test, just change this DV instead

# Merging the data and chance datasets together
response_window.chance_test <- rbind(response_window,
                                     response_window.chance) %>%
  mutate_at("Chance", parse_factor, levels = NULL) # Just in case

After that, you can just run the analysis using Chance as a predictor column:

# Determine threshold based on alpha = .05 two-tailed
num_sub = length(unique((response_window.chance_test$ParticipantName)))
threshold_t = qt(p = 1 - .05/2,
                 df = num_sub-1)

# Determine clusters
df_timeclust <- response_window.chance_test %>%
  make_time_cluster_data(predictor_column = "Chance",
                         aoi = "YourAOI",
                         test = "t.test",
                         threshold = threshold_t)

# Run analysis
clust_analysis <-  analyze_time_clusters(df_timeclust,
                                         within_subj = F,
                                         parallel = T)
mmb951 commented 6 years ago

@respatte Great, I will try that. Thanks a lot for your help

sambfloyd commented 5 years ago

hi! this is great, thanks @respatte . My issue is that the cluster analysis does not provide a t or p statistic as far as I can tell. The function analyze_time_bins produces these but I don't think your method will work with analyze_time_bins. Any recommendations?

respatte commented 5 years ago

@sambfloyd I didn't test it but I don't see why this workaround wouldn't work with analyze_time_bins, have you tried it? I'm guessing what you want is a t-statistic for each time bin, whether it reaches the defined threshold or not? In that case you would need to use analyse_time_bins indeed, but analyze_time_clusters does give you the summed t statistic for each cluster.

sambfloyd commented 5 years ago

@respatte sorry for not updating, I did exactly that and forgot to post -- it works great.

The only minor issue I have (with both clusters and bins) is the mutate_at line of code- it runs but it seems to recode the Chance variable weirdly-- when I look at the levels it says character(0) instead of NULL (which does work for the analysis). But I just run it without that since chance is comes out as having NULL levels before that line.