Howdy, Stranger!

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

Supported by

Initial Angle of Trajectory

Hello Pascal,

I was wondering if the mousetrap package in R was capable of producing the initial angle of the trajectory. This is a metric I've seen in Coco and Duran, (2016). They define it as:

"(a) initial degree (the degree of deviation from vertical after the mouse trajectory leaves a 50-pixel radius from the starting point, same as Buetti and Kerzel (2009)), where positive values indicate angles towards the incorrect target"

Thanks for any help you can provide. The mousetrap package has been a huge boon to my research.


  • edited June 2019

    Hi Mike,

    we do not calculate it directly. However, the mt_angles function calculates the movement angle for every point of the trajectory, including a vertical based angle. If you find a way to filter the trajectory beforehand so it only contains the start point and the point for which you would like to determine the angle (and the end point), you could use it to get the initial movement angle.


    Pascal (note: I am currently traveling for the next two weeks without steady internet access, so my replies might be a bit delayed)

  • edited July 2019

    Hi Pascal,

    Thank you again for your assistance! I looked into the mt_angle function and was able to produce a plot and aggregated data. I just wanted to confirm that this workflow and output looks reasonable.

    MT_EXP1 <- mt_import_mousetrap(d.EXP1, 
                                  timestamps_label= "timestamps_get_MT", 
                                  xpos_label = "xpos_get_MT",
                                  ypos_label = "ypos_get_MT") 
    MT_EXP1 <- mt_remap_symmetric(MT_EXP1) 
    MT_EXP1 <- mt_align_start(MT_EXP1)
    MT_EXP1 <- mt_angles(MT_EXP1, unit="degree", na_replace=TRUE)
    MT_EXP1_DS <- mt_subset(MT_EXP1, CUESIDE=="DS") 
    # plot the angle by timestamps 
    mt_plot_aggregate(MT_EXP1_DS, use = "trajectories",
                     x = "timestamps", y="angle_v",
                     color = "CUE") +
     geom_line(size=2) +
     scale_color_manual(values=c("red", "black")) +
     ggtitle("EXP 1 - LONG DUR (vertical angle)") + theme(plot.title = element_text(hjust = 0.5)) 
    # aggregate angles 
    EXP1_ang <- mt_aggregate_per_subject(MT_EXP1_DS, use="trajectories",
                                        use2_variables = "CUE",
                                        subject_id = "subject_nr")

    Once I've aggregated the data. Couldn't I just subset the df to the relevant time period (e.g., first 500 ms) to get the initial angle of movement across those timestamps?

    # aggregate angles 
    EXP1_ang <- mt_aggregate_per_subject(MT_EXP1_DS, 
                                        use2_variables = "CUE",
                                        subject_id = "subject_nr")
    # filter to relevant timeperiod
    EXP1_ang_int <- EXP1_ang %>% filter(timestamps < 500)

  • Hi Mike,

    the angle calculation looks fine to me.

    The aggregated plot might be a bit misleading as it averages the values for each specific time point and if one trial only has a recorded position at say timestamp 501 ms it will not be reflected for the timestamp 500. One solution for this could be to use mt_resample before calculating the angle to ensure that the timestamps are identical across trials.

    Afterwards, your code to only look at the first 500 ms is in principle fine in that it will give you the average angle for each timestamp separately for each condition if this is what you want to analyze.



  • Hi Pascal,

    Thanks for the help and sorry for the late reply. I used the mt_resample function and I'm happy to say that nothing appeared to change because of it. I will keep this in mind for the future. Thank you!

Sign In or Register to comment.