Closed bzuck-temple closed 4 years ago
I do not think I am going to merge this into the package just yet, but something like this will probably do the trick:
baseline_correction_pupil<-function(datafile, pupil_colnames=NULL, baseline_start=NULL, event_onset=NULL, event_offset=NULL, baseline_method="sub") { message("Calculating baseline")
baseline <- datafile %>% dplyr::group_by(subject, trial) %>% dplyr::filter(time > time[event_onset], time < time[event_offset] %>% dplyr::rename(pupil_avg = pupil_colnames) %>% dplyr::summarise(baseline = median(pupil_avg)) %>% ungroup()
message("Merging baseline") merge_baseline <- merge(baseline,datafile,all=TRUE) # merge median pupil size with raw dataset
if (baseline_method=="sub") { message("Performing subtractive baseline correction")
corrected_baseline <- merge_baseline %>%
dplyr::rename(pupil_avg = pupil_colnames) %>%
dplyr::mutate(baselinecorrectedp = pupil_avg - baseline) %>%
dplyr::rename(movingavgpup = pupil_avg) %>%
dplyr::arrange(subject, trial, time)
} if (baseline_method=="div") { message("Performing divisive baseline correction")
corrected_baseline <- merge_baseline %>%
dplyr::rename(pupil_avg = pupil_colnames) %>%
dplyr::mutate(baselinecorrectedp = (pupil_avg - baseline)/baseline) %>%
dplyr::rename(movingavgpup = pupil_avg) %>%
dplyr::arrange(subject, trial, time)
}
The first bit of code should be:
baseline <- datafile %>%
dplyr::group_by(subject, trial) %>%
dplyr::filter(time > time[message==event_onset],
time < time[message==event_offset] %>%
dplyr::rename(pupil_avg = pupil_colnames) %>%
dplyr::summarise(baseline = median(pupil_avg)) %>%
ungroup()
Hi Jason,
Thanks for this. I've been trying to get it working but am getting hung up (I believe) with the baseline code. I changed time[message==event_onset] to time[sample_message==event_onset]. I assumed you were calling the column with the messages from eyelink. When I run this code outside of the function the baseline dataframe is empty.
Additionally, is anything intended for the argument: baseline_start=NULL found in the function? I didn't see it in the code.
I will keep working on this myself but if you can see anything that stands out let me know.
Thanks again for your help, Bonnie
On Sat, May 11, 2019 at 2:59 PM jgeller112 notifications@github.com wrote:
The first bit of code should be:
baseline <- datafile %>% dplyr::group_by(subject, trial) %>% dplyr::filter(time > time[message==event_onset], time < time[message==event_offset] %>% dplyr::rename(pupil_avg = pupil_colnames) %>% dplyr::summarise(baseline = median(pupil_avg)) %>% ungroup()
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/dmirman/gazer/issues/10#issuecomment-491535943, or mute the thread https://github.com/notifications/unsubscribe-auth/ALVSILRXIVRMMTTSZ2WNLVLPU4JRXANCNFSM4HLKZ56A .
-- Bonnie M Zuckerman, MS Temple University www.reilly-coglab.com
Sorry about that! I didn’t test the code before posting. I started to write the function, but decided against it in lieu of writing something specific for you. This is why the ‘baseline_start’ argument is not defined. If you solve it before I get to it, please post it here :).
Hi, We managed to get this working! Thank you again. We found that, with both filtering the outliers and MAD, rows with our sample messages were being removed. Is there something wrong with changing the items that normally are removed to NAs?
I am glad you got this working! I think that is a great suggestion.
Sorry for the delay! I think you were using an older version of the paper. The newest version on PsyArXiv does filtering after baseline correction which eliminates that issue you mentioned.
Currently baseline_window within the baseline_correction_pupil function can only take numeric values. Our group would like to use a sample message to mark the onset and offset of a baseline. Some experiments have variable baseline lengths or baselines occur at different times due to an added jitter. Thanks!
something like this: