Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

downsample_gaze not found #27

Open
vicentemunozlh opened this issue Nov 17, 2022 · 13 comments
Open

downsample_gaze not found #27

vicentemunozlh opened this issue Nov 17, 2022 · 13 comments

Comments

@vicentemunozlh
Copy link

Hello, thanks for the great algorithm!

every other function is working great for me exept for the downsample_gaze one. The error showed in the console is the following:

> timebins1 <- downsample_gaze(baseline_pupil_onset, bin.length = 100, timevar = "time_zero", aggvars= c("subject", "timebins"), type="pupilz")
Error in downsample_gaze(baseline_pupil_onset, bin.length = 100, timevar = "time_zero",  : 
  object 'downsample' not found

Is there a reason why or am I just applying it wrong??

@jgeller112
Copy link
Collaborator

Hi!

that function does not take pupilz as an input it is either pupil or gaze

@vicentemunozlh
Copy link
Author

Hello! thanks for the quick response. What if I change the variable name, will the results be correct or by beeing scaled before (with the pupilz method) it will create bad results ?

@vicentemunozlh
Copy link
Author

Sorry but now by checking the functions in the code section I am a little bit confused. If I made the pupilz convertion in the re-scaling section, what parameter should I be putting in the pup_missing, pup_outliers and mad_removal ?? sorry if it is clearer but I can't figure it out , this is that section of the code :

timebinsz <- baseline_pupil %>% 
  group_by(subject, trial) %>%
  mutate(pupilz= scale(pup_interp)) %>% ungroup()

pup_missing<-count_missing_pupil(timebinsz, pupil="pupilz", missingthresh = .2)

puphist <- ggplot(timebinsz, aes(x = pupilz)) +
  geom_histogram(aes(y = ..count..), colour = 'green', binwidth = 0.001) +
  geom_vline(xintercept = -4, linetype = 'dotted') +
  geom_vline(xintercept = 4, linetype = 'dotted') +
  xlab('Pupil Size') +
  ylab('Count') +
  theme_bw()

pup_outliers <- pup_missing %>%
  filter(pupilz >= number, pupilz <= number2)    

mad_removal <- pup_outliers %>%
  group_by(subject, trial) %>%
  mutate(speed = speed_pupil(pupilz, time)) %>%   
  mutate(MAD = calc_mad(speed, n = 16)) %>%
  filter(speed < MAD)

Tanks a lot for any help possible !

@jgeller112
Copy link
Collaborator

Change pupilz to pupil and it should work. Gazer requires columns to be named appropriately to work with certain functions.

@jgeller112
Copy link
Collaborator

Just to be clear here type="pupilz" is not correct as the type is either pupil or gaze. It is not asking for a column name

@vicentemunozlh
Copy link
Author

So, the pupilz created should not be used as a replacement of pupil in the next steps ? That is the part I am confused about.

@jgeller112
Copy link
Collaborator

jgeller112 commented Nov 25, 2022 via email

@vicentemunozlh
Copy link
Author

vicentemunozlh commented Nov 25, 2022

Ok, I think I understand, thank you. Last question, in case I used the timbinz to create the pupilz variable, should I run the baseline_correction_pupil_msg function with pupil_colname= 'pupilz' instead of pupil_colname= 'pup_interp' ?

Or does the pupilz became just a replacement for the pupil variable? , so in the code when you use pupil I should be using pupilz instead but when you are using pup_interp and baselinecorrectedp continue using those?

@jgeller112
Copy link
Collaborator

In those functions, your pupilz would be changed to pup_interp in the function


    baseline <- event_time %>%
      dplyr::group_by(subject, trial) %>%
      dplyr::filter(time >= event_offset_time - baseline_dur,
                    time <= event_offset_time) %>%
      _**dplyr::rename(pupil_avg = pupil_colname) %>%**_
      dplyr::summarise(baseline = median(pupil_avg, na.rm=TRUE)) %>%
      dplyr::full_join(., datafile) %>%
      dplyr::ungroup()

  message("Merging baseline")
    message("Performing median divisive baseline correction")
    corrected_baseline <- baseline %>%
      dplyr::rename(pupil_avg = pupil_colname) %>%
      dplyr::mutate(baselinecorrectedp = (pupil_avg - baseline)/baseline) %>%
      _**dplyr::rename(pup_interp = pupil_avg) %>%**_
      dplyr::arrange(subject, trial, time)


for instance here whatever you specified as pupil_colname in the baseline_correction function will be changed to pupil_avg and then to pupil_interp in the function. (the pupil_interp variable created is interpolated with your z score var). You should be able to carry on without changing the defaults.

@jgeller112
Copy link
Collaborator

My suggestion would be to take your pupilz column and change it to pupil and run the pipeline on that

@vicentemunozlh
Copy link
Author

Thank you very much for your help and the gazeR package !

@sebacea
Copy link

sebacea commented Nov 29, 2022

Hi @jgeller112 , I'm working with @vicentemunozlh. I think there are two questions in this Issue.

First, regarding the use of type=pupilz in downsample_gaze function. We got that available types are either gaze or pupilonly.

Second, provided the application of baseline_correction_pupil or baseline_correction_pupil_msg, the generated data frame, let us say baseline_pupil as in the paper, includes a new variable called baselinecorrectedp. Thus, if Re-scaling is applied, it is correct to apply the scale function to the variable baselinecorrectedp?

Our question is rooted in the fact the data frame timebinz (in page 2248 of Geller, Winn, Mahr and Mirman (2020)) is created by scaling the variable baseline_pupil$pup_interp instead of baseline_pupil$baselinecorrectedp. Thus, we need to be sure if a re-scale like:

timebinz<- baseline_pupil %>%
  group_by(subject,trial) %>%
  mutate(pupilz = scale(baselinecorrectedp))

is correct or not.

We have a similar question regarding the application of Artifact rejection through MAD since you use pup_interpvariable instead of baselinecorrectedp. Should we use also baselinecorrectedp in the creation of the data frame mad_removal? That is,

mad_removal<- pup_outliers %>%
  group_by(subject,trial) %>%
  mutate(speed = speed_pupil(baselinecorrectedp, time)) %>%
  mutate(MAD=calc_mad(speed, n=16)) %>%
  filter(speed < MAD)

Note that we use time instead of time_zero in the call to speed_pupil since we believe it is a typo.

@jgeller112
Copy link
Collaborator

jgeller112 commented Nov 29, 2022

First, regarding the use of type=pupilz in downsample_gaze function. We got that available types are either gaze or pupilonly.

As I said, this is an argument function and not where you put your pupil variable name. This function assumes your pupil variable is called baselinecorrectedp

The paper assumes you have used gazeR consistent names

timebinz<- baseline_pupil %>%
  group_by(subject,trial) %>%
  mutate(pupilz = scale(baselinecorrectedp))

Call pupilz (baselinecorrectedp) so it is consistent with gazeR names and carry one with preprocessing .

Note that we use time instead of time_zero in the call to speed_pupil since we believe it is a typo.

Yep! Here is most up-to-date paper with corrections: https://psyarxiv.com/4qwr8/

mad_removal<- pup_outliers %>%
group_by(subject,trial) %>%
mutate(speed = speed_pupil(baselinecorrectedp, time)) %>%
mutate(MAD=calc_mad(speed, n=16)) %>%
filter(speed < MAD)

I performed this correction on non-baseline corrected data (pup_interp). I guess it could be done on the baseline corrected pupil column as well. In the MAD pupil paper (https://d-nb.info/1167304861/34) it was done on non-baselined data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants