jessivarela / QP

0 stars 0 forks source link

gazeR::onset_pupil #1

Open laurafdeza opened 3 years ago

laurafdeza commented 3 years ago

Hi @jgeller112,

This is the script where the error pops up.

The same script was used here for the smaller bins and it worked fine.

jgeller112 commented 3 years ago

I’ll take a look at this tomorrow and get back to you.

jgeller112 commented 3 years ago

@laurafdeza Can you link the actual data you used as input with onset_pupil? The data in the folder is not available to me.

laurafdeza commented 3 years ago

Sorry I didn't reply earlier, @jgeller112.

Is it throwing an error message? The 50 ms bin data is det_hs_50.txt here.

Just in case, here's the zipped data containing the raw .txt with the 10 and 50 ms bins.

jgeller112 commented 3 years ago

@laurafdeza,

You have to be very careful about what packages you call first as it can have some downstream effects on subsequent function calls, which is what is happening here. In your case calling plyr messed up dplyr stuff like select, mutate, and group_by. I would ditch plyr and just go with dplyr. If you need plyr for something, I suggest appending each function call with :: like dplyr::select(). I did that for the below code and my onset_pupil function works perfectly. I hope this helps.

# Read data
det50 <- det50 %>%

  #select and rename variables of interest
  dplyr::select(., RECORDING_SESSION_LABEL, TRIAL_INDEX, BIN_INDEX,
         AVERAGE_IA_0_SAMPLE_COUNT, AVERAGE_IA_0_SAMPLE_COUNT_.,
         AVERAGE_IA_1_SAMPLE_COUNT, AVERAGE_IA_1_SAMPLE_COUNT_.,
         AVERAGE_IA_2_SAMPLE_COUNT, AVERAGE_IA_2_SAMPLE_COUNT_.,
         ACCURACY, id, noun_transparency, structure, gender, 
         t01, t02, t03, t04, t05, t06, target, version) %>%
  dplyr::rename(., participant = RECORDING_SESSION_LABEL,
                trial = TRIAL_INDEX, 
                bin = BIN_INDEX,
                target_count = AVERAGE_IA_1_SAMPLE_COUNT, 
                target_prop = AVERAGE_IA_1_SAMPLE_COUNT_.,
                onset_que = t01,
                onset_det = t02,
                onset_noun = t03,
                onset_target = t04,
                offset_target = t05,
                endSentence = t06,
                sentence_id = id) %>%

  dplyr::filter(., ACCURACY == 1) %>%

  # drop unused levels of factors
  droplevels(.) %>%

  # Create eLog variable and respective wts
  dplyr::mutate(.,eLog = log((target_count + 0.5) / (50 - target_count + 0.5)),
         wts = 1 / (target_count + 0.5) + 1 / (50 - target_count + 0.5)) %>%

  # Select necessary columns
  # Gather data to prepare for bin adjustment
  # Get suffix onset label and center at 0 for each
  # participant for each item

  dplyr::select(participant, target, bin, noun_transparency, structure, gender,
                target_count, target_prop, eLog, wts, onset_target) %>%   
  tidyr::gather(., landmark, lm_bin, -c(participant:wts)) %>%
  dplyr::mutate(., lm_bin = (lm_bin / 50) %>% ceiling(.),
         t_onset = if_else(bin == lm_bin, TRUE, FALSE)) %>%

  dplyr::group_by(., participant, target) %>%
  dplyr::mutate(., time_zero = gazer::onset_pupil(bin, t_onset, event = c("TRUE"))) %>%
  dplyr::ungroup(.)
laurafdeza commented 3 years ago

Oh, ok. Thank you! That's definitely not where I was looking into.