samhforbes / PupillometryR

An R package for preparing and analysing pupillometry data
Other
42 stars 4 forks source link

problem with regress function with NA from both eyes #19

Closed irmakoz1 closed 10 months ago

irmakoz1 commented 3 years ago

Hello,

I have pupillometry data from HTC VR, Tobii eye tracker. I have -1 and 0 values as NA. Sometimes it is in both eyes. When I run the regress_data function I receive this error:

Error: Problem with mutate() column pupil1newkk. i pupil1newkk = .predict_right(pupilsDiameterL, pupilsDiameterR). x 0 (non-NA) cases i The error occurred in group 2: SubjectID = "2", Trial = 2, sound = FALSE, light = -0.4997447. Run rlang::last_error() to see where the error occurred.

To be able to correctly smooth and preprocess my data what should I do in this case? I believe this error is due to NA from both eyes. Is there a function to skip or clean up the NA's before running the regress function? In addition, is there an option in the pipeline to exclude data that are above or below certain standard deviation?

sampledata

samhforbes commented 3 years ago

Hi @irmakoz1 Thanks for highlighting this. Firstly I should stress that the regress option simply allows a bit of extra smoothing in binocular recording. If you aren't consistently collecting data from both eyes you can skip this step. But yes it looks like this is occurring because you have a trial where both eyes are consistently NAs. You could clean data first and then attempt this if it helps, but that would be complex as you'd want to do it on both eyes.

Secondly, it will be really important to first set those pupil values to be NA instead of -1 or 0. Otherwise it will massively affect your mean pupil sizes.

irmakoz1 commented 3 years ago

Hello, Thank you for the quick answer. However, in this case the NA values are due to blinks in the time period of the collected data (data is consistently collected, includes interindividual variability of blinks and possible eye tracker errors but no missing time points). If I simply get rid of them then I will have missing time points. To not to have this, it would be better of changing them with average values (missing pupil diameter data) . Is there a function in the pipeline that can deal with the blinks replacing them with proximal mean values, so that I can use the regress function for extra smoothing? ( I am trying to follow the guideline vignette, and could not find any option)

samhforbes commented 3 years ago

Oh that's interesting. I'm not saying get rid of the NA values, to be clear, I am saying that your NA values can't be -1 or 0, as those are numeric values and will affect your calculations. You should change them so they are set to NA rather than -1, if you see my meaning.

Depending on your setup you could use the interpolate_data function to do it, but I would advise against that if you have lots of missing data in one pupil.

irmakoz1 commented 3 years ago

Hello, I am still trying to overcome this problem, I have tried each trial separately, whenever my light value is continuous it gives me errors. I use the light column as the condition and it supposed to be continuous however, due to my experimental design there are some trials that the light value is constant and in those trials pipeline is working.

samhforbes commented 3 years ago

Oh I see - condition is a continuous variable? Do you have a reproducible example you can share with me (by email if possible)? I'd like to see where the issue arises.

samhforbes commented 10 months ago

Closing as inactive, but happy to reopen if needed!