Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Question about 'mt_time_normalize' function in mousetrap R package

Hi there,

I am a psychology student and I am trying to use mousetrap to analysis some mouse tracking data. Our task is asking the participants to rate their emotion on a x-y coordinate. When I am trying to use mt_time_normalize function to do the temporal normalization, sometimes I will get the error :

Error in stats::approx(trajectories[i, , timestamps], trajectories[i, : need at least two non-NA values to interpolate

I searched about this, and it seems that it's caused by the tied x when y is different (so the code doesn't know how to interpolate between these two points). I speculate that if we add [tied = ordered] in the code for mt_time_normalize this problem may be solved, but I am not sure whether this is the right way to do this.

Hope to get your comments on this issue!

Best,
Haoxue

Comments

  • Hi Haoxue,

    I think that the error is caused by trajectories that contain <= 2 logged positions. I would suggest that you check this in your data and potentially exclude all trajectories with <= 2 logged positions.

    # Load mousetrap library
    library(mousetrap)
    
    # Calculate number of logged positions
    mt_example <- mt_count(mt_example, save_as = "data")
    
    # Table of number of logged positions
    table(mt_example$data$nobs)
    
    # Check if there are trials with 2 or fewer logged positions
    table(mt_example$data$nobs<=2)
    
    # Only keep trials with more than 2 logged positions
    mt_example <- mt_subset(mt_example, nobs>2)
    
    

    Hope this helps. Just let me know if it does not work or if you have additional questions.

    Best,

    Pascal

  • Hi Pascal,

    Thanks for your quick reply! I have now figured out why temporal normalization doesn't work - this is due to in some trials the participants didn't move their mouse at all (because we don't have a required ending point), then something is wrong in the process to align start and end.

    Truly there're a bunch of data with logged position <=2, but now it seems that it isn't the real problem.

    Besides, could you please tell me what exactly 'logged position' means? I am still a little bit confused about this concept.

    Thanks again for this amazing R package and your help!

    Best,
    Haoxue

  • Hi Haoxue,

    indeed there seems to be an additional problem in case all positions in a trial are the same. However, what happens then is that mt_align_start_end does not work properly, result in every positiion to be NaN. This subsequently leads to a problem in mt_time_normalize.

    I would suggest to exclude all trials with identical positions across the whole trial, as these trials (where the cursor was not moved at all) would also not contain any relevant information for computing mouse-tracking indices or creating plots. You could do this using the following code:

    # Calculate variance of positions for each trial
    mt_example$data$pos_var <- apply(mt_example$trajectories[,,"xpos"],1,var,na.rm=TRUE) + apply(mt_example$trajectories[,,"ypos"],1,var,na.rm=TRUE)
    
    # Check if there are trials with 0 variance (i.e., all positions are identical)
    table(mt_example$data$pos_var==0)
    
    # Only keep trials where positions varied
    mt_example <- mt_subset(mt_example, pos_var>0)
    

    With logged positions I just meant that each trial varies with regard to the number of cursor positions that was recorded. If you use the mousetrap plugin in OpenSesame to track mouse movements, it will be default record the cursor position every 10 ms leading to 101 recorded positions for a trial lasting 1 s and 201 recorded positions for a trial lasting 2 s.

    Best,

    Pascal

    Thanked by 1grassnow
Sign In or Register to comment.