diff --git a/NEWS.md b/NEWS.md index 5a34bd9..bef0c1c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,7 @@ # mousetrap 3.2.2 ## Announcements -* A updated tutorial to movement tracking of psychological processes with the `mousetrap` R package has been published as a preprint. Please cite it as follows when using `mousetrap` in your research: Wulff, D. U.\*, Kieslich, P. J.\*, Henninger, F., Haslbeck, J. M. B., & Schulte-Mecklenbeck, M. (2023). _Movement tracking of psychological processes: A tutorial using mousetrap._ PsyArXiv. https://doi.org/10.31234/osf.io/v685r +* A tutorial to movement tracking of psychological processes with the `mousetrap` R package has been published as a preprint. Please cite it as follows when using `mousetrap` in your research: Wulff, D. U.\*, Kieslich, P. J.\*, Henninger, F., Haslbeck, J. M. B., & Schulte-Mecklenbeck, M. (2023). _Movement tracking of psychological processes: A tutorial using mousetrap._ PsyArXiv. https://doi.org/10.31234/osf.io/v685r ## Bugs fixed * `mt_import_long`: Preserve original trial order when importing trajectories. This also fixes the issue that trajectories are imported incorrectly when `mt_id_label` contains mixed case (closes #17, thanks to @LiKao) @@ -13,6 +13,7 @@ # mousetrap 3.2.1 ## Announcements +* A tutorial to movement tracking of psychological processes with the `mousetrap` R package has been published as a preprint. Please cite it as follows when using `mousetrap` in your research: Wulff, D. U.\*, Kieslich, P. J.\*, Henninger, F., Haslbeck, J. M. B., & Schulte-Mecklenbeck, M. (2021). _Movement tracking of cognitive processes: A tutorial using mousetrap._ PsyArXiv. https://doi.org/10.31234/osf.io/v685r Note that this tutorial has been updated and a new preprint has been published (see 3.2.2 release above). * After more than 5 years, `mousetrap` finally has a logo (thanks to Dirk Wulff) ## General changes to existing functions diff --git a/_pkgdown.yml b/_pkgdown.yml index d6a3241..6778ff9 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -34,7 +34,7 @@ navbar: type: default left: - text: Overview - href: reference/mousetrap.html + href: reference/mousetrap-package.html - text: Reference href: reference/index.html - text: News diff --git a/docs/404.html b/docs/404.html index d4aafd0..42db92e 100644 --- a/docs/404.html +++ b/docs/404.html @@ -32,14 +32,14 @@
diff --git a/docs/authors.html b/docs/authors.html index f473cf1..c59f129 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -17,13 +17,13 @@ -Wulff, D. U., Kieslich, P. J., Henninger, F., Haslbeck, J. M. B., & Schulte-Mecklenbeck, M. (2021). Movement tracking of cognitive processes: A tutorial using mousetrap. PsyArXiv. https://doi.org/10.31234/osf.io/v685r
+Wulff, D. U.*, Kieslich, P. J.*, Henninger, F., Haslbeck, J. M. B., & Schulte-Mecklenbeck, M. (2023). Movement tracking of psychological processes: A tutorial using mousetrap. PsyArXiv. https://doi.org/10.31234/osf.io/v685r
@Misc{, - title = {Movement tracking of cognitive processes: {A} tutorial using mousetrap}, + title = {Movement tracking of psychological processes: {A} tutorial using mousetrap}, author = {Dirk U. Wulff and Pascal J. Kieslich and Felix Henninger and Jonas M. B. Haslbeck and Michael Schulte-Mecklenbeck}, - year = {2021}, + year = {2023}, publisher = {PsyArXiv}, - url = {https://psyarxiv.com/v685r}, + url = {https://osf.io/preprints/psyarxiv/v685r}, doi = {10.31234/osf.io/v685r}, }@@ -101,7 +101,7 @@
The mousetrap package provides functions for importing, preprocessing, +analyzing, aggregating, and visualizing mouse-tracking data. In the +following, a brief overview of the functions in this package is given.
+Depending on the file format, one of the standard R functions for reading +files into R can be used (e.g., read.table or +read.csv).
+If raw data were collected using +MouseTracker, the mousetrap package +provides the read_mt function to read files in the ".mt" format.
+If several raw data files should be read and merged, the +read_bulk function from the +readbulk package can be +used (or the read_opensesame function, if data were +collected using OpenSesame).
+The initial step to prepare data for analysis in the mousetrap package is +to create a mousetrap data object. Depending on the input format, one of +the following functions can be used. A detailed description (and example) +of the resulting mousetrap data object can be found in mt_example.
+mt_import_mousetrap imports mouse-tracking data that were recorded +using the mousetrap +plugin for OpenSesame.
+mt_import_wide imports mouse-tracking data saved in a wide format +(e.g., data collected using +MouseTracker).
+mt_import_long imports mouse-tracking data saved in a long format. +(e.g., trajectories exported using mt_export_long).
+A number of functions are available that perform geometric preprocessing +operations.
+mt_remap_symmetric remaps mouse trajectories to one side (or one +quadrant) of the coordinate system.
+mt_align is a general purpose function for aligning and rescaling +trajectories. For specific operations, you can rely on one of the +following functions.
+mt_align_start aligns the start position of trajectories.
+mt_align_start_end aligns all trajectories so that they share a +common initial and final coordinate (this is also sometimes referred to as +"space-normalization").
+A number of functions are available that perform resampling and +interpolation operations.
+mt_exclude_initiation excludes the initial phase of a trial without +mouse movement.
+mt_exclude_finish excludes a potential phase without mouse movement at the end of a trial.
+mt_time_normalize performs time-normalization using equidistant time +intervals, resulting in an identical number of samples for all +trajectories.
+mt_resample resamples trajectories so that samples occur at constant +intervals of a specified length.
+mt_average averages trajectory coordinates (and related variables) +for time bins of constant duration.
+mt_length_normalize re-represents each trajectory spatially so that +adjacent points on the trajectory become equidistant to each other.
+A number of functions are available for data handling operations, such as +filtering or adding of new variables or trajectories.
+mt_subset filters mouse-tracking data by trials, so that only those +meeting the defined criteria are included.
+mt_add_variables adds new, self created variables to a trajectory +array.
+mt_add_trajectory adds a new trajectory to a trajectory array.
+mt_bind joins two trajectory arrays.
+A number of different analysis procedures and summary statistics for mouse +trajectories have been established in the existing literature. The following +functions implement many of these approaches.
+mt_derivatives calculates distance, velocity, and +acceleration for trajectories.
+mt_angles calculates movement angles for trajectories.
+mt_deviations calculates the deviations from an idealized +trajectory (straight line).
+mt_measures calculates a set of mouse-tracking measures.
+mt_sample_entropy calculates sample entropy.
+mt_standardize standardizes mouse-tracking measures onto a common +scale (separately for subsets of the data, e.g., per participant).
+mt_scale_trajectories provides different options for standardizing +variables in a mouse trajectory array.
+mt_check_bimodality assesses the bimodality of mouse-tracking +measure distributions.
+mt_check_resolution checks the (temporal) logging resolution of raw +trajectories.
+mt_count counts the number of observations for each trajectory.
+A number of different functions for clustering trajectories is provided.
+mt_distmat computes the dissimilarity/distance between each pair of +trajectories.
+mt_cluster performs trajectory clustering with a specified number of +clusters.
+mt_cluster_k estimates the optimal number of clusters using various +methods.
+mt_map maps trajectories onto a predefined set of prototype +trajectories (a core set is provided in mt_prototypes).
+A number of helper functions are provided for aggregating, plotting, and +exporting the multi-dimensional mouse trajectory arrays.
+mt_reshape is a general purpose reshaping and aggregation function +for mousetrap data.
+mt_aggregate aggregates mouse-tracking data per condition.
+mt_aggregate_per_subject aggregates mouse-tracking data per +(within subjects-) condition separately for each subject.
+mt_export_long exports mouse-tracking data in long format.
+mt_export_wide exports mouse-tracking data in wide format.
+The following functions can be used for plotting trajectory data, e.g., +individual and aggregated trajectories or velocity profiles.
+mt_plot plots individual trajectory data.
+mt_plot_aggregate plots aggregated trajectory data.
+mt_plot_add_rect adds rectangles to a trajectory plot.
+mt_plot_riverbed plots the relative frequency of a selected variable +across time.
+mt_plot_per_trajectory creates a pdf with separate plots per +trajectory.
+mt_heatmap and mt_heatmap_ggplot plot trajectory heatmaps.
+mt_diffmap for creating a difference-heatmap of two trajectory +heatmap images.
+mt_animate creates a gif trajectory animation.
+bimodality_coefficient calculates the bimodality coefficient.
+scale_within scales and centers variables within the levels of +another variable.
+bezier creates Bezier-curves using the Bernstein approximation.
+mt_example and mt_example_raw contain a mouse-tracking
+example dataset for demonstrations using the mousetrap
package.
KH2017 and KH2017_raw contain a mouse-tracking dataset from +Kieslich & Henninger (2017).
+Useful links:
if (FALSE) {
+KH2017 <- mt_import_mousetrap(subset(KH2017_raw,correct==1))
+KH2017 <- mt_remap_symmetric(KH2017)
+KH2017 <- mt_align_start(KH2017)
+}
+
+KH2017 <- mt_time_normalize(KH2017)
+KH2017 <- mt_measures(KH2017)
+
+mt_aggregate(
+ KH2017, use="measures",
+ use_variables=c("MAD", "AD"),
+ use2_variables="Condition",
+ subject_id="subject_nr"
+)
+#> Condition MAD AD
+#> 1 Atypical 343.7954 100.36799
+#> 2 Typical 172.2093 39.72137
+
+mt_plot_aggregate(KH2017,
+ use="tn_trajectories",
+ x="xpos", y="ypos", color="Condition",
+ subject_id="subject_nr"
+)
+
+
+if (FALSE) {
+mt_plot(KH2017,
+ use="tn_trajectories",
+ x="xpos", y="ypos", color="Condition"
+)
+}
+
mt_add_trajectory(
- data,
- use = "trajectories",
- save_as = use,
- xpos = NULL,
- ypos = NULL,
- xypos = NULL,
- id = "new"
-)
mt_add_trajectory(
+ data,
+ use = "trajectories",
+ save_as = use,
+ xpos = NULL,
+ ypos = NULL,
+ xypos = NULL,
+ id = "new"
+)
a mousetrap data object created using one of the mt_import
functions (see mt_example for details). Alternatively, a trajectory
array can be provided directly (in this case use
will be ignored).
a character string specifying which trajectory data should be used.
a character string specifying where the resulting trajectory data should be stored.
a vector of x positions. Ignored, if xypos
is provided.
a vector of y positions. Ignored, if xypos
is provided.
a matrix, the first column corresponding to the x positions, the second to the y positions.
a character string specifying the identifier of the to be added trajectory.
A mousetrap data object (see mt_example) where the new + + +
A mousetrap data object (see mt_example) where the new
trajectory has been added.
If the trajectory array was provided directly as data
, only the
trajectory array will be returned.
mt_add_variables(data, use = "trajectories", save_as = use, variables)
mt_add_variables(data, use = "trajectories", save_as = use, variables)
a mousetrap data object created using one of the mt_import
functions (see mt_example for details). Alternatively, a trajectory
array can be provided directly (in this case use
will be ignored).
a character string specifying which trajectory data should be used.
a character string specifying where the resulting trajectory data should be stored.
a list of matrices that each contain the data of one of the to be added variables. In this case, the new variables with @@ -86,10 +92,13 @@
NA
s.A mousetrap data object (see mt_example) where the new + + +
A mousetrap data object (see mt_example) where the new
variables have been added to the trajectory array.
Depending on the input to variables
, the values for the added
variables are either NA
s or their actual values. If columns of the
@@ -105,16 +114,16 @@
# Calculate new (arbitrary) variables for this example
-# ... the sum of the x- and y-positions
-xy_sum <- mt_example$trajectories[,,"xpos"] + mt_example$trajectories[,,"ypos"]
-# ... the product of the x- and y-positions
-xy_prod <- mt_example$trajectories[,,"xpos"] * mt_example$trajectories[,,"ypos"]
-
-# Add the new variables to the trajectory array
-mt_example <- mt_add_variables(mt_example,
- variables=list(xy_sum=xy_sum, xy_prod=xy_prod))
-
+ # Calculate new (arbitrary) variables for this example
+# ... the sum of the x- and y-positions
+xy_sum <- mt_example$trajectories[,,"xpos"] + mt_example$trajectories[,,"ypos"]
+# ... the product of the x- and y-positions
+xy_prod <- mt_example$trajectories[,,"xpos"] * mt_example$trajectories[,,"ypos"]
+
+# Add the new variables to the trajectory array
+mt_example <- mt_add_variables(mt_example,
+ variables=list(xy_sum=xy_sum, xy_prod=xy_prod))
+
mt_aggregate(
- data,
- use = "measures",
- use_variables = NULL,
- use2 = "data",
- use2_variables = NULL,
- subject_id = NULL,
- trajectories_long = TRUE,
- ...
-)
mt_aggregate(
+ data,
+ use = "measures",
+ use_variables = NULL,
+ use2 = "data",
+ use2_variables = NULL,
+ subject_id = NULL,
+ trajectories_long = TRUE,
+ ...
+)
a mousetrap data object created using one of the mt_import
functions (see mt_example for details). Alternatively, a trajectory
array can be provided directly (in this case use
will be ignored).
a character string specifying which dataset should be aggregated.
The corresponding data are selected from data
using
data[[use]]
. Usually, this value corresponds to either
"tn_trajectories" or "measures", depending on whether the time-normalized
trajectories or derived measures should be aggregated.
a character vector specifying the mouse-tracking variables to aggregate. If a data.frame with mouse-tracking measures is @@ -95,21 +99,29 @@
a character string specifying where the data containing the
condition information can be found. Defaults to "data" as
data[["data"]]
usually contains all non mouse-tracking trial data.
Alternatively, a data.frame can be provided directly.
a character string (or vector) specifying the variables
(in data[[use2]]
) across which the trajectories / measures will be
aggregated. For each combination of levels of the grouping variable(s),
aggregation will be performed separately using summarize_at.
an optional character string specifying the column that
contains the subject identifier. If specified, aggregation will be
performed within subjects first (i.e., within subjects for all available
values of the grouping variables specified in use2_variables
).
logical indicating if the reshaped trajectories
should be returned in long or wide format. If TRUE
, every recorded
@@ -119,13 +131,18 @@
xpos_1
,
xpos_2
, ...). Only relevant if data[[use]]
contains
trajectories.additional arguments passed on to mt_reshape (such as
subset
).
A data.frame containing the aggregated data.
+ + +A data.frame containing the aggregated data.
# Time-normalize trajectories
-mt_example <- mt_time_normalize(mt_example)
-
-# Aggregate time-normalized trajectories per condition
-average_trajectories <- mt_aggregate(mt_example,
- use="tn_trajectories",
- use2_variables="Condition"
-)
-
-
-# Calculate mouse-tracking measures
-mt_example <- mt_measures(mt_example)
-
-# Aggregate measures per condition
-average_measures <- mt_aggregate(mt_example,
- use="measures", use_variables=c("MAD", "AD"),
- use2_variables="Condition"
-)
-
-# Aggregate measures per condition
-# first within subjects and then across subjects
-average_measures <- mt_aggregate(mt_example,
- use="measures", use_variables=c("MAD", "AD"),
- use2_variables="Condition",
- subject_id="subject_nr"
-)
-
+ # Time-normalize trajectories
+mt_example <- mt_time_normalize(mt_example)
+
+# Aggregate time-normalized trajectories per condition
+average_trajectories <- mt_aggregate(mt_example,
+ use="tn_trajectories",
+ use2_variables="Condition"
+)
+
+
+# Calculate mouse-tracking measures
+mt_example <- mt_measures(mt_example)
+
+# Aggregate measures per condition
+average_measures <- mt_aggregate(mt_example,
+ use="measures", use_variables=c("MAD", "AD"),
+ use2_variables="Condition"
+)
+
+# Aggregate measures per condition
+# first within subjects and then across subjects
+average_measures <- mt_aggregate(mt_example,
+ use="measures", use_variables=c("MAD", "AD"),
+ use2_variables="Condition",
+ subject_id="subject_nr"
+)
+
mt_align(
- data,
- use = "trajectories",
- save_as = use,
- dimensions = c("xpos", "ypos"),
- coordinates = "isotropic",
- align_start = FALSE,
- align_end = FALSE,
- align_side = "no",
- verbose = FALSE
-)
mt_align(
+ data,
+ use = "trajectories",
+ save_as = use,
+ dimensions = c("xpos", "ypos"),
+ coordinates = "isotropic",
+ align_start = FALSE,
+ align_end = FALSE,
+ align_side = "no",
+ verbose = FALSE
+)
a mousetrap data object created using one of the mt_import
functions (see mt_example for details). Alternatively, a trajectory
array can be provided directly (in this case use
will be ignored).
a character string specifying which trajectory data should be used.
a character string specifying where the resulting trajectory data should be stored.
a character string specifying which trajectory variables should be used. Can be of length 2 or 3 for two-dimensional or three-dimensional alignment respectively.
either a numeric vector of length 4 specifying the xstart, ystart, xend, yend coordinates of the trajectory start and end points. Can @@ -97,26 +105,37 @@
c(0,0,-1,1)
, and wide
to set
coordinates to c(0,0,-1,1.2)
. In the three-dimensional case,
coordinates
is a vector of length 6.boolean specifying whether the start points of all
trajectories should be aligned to the position specified in
coordinates
. See Details.
boolean specifying whether the end points of all trajectories
should be aligned to the position specified in coordinates
. See
Details.
character string specifying whether all trajectories should
be flipped to the left side (left
), the right side (right
),
or not at all (no
). Assumes that first entry in dimensions
are the x positions.
logical indicating whether function should report its progress.
A mousetrap data object (see mt_example) with aligned + + +
A mousetrap data object (see mt_example) with aligned
trajectories. Per default, the dimensions in the original trajectory array
will be replaced. If a different trajectory array is specified using
save_as
, a new trajectory array will be created (including only the
@@ -155,10 +174,10 @@
mt_example <- mt_align(mt_example,
- align_start = TRUE, align_end = TRUE,
- coordinates = 'mt')
-
+ mt_example <- mt_align(mt_example,
+ align_start = TRUE, align_end = TRUE,
+ coordinates = 'mt')
+
a mousetrap data object created using one of the mt_import
functions (see mt_example for details). Alternatively, a trajectory
array can be provided directly (in this case use
will be ignored).
a character string specifying which trajectory data should be used.
a character string specifying where the resulting trajectory data should be stored.
a character vector specifying the dimensions in the trajectory array that should be aligned.
a numeric vector specifying the start values for each dimension,
i.e., the values the first recorded position should have in every trial. If
NULL
, trajectories are aligned to the mean first position across all
trials.
logical indicating whether function should report its progress.
A mousetrap data object (see mt_example) with aligned + + +
A mousetrap data object (see mt_example) with aligned
trajectories. All other trajectory dimensions not specified in
dimensions
(e.g., timestamps) will be kept as is in the resulting
trajectory array. If the trajectory array was provided directly as
@@ -114,21 +127,21 @@
# Import raw trajectories for demonstration
-mt_example <- mt_import_mousetrap(mt_example_raw)
-
-# Align trajectories to start coordinates (0,0)
-mt_example <- mt_align_start(mt_example,
- start=c(0,0))
-
-
-# Import raw trajectories for demonstration
-mt_example <- mt_import_mousetrap(mt_example_raw)
-
-# Align trajectories to mean first coordinates
-mt_example <- mt_align_start(mt_example,
- start=NULL)
-
+ # Import raw trajectories for demonstration
+mt_example <- mt_import_mousetrap(mt_example_raw)
+
+# Align trajectories to start coordinates (0,0)
+mt_example <- mt_align_start(mt_example,
+ start=c(0,0))
+
+
+# Import raw trajectories for demonstration
+mt_example <- mt_import_mousetrap(mt_example_raw)
+
+# Align trajectories to mean first coordinates
+mt_example <- mt_align_start(mt_example,
+ start=NULL)
+
a mousetrap data object created using one of the mt_import
functions (see mt_example for details). Alternatively, a trajectory
array can be provided directly (in this case use
will be ignored).
a character string specifying which trajectory data should be used.
a character string specifying where the resulting trajectory data should be stored.
a character vector specifying the dimensions in the trajectory array that should be aligned.
a numeric vector specifying the start values for each dimension,
i.e., the values the first recorded position should have in every trial. If
NULL
, trajectories are aligned to the mean first position across all
trials.
a numeric vector specifying the end values for each dimension, i.e., the values the last recorded position should have in every trial. If @@ -98,13 +108,18 @@
logical indicating whether function should report its progress.
A mousetrap data object (see mt_example) with aligned + + +
A mousetrap data object (see mt_example) with aligned
trajectories. All other trajectory dimensions not specified in
dimensions
(e.g., timestamps) will be kept as is in the resulting
trajectory array. If the trajectory array was provided directly as
@@ -132,22 +147,22 @@
# Align start and end positions to specific coordinates
-mt_example <- mt_align_start_end(mt_example,
- start=c(0,0), end=c(-1,1))
-
-
-# Import raw trajectories for demonstration
-mt_example <- mt_import_mousetrap(mt_example_raw)
-
-# Remap trajectories
-mt_example <- mt_remap_symmetric(mt_example)
-
-# Align trajectories to mean first and last coordinates
-mt_example <- mt_align_start_end(mt_example,
- start=NULL, end=NULL)
-
-
+ # Align start and end positions to specific coordinates
+mt_example <- mt_align_start_end(mt_example,
+ start=c(0,0), end=c(-1,1))
+
+
+# Import raw trajectories for demonstration
+mt_example <- mt_import_mousetrap(mt_example_raw)
+
+# Remap trajectories
+mt_example <- mt_remap_symmetric(mt_example)
+
+# Align trajectories to mean first and last coordinates
+mt_example <- mt_align_start_end(mt_example,
+ start=NULL, end=NULL)
+
+
mt_angles(
- data,
- use = "trajectories",
- dimensions = c("xpos", "ypos"),
- save_as = use,
- na_replace = FALSE,
- unit = "radian",
- verbose = FALSE
-)
mt_angles(
+ data,
+ use = "trajectories",
+ dimensions = c("xpos", "ypos"),
+ save_as = use,
+ na_replace = FALSE,
+ unit = "radian",
+ verbose = FALSE
+)
a mousetrap data object created using one of the mt_import
functions (see mt_example for details). Alternatively, a trajectory
array can be provided directly (in this case use
will be ignored).
a character string specifying which trajectory data should be used.
a character string specifying which trajectory variables should be used. Must be of length 2.
a character string specifying where the resulting trajectory data should be stored.
logical specifying whether NA
s in the angle values
should be replaced using the next existing angle value (see Details).
Defaults to FALSE
.
character specifying the unit for the angles. Default is "radian", alternative is "degree".
logical indicating whether function should report its progress.
A mousetrap data object (see mt_example) with point-based and + + +
A mousetrap data object (see mt_example) with point-based and
vertical-based angles added as additional variables to the trajectory array
(called angle_p
and angle_v
). If a trajectory array was
provided directly as data
, only the trajectory array will be
@@ -135,14 +150,14 @@
# Calculate movement angles
-mt_example <- mt_angles(mt_example)
-
-# Calculate movement angles (in degree)
-# and replace NAs with next existing value
-mt_example <- mt_angles(mt_example,
- unit="degree", na_replace=TRUE)
-
+ # Calculate movement angles
+mt_example <- mt_angles(mt_example)
+
+# Calculate movement angles (in degree)
+# and replace NAs with next existing value
+mt_example <- mt_angles(mt_example,
+ unit="degree", na_replace=TRUE)
+
mt_animate(
- data,
- use = "trajectories",
- dimensions = c("xpos", "ypos"),
- timestamps = "timestamps",
- filename = "trajectory_animation.gif",
- xres = 1000,
- seconds = 3,
- framerate = 24,
- speed = 0.5,
- density = 3,
- jitter = TRUE,
- remove = FALSE,
- bg = "black",
- col = "white",
- lwd = 1,
- loop = FALSE,
- bounds = NULL,
- norm = FALSE,
- upscale = 1,
- decay = 10,
- max_intensity = 5,
- discard_images = TRUE,
- im_path = NULL,
- parallel = TRUE,
- verbose = FALSE
-)
mt_animate(
+ data,
+ use = "trajectories",
+ dimensions = c("xpos", "ypos"),
+ timestamps = "timestamps",
+ filename = "trajectory_animation.gif",
+ xres = 1000,
+ seconds = 3,
+ framerate = 24,
+ speed = 0.5,
+ density = 3,
+ jitter = TRUE,
+ remove = FALSE,
+ bg = "black",
+ col = "white",
+ lwd = 1,
+ loop = FALSE,
+ bounds = NULL,
+ norm = FALSE,
+ upscale = 1,
+ decay = 10,
+ max_intensity = 5,
+ discard_images = TRUE,
+ im_path = NULL,
+ parallel = TRUE,
+ verbose = FALSE
+)
a mousetrap data object created using one of the mt_import
functions (see mt_example for details). Alternatively, a trajectory
array can be provided directly (in this case use
will be ignored).
a character string specifying which trajectory data should be used.
a character vector specifying the two dimensions in the
trajectory array that contain the mouse positions. Usually (and by
default), the first value in the vector corresponds to the x-positions
(xpos
) and the second to the y-positions (ypos
).
a character string specifying the trajectory dimension
containing the timestamps. If NULL
linearly increasing timestamps
are assumed, producing a perfectly constant timestamp interval.
character string specifying the path and filename of the
resulting .gif. If the extension of filename
is not
.gif, .gif is added at the end. Must not contain spaces.
numeric specifying the resolution of the .gif file.
numeric specifying the duration of the .gif file.
numeric specifying the framerate of the .gif file. Defaults to 24 implying smooth non-discrete frame transitions for the human eye.
numeric specifying the speed of the trajectories with regard to their original velocity profile. I.e., a value of .5 shows trajectories in half of the original velocities, whereas a value of 2 shows trajectories in double of the original velocities.
integer specifying the number of trajectories to be added
each frame. I.e., if density = 10
, seconds = 10
,
framerate = 24
and speed = .5
then the animation will show 10
x 10 x 24 x .5 = 1200 trajectories.
logical specifying whether the density should be jittered. If
TRUE
, density
varies according to
rgeom (1/density
).
logical specifying whether trajectories that reached their end
points should be removed from the rest of the animation. Defaults to
FALSE
implying that all finished trajectories remain visible.
character string specifying the background color.
character string specifying the foreground color, i.e., the color used to draw the trajectories.
numeric specifying the line width of the trajectories.
logical specifying whether gif should be looped. If FALSE
(the default), the last frame will remain visible after the animation is
finished. If TRUE
, the gif will infinitely repeat itself.
numeric vector specifying the xleft, xright, ybottom, and ytop
limits of the animation canvas. Defaults to NULL
in which case the
animation canvas is set to include all existing trajectory points,
irrespective of how extreme they may be.
logical specifying whether the trajectories should be remapped to the mt-space. See mt_align. Note that aligning often requires that that all trajectories are flipped to one side first (see mt_remap_symmetric).
numeric specifying a scaling factor for the animation
resolution. E.g, upscale = 2
implies that the x-resolution in
.gif file is 2*xres
.
numeric defining a within-trajectory gradient of color intensity. Specifically, values larger than 1 will give more recent movements higher color intensities than movements that lie longer in the past, and vice versa.
numeric specifying the maximum color intensity. A value of, e.g., 5, implies that color intensity is limited to 5 overlapping @@ -175,24 +215,33 @@
decay
is unequal 1, this metric
refers to the most intense color point within the trajectory.logical specifying whether the temporary folder containing the temporary .png images should be deleted. Defaults to TRUE.
character string specifying the location of ImageMagick's
convert function. If NULL
, the convert function is
expected in '/usr/local/bin/convert'
, the default location for Linux
and OSX operating systems. The location has to be specified explicitly for
Windows (see Details and Examples).
logical specifying whether the temporary .png images should be created using parallel processing (uses clusterApplyLB). Process will be run on the maximum number of available cores (as determined by detectCores).
logical indicating whether function should report its progress.
if (FALSE) {
-# Preprocess trajectory data
-mt_example <- mt_align_start(mt_example)
-mt_example <- mt_remap_symmetric(mt_example)
-
-# Create animated trajectory gif
-# (under Linux / OSX)
-mt_animate(mt_example,filename = "MyMovie.gif")
-
-# Increase duration and density while decreasing speed
-mt_animate(mt_example, filename = "MyMovie2.gif",
- seconds = 10, speed = .3, density = 10)
-
-# Create animated trajectory gif
-# (under Windows - ImageMagick version specific example)
-mt_animate(mt_example,filename = "MyMovie.gif",
- im_path = "C:/Program Files/ImageMagick-7.0.5-Q16/convert.exe")
-
-}
-
+ if (FALSE) {
+# Preprocess trajectory data
+mt_example <- mt_align_start(mt_example)
+mt_example <- mt_remap_symmetric(mt_example)
+
+# Create animated trajectory gif
+# (under Linux / OSX)
+mt_animate(mt_example,filename = "MyMovie.gif")
+
+# Increase duration and density while decreasing speed
+mt_animate(mt_example, filename = "MyMovie2.gif",
+ seconds = 10, speed = .3, density = 10)
+
+# Create animated trajectory gif
+# (under Windows - ImageMagick version specific example)
+mt_animate(mt_example,filename = "MyMovie.gif",
+ im_path = "C:/Program Files/ImageMagick-7.0.5-Q16/convert.exe")
+
+}
+
mt_average(
- data,
- use = "trajectories",
- save_as = "av_trajectories",
- dimensions = "all",
- av_dimension = "timestamps",
- intervals = NULL,
- interval_size = 100,
- max_interval = NULL,
- verbose = FALSE
-)
mt_average(
+ data,
+ use = "trajectories",
+ save_as = "av_trajectories",
+ dimensions = "all",
+ av_dimension = "timestamps",
+ intervals = NULL,
+ interval_size = 100,
+ max_interval = NULL,
+ verbose = FALSE
+)
a mousetrap data object created using one of the mt_import
functions (see mt_example for details). Alternatively, a trajectory
array can be provided directly (in this case use
will be ignored).
a character string specifying which trajectory data should be used.
a character string specifying where the resulting trajectory data should be stored.
a character vector specifying the dimensions in the
trajectory array that should be averaged. By default ("all"
), all
trajectory dimensions will be averaged.
a character string specifying which values should be used
for determining the intervals for averaging ("timestamps"
by
default).
an optional numeric vector. If specified, these values are
taken as the borders of the intervals (interval_size
and
max_interval
are ignored).
an integer specifying the size of the constant dimension interval.
an integer specifying the upper limit of the last
dimension value that should be included (therefore, it should be a multiple
of the interval_size
). If specified, only values will be used for
averaging where the dimension values are smaller than max_interval
.
If unspecified (the default), all values will be included.
logical indicating whether function should report its progress.
A mousetrap data object (see mt_example) with an additional + + +
A mousetrap data object (see mt_example) with an additional
array (by default called av_trajectories
) that contains the average
trajectory data per dimension interval. If a trajectory array was provided
-directly as data
, only the average trajectories will be returned.
-For the dimension values used for averaging (specified in
+directly as data
, only the average trajectories will be returned.
For the dimension values used for averaging (specified in
av_dimension
), the mid point of the respective interval is reported,
which is helpful for plotting the trajectory data later on. However, this
value does not necessarily correspond to the empirical mean of the
@@ -161,19 +182,19 @@
mt_example <- mt_derivatives(mt_example)
-
-# average trajectories across 100 ms intervals
-mt_example <- mt_average(mt_example, save_as="av_trajectories",
- interval_size=100)
-
-# average time-normalized trajectories across specific intervals
-# of the time steps
-mt_example <- mt_time_normalize(mt_example)
-mt_example <- mt_average(mt_example,
- use="tn_trajectories", save_as="av_tn_trajectories",
- av_dimension = "steps", intervals = c(0.5,33.5,67.5,101.5))
-
+ mt_example <- mt_derivatives(mt_example)
+
+# average trajectories across 100 ms intervals
+mt_example <- mt_average(mt_example, save_as="av_trajectories",
+ interval_size=100)
+
+# average time-normalized trajectories across specific intervals
+# of the time steps
+mt_example <- mt_time_normalize(mt_example)
+mt_example <- mt_average(mt_example,
+ use="tn_trajectories", save_as="av_tn_trajectories",
+ av_dimension = "steps", intervals = c(0.5,33.5,67.5,101.5))
+
mt_bind(trajectories1, trajectories2, verbose = FALSE)
mt_bind(trajectories1, trajectories2, verbose = FALSE)
a trajectory array (see mt_example).
a trajectory array (see mt_example).
logical indicating whether function should report its progress.
A trajectory array.
+ + +A trajectory array.
mt_check_bimodality(
- data,
- use = "measures",
- use_variables = NULL,
- methods = c("BC", "HDS"),
- B = 2000,
- grouping_variables = NULL,
- ...
-)
mt_check_bimodality(
+ data,
+ use = "measures",
+ use_variables = NULL,
+ methods = c("BC", "HDS"),
+ B = 2000,
+ grouping_variables = NULL,
+ ...
+)
a mousetrap data object created using one of the mt_import functions (see mt_example for details).
a character string specifying which data should be used. By
default, points to the measures
data.frame created using
mt_measures.
a vector specifying for which mouse-tracking measures bimodality should be assessed.
a character string (or vector) specifying which methods should be used for assessing bimodality (see Details).
an integer specifying the number of replicates used in the Monte Carlo test (only relevant if "HDS_sim" is included in methods, see Details).
a character string (or vector) specifying one or
more variables in data[["data"]]
. If specified, bimodality will be
assessed separately for each level of the variable. If unspecified (the
default), bimodality is checked across all trials.
additional arguments passed on to mt_reshape (such as
subset
).
A list of several data.frames. Each data.frame contains the value + + +
A list of several data.frames. Each data.frame contains the value returned by the respective method for assessing bimodality (see Details) - separately per condition (specified in the row dimension) and measure (specified in the column dimension).
@@ -157,12 +172,12 @@# Calculate measures
-mt_example <- mt_measures(mt_example)
-
-# Assess bimodality for untransformed variables
-mt_check_bimodality(mt_example,
- use_variables=c("MAD", "AD"))
+ # Calculate measures
+mt_example <- mt_measures(mt_example)
+
+# Assess bimodality for untransformed variables
+mt_check_bimodality(mt_example,
+ use_variables=c("MAD", "AD"))
#> $BC
#> MAD AD
#> 1 0.6239962 0.7714127
@@ -171,14 +186,14 @@ Examples
#> MAD AD
#> 1 0.949304 0.9805709
#>
-
-# Standardize variables per participant
-mt_example <- mt_standardize(mt_example,
- use_variables=c("MAD", "AD"), within="subject_nr")
-
-# Assess bimodality for standardized variables
-mt_check_bimodality(mt_example,
- use_variables=c("z_MAD", "z_AD"))
+
+# Standardize variables per participant
+mt_example <- mt_standardize(mt_example,
+ use_variables=c("MAD", "AD"), within="subject_nr")
+
+# Assess bimodality for standardized variables
+mt_check_bimodality(mt_example,
+ use_variables=c("z_MAD", "z_AD"))
#> $BC
#> z_MAD z_AD
#> 1 0.5099593 0.7212444
@@ -187,24 +202,24 @@ Examples
#> z_MAD z_AD
#> 1 0.7749003 0.7463675
#>
-
-# Assess bimodality with simulated p values for HDS
-mt_check_bimodality(mt_example,
- use_variables=c("z_MAD", "z_AD"),
- methods=c("BC", "HDS_sim"))
+
+# Assess bimodality with simulated p values for HDS
+mt_check_bimodality(mt_example,
+ use_variables=c("z_MAD", "z_AD"),
+ methods=c("BC", "HDS_sim"))
#> $BC
#> z_MAD z_AD
#> 1 0.5099593 0.7212444
#>
#> $HDS_simulated_p_value
-#> z_MAD z_AD
-#> 1 0.7965 0.7475
+#> z_MAD z_AD
+#> 1 0.7855 0.753
#>
-
-# Assess bimodality per condition
-mt_check_bimodality(mt_example,
- use_variables=c("z_MAD", "z_AD"),
- grouping_variables="Condition")
+
+# Assess bimodality per condition
+mt_check_bimodality(mt_example,
+ use_variables=c("z_MAD", "z_AD"),
+ grouping_variables="Condition")
#> $BC
#> Condition z_MAD z_AD
#> 1 Atypical 0.4056693 0.3430277
@@ -215,7 +230,7 @@ Examples
#> 1 Atypical 0.3458943 0.4716631
#> 2 Typical 0.9831558 0.9923261
#>
-
+
mt_check_resolution(
- data,
- use = "trajectories",
- timestamps = "timestamps",
- desired = NULL,
- digits = NULL
-)
mt_check_resolution(
+ data,
+ use = "trajectories",
+ timestamps = "timestamps",
+ desired = NULL,
+ digits = NULL
+)
a mousetrap data object created using one of the mt_import
functions (see mt_example for details). Alternatively, a trajectory
array can be provided directly (in this case use
will be ignored).
a character string specifying which trajectory data should be used.
a character string specifying the trajectory dimension containing the timestamps.
an optional integer. If specified, additional statistics are computed concerning the (relative) frequencies with which exactly the desired timestamp difference (with tolerance 1e-12) occurred.
an optional integer. If specified, timestamps will be rounded before performing any checks. Potentially useful if timestamps are recorded with submillisecond precision.
A list with various descriptive statistics. For convenience, the + + +
A list with various descriptive statistics. For convenience, the relative frequencies are rounded to 4 decimal places.
mt_check_resolution(mt_example)
+ mt_check_resolution(mt_example)
#> $summary
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
#> 1.000 10.000 10.000 9.977 10.000 14.000
@@ -133,7 +144,7 @@ Examples
#> 1 2 3 4 6 7 8 10 11 14
#> 0.0005 0.0009 0.0005 0.0001 0.0011 0.0005 0.0011 0.9944 0.0007 0.0001
#>
-
+
mt_cluster(
- data,
- use = "ln_trajectories",
- save_as = "clustering",
- dimensions = c("xpos", "ypos"),
- n_cluster = 5,
- method = "hclust",
- weights = rep(1, length(dimensions)),
- pointwise = TRUE,
- minkowski_p = 2,
- hclust_method = "ward.D",
- kmeans_nstart = 10,
- na_rm = FALSE,
- cluster_output = FALSE,
- verbose = FALSE
-)
mt_cluster(
+ data,
+ use = "ln_trajectories",
+ save_as = "clustering",
+ dimensions = c("xpos", "ypos"),
+ n_cluster = 5,
+ method = "hclust",
+ weights = rep(1, length(dimensions)),
+ pointwise = TRUE,
+ minkowski_p = 2,
+ hclust_method = "ward.D",
+ kmeans_nstart = 10,
+ na_rm = FALSE,
+ cluster_output = FALSE,
+ verbose = FALSE
+)
a mousetrap data object created using one of the mt_import
functions (see mt_example for details). Alternatively, a trajectory
array can be provided directly (in this case use
will be ignored).
a character string specifying which trajectory data should be used.
a character string specifying where the resulting data should be stored.
a character vector specifying which trajectory variables should be used. Can be of length 2 or 3, for two-dimensional or three-dimensional trajectories respectively.
an integer specifying the number of clusters to estimate.
character string specifying the clustering procedure. Either hclust (the default) or kmeans.
numeric vector specifying the relative importance of the
variables specified in dimensions
. Defaults to a vector of 1s
implying equal importance. Technically, each variable is rescaled so that
the standard deviation matches the corresponding value in weights
.
To use the original variables, set weights = NULL
.
boolean specifying the way in which dissimilarity between
the trajectories is measured. If TRUE
(the default),
@@ -113,39 +127,54 @@
method
is "hclust". See mt_distmat for further
details.an integer specifying the distance metric for the cluster
solution. minkowski_p = 1
computes the city-block distance,
minkowski_p = 2
(the default) computes the Euclidian distance,
minkowski_p = 3
the cubic distance, etc. Only relevant if
method
is "hclust". See mt_distmat for further details.
character string specifying the linkage criterion used.
Passed on to the method
argument of hclust. Default is
set to ward.D
. Only relevant if method
is "hclust".
integer specifying the number of reruns of the kmeans
procedure. Larger numbers minimize the risk of finding local minima. Passed
on to the nstart
argument of kmeans. Only relevant if
method
is "kmeans".
logical specifying whether trajectory points containing NAs should be removed. Removal is done column-wise. That is, if any trajectory has a missing value at, e.g., the 10th recorded position, the 10th position is removed for all trajectories. This is necessary to compute distance between trajectories.
logical. If FALSE
(the default), the mousetrap
data object with the cluster assignments is returned (see Value). If
TRUE
, the output of the cluster method (kmeans
or
hclust
) is returned directly.
logical indicating whether function should report its progress.
A mousetrap data object (see mt_example) with an additional + + +
A mousetrap data object (see mt_example) with an additional
data.frame added to it (by default called clustering
) that
contains the cluster assignments. If a trajectory array was provided
directly as data
, only the clustering data.frame
will be
@@ -177,7 +206,7 @@
Wulff, D. U., Kieslich, P. J., Henninger, F., Haslbeck, J. M. B., & -Schulte-Mecklenbeck, M. (2021). Movement tracking of cognitive +Schulte-Mecklenbeck, M. (2023). Movement tracking of psychological processes: A tutorial using mousetrap. PsyArXiv. -doi: 10.31234/osf.io/v685r
+doi:10.31234/osf.io/v685rWulff, D. U., Haslbeck, J. M. B., & Schulte-Mecklenbeck, M. (2022). Measuring the (dis-)continuous mind: What movement trajectories reveal about cognition. Manuscript in preparation.
@@ -208,17 +237,17 @@# Length normalize trajectories
-KH2017 <- mt_length_normalize(KH2017)
-
-# Cluster trajectories
-KH2017 <- mt_cluster(KH2017, use="ln_trajectories")
-
-# Plot clustered trajectories
-mt_plot(KH2017,use="ln_trajectories",
- use2="clustering",facet_col="cluster")
+ # Length normalize trajectories
+KH2017 <- mt_length_normalize(KH2017)
+
+# Cluster trajectories
+KH2017 <- mt_cluster(KH2017, use="ln_trajectories")
+
+# Plot clustered trajectories
+mt_plot(KH2017,use="ln_trajectories",
+ use2="clustering",facet_col="cluster")
-
+
mt_cluster_k(
- data,
- use = "ln_trajectories",
- dimensions = c("xpos", "ypos"),
- kseq = 2:15,
- compute = c("stability", "gap", "jump", "slope"),
- method = "hclust",
- weights = rep(1, length(dimensions)),
- pointwise = TRUE,
- minkowski_p = 2,
- hclust_method = "ward.D",
- kmeans_nstart = 10,
- n_bootstrap = 10,
- model_based = FALSE,
- n_gap = 10,
- na_rm = FALSE,
- verbose = FALSE
-)
mt_cluster_k(
+ data,
+ use = "ln_trajectories",
+ dimensions = c("xpos", "ypos"),
+ kseq = 2:15,
+ compute = c("stability", "gap", "jump", "slope"),
+ method = "hclust",
+ weights = rep(1, length(dimensions)),
+ pointwise = TRUE,
+ minkowski_p = 2,
+ hclust_method = "ward.D",
+ kmeans_nstart = 10,
+ n_bootstrap = 10,
+ model_based = FALSE,
+ n_gap = 10,
+ na_rm = FALSE,
+ verbose = FALSE
+)
a mousetrap data object created using one of the mt_import
functions (see mt_example for details). Alternatively, a trajectory
array can be provided directly (in this case use
will be ignored).
a character string specifying which trajectory data should be used.
a character vector specifying which trajectory variables should be used. Can be of length 2 or 3, for two-dimensional or three-dimensional trajectories respectively.
a numeric vector specifying set of candidates for k. Defaults to
2:15, implying that all values of k within that range are compared using
the metrics specified in compute
.
character vector specifying the to be computed measures. Can
be any subset of c("stability","gap","jump","slope")
.
character string specifying the type of clustering procedure
for the stability-based method. Either hclust
or kmeans
.
numeric vector specifying the relative importance of the
variables specified in dimensions
. Defaults to a vector of 1s
implying equal importance. Technically, each variable is rescaled so that
the standard deviation matches the corresponding value in weights
.
To use the original variables, set weights = NULL
.
boolean specifying the way in which dissimilarity between
the trajectories is measured. If TRUE
(the default),
@@ -113,44 +127,63 @@
method
is "hclust". See mt_distmat for further
details.an integer specifying the distance metric for the cluster
solution. minkowski_p = 1
computes the city-block distance,
minkowski_p = 2
(the default) computes the Euclidian distance,
minkowski_p = 3
the cubic distance, etc. Only relevant if
method
is "hclust". See mt_distmat for further details.
character string specifying the linkage criterion used.
Passed on to the method
argument of hclust. Default is
set to ward.D
. Only relevant if method
is "hclust".
integer specifying the number of reruns of the kmeans
procedure. Larger numbers minimize the risk of finding local minima. Passed
on to the nstart
argument of kmeans. Only relevant if
method
is "kmeans".
an integer specifying the number of bootstrap comparisons
used by stability
. See cStability.
boolean specifying whether the model-based or the
model-free should be used by stability
, when method is
kmeans
. See cStability and Haslbeck & Wulff (2020).
integer specifying the number of simulated datasets used by
gap
. See Tibshirani et al. (2001).
logical specifying whether trajectory points containing NAs should be removed. Removal is done column-wise. That is, if any trajectory has a missing value at, e.g., the 10th recorded position, the 10th position is removed for all trajectories. This is necessary to compute distance between trajectories.
logical indicating whether function should report its progress.
A list containing two lists that store the results of the different + + +
A list containing two lists that store the results of the different
methods. kopt
contains the estimated k
for each of the
methods specified in compute
. paths
contains the values for
each k
in kseq
as computed by each of the methods specified
@@ -213,19 +246,19 @@
-if (FALSE) {
-# Length normalize trajectories
-KH2017 <- mt_length_normalize(KH2017)
-
-# Find k
-results <- mt_cluster_k(KH2017, use="ln_trajectories")
-
-# Retrieve results
-results$kopt
-results$paths
-}
-
+
+if (FALSE) {
+# Length normalize trajectories
+KH2017 <- mt_length_normalize(KH2017)
+
+# Find k
+results <- mt_cluster_k(KH2017, use="ln_trajectories")
+
+# Retrieve results
+results$kopt
+results$paths
+}
+
mt_count(data, use = "trajectories", save_as = "measures", dimensions = "xpos")
mt_count(data, use = "trajectories", save_as = "measures", dimensions = "xpos")
a mousetrap data object created using one of the mt_import
functions (see mt_example for details). Alternatively, a trajectory
array can be provided directly (in this case use
will be ignored).
a character string specifying which trajectory data should be used.
a character string specifying where the resulting trajectory data should be stored.
a character vector specifying the name of the dimension(s) that should be used for counting the number of observations. If several dimensions are specified, the number of complete observations are reported.
A mousetrap data object (see mt_example).
-If a data.frame with label specified in save_as
(by default
+
+
+
A mousetrap data object (see mt_example).
+ + +If a data.frame with label specified in save_as
(by default
"measures") already exists, the number of observations (called nobs
)
-are added as additional column. If not, an additional data.framewill be added.
-If a trajectory array was provided directly as data
, only a named
+are added as additional column. If not, an additional data.frame
will be added.
+ + +If a trajectory array was provided directly as data
, only a named
character vector will be returned.
mt_derivatives(
- data,
- use = "trajectories",
- save_as = use,
- dimensions = c("xpos", "ypos"),
- timestamps = "timestamps",
- prefix = "",
- absolute = FALSE,
- return_delta_time = FALSE,
- verbose = FALSE
-)
mt_derivatives(
+ data,
+ use = "trajectories",
+ save_as = use,
+ dimensions = c("xpos", "ypos"),
+ timestamps = "timestamps",
+ prefix = "",
+ absolute = FALSE,
+ return_delta_time = FALSE,
+ verbose = FALSE
+)
a mousetrap data object created using one of the mt_import
functions (see mt_example for details). Alternatively, a trajectory
array can be provided directly (in this case use
will be ignored).
a character string specifying which trajectory data should be used.
a character string specifying where the resulting trajectory data should be stored.
a character vector specifying across which dimension(s)
distances, velocity, and acceleration are calculated. By default
(c("xpos","ypos")
), they are calculated across both x and y
dimensions. Alternatively, only one dimension can be specified, e.g.,
"xpos"
or "ypos"
.
a character string specifying the trajectory dimension containing the timestamps.
an optional character string that is added as a prefix to the to be created new trajectory dimensions.
logical indicating if absolute values for distances and
velocities should be reported. Only relevant if a single dimension is
specified in dimensions
(see Details).
logical indicating if the timestamp differences should be returned as well (as "delta_time").
logical indicating whether function should report its progress.
A mousetrap data object (see mt_example) with Euclidian + + +
A mousetrap data object (see mt_example) with Euclidian
distance, velocity, and acceleration added as additional variables to the
trajectory array (called dist
, vel
, and acc
, if no
prefix was specified). If the trajectory array was provided directly as
@@ -157,15 +176,15 @@
# Calculate derivatives looking at movement
-# across both dimensions
-mt_example <- mt_derivatives(mt_example)
-
-# Calculate derivatives only looking at movement along x dimension
-# reporting absolute values for distance and velocity
-mt_example <- mt_derivatives(mt_example,
- dimensions="xpos", absolute=TRUE)
-
+ # Calculate derivatives looking at movement
+# across both dimensions
+mt_example <- mt_derivatives(mt_example)
+
+# Calculate derivatives only looking at movement along x dimension
+# reporting absolute values for distance and velocity
+mt_example <- mt_derivatives(mt_example,
+ dimensions="xpos", absolute=TRUE)
+
mt_deviations(
- data,
- use = "trajectories",
- save_as = use,
- dimensions = c("xpos", "ypos"),
- start_ideal = NULL,
- end_ideal = NULL,
- prefix = "",
- verbose = FALSE
-)
mt_deviations(
+ data,
+ use = "trajectories",
+ save_as = use,
+ dimensions = c("xpos", "ypos"),
+ start_ideal = NULL,
+ end_ideal = NULL,
+ prefix = "",
+ verbose = FALSE
+)
a mousetrap data object created using one of the mt_import
functions (see mt_example for details). Alternatively, a trajectory
array can be provided directly (in this case use
will be ignored).
a character string specifying which trajectory data should be used.
a character string specifying where the resulting trajectory data should be stored.
a character vector specifying the two dimensions in the
trajectory array that contain the mouse positions. By default
(c("xpos","ypos")
), the x- and y-positions are used.
an optional vector specifying the start position (see Example). If specified, this position will be used as the starting point of the idealized trajectory (instead of the actual starting point).
an optional vector specifying the end position (see Example). If specified, this position will be used as the end point of the idealized trajectory (instead of the actual end point).
an optional character string that is added as a prefix to the to be created new trajectory dimensions.
logical indicating whether function should report its progress.
A mousetrap data object (see mt_example) where the positions + + +
A mousetrap data object (see mt_example) where the positions
of the idealized trajectory (by default called xpos_ideal
and
ypos_ideal
) and the perpendicular deviations of the actual
trajectory from the idealized trajectory (by default called
@@ -144,15 +161,15 @@
# Calculate deviations from idealized trajectory
-# (straight line connecting the start and end point of each trial)
-mt_example <- mt_deviations(mt_example)
-
-# Calculate deviations from idealized trajectory with
-# constant start and end points across trials
-mt_example <- mt_deviations(mt_example,
- start_ideal=c(0,0), end_ideal=c(-665,974))
-
+ # Calculate deviations from idealized trajectory
+# (straight line connecting the start and end point of each trial)
+mt_example <- mt_deviations(mt_example)
+
+# Calculate deviations from idealized trajectory with
+# constant start and end points across trials
+mt_example <- mt_deviations(mt_example,
+ start_ideal=c(0,0), end_ideal=c(-665,974))
+
mt_diffmap(
- x,
- y = NULL,
- condition = NULL,
- use = "trajectories",
- dimensions = c("xpos", "ypos"),
- use2 = "data",
- filename = NULL,
- bounds = NULL,
- xres = 500,
- upscale = 4,
- smooth_radius = 10,
- colors = c("#00863F", "#000000", "#FF1900"),
- n_shades = 1000,
- plot = TRUE,
- ...,
- verbose = TRUE
-)
mt_diffmap(
+ x,
+ y = NULL,
+ condition = NULL,
+ use = "trajectories",
+ dimensions = c("xpos", "ypos"),
+ use2 = "data",
+ filename = NULL,
+ bounds = NULL,
+ xres = 500,
+ upscale = 4,
+ smooth_radius = 10,
+ colors = c("#00863F", "#000000", "#FF1900"),
+ n_shades = 1000,
+ plot = TRUE,
+ ...,
+ verbose = TRUE
+)
an object of class mousetrap
), a trajectory object of class
array
, or an object of class mt_heatmap_raw
(as created by
mt_heatmap_raw).
an object of class mousetrap
), a trajectory object of class
array
, or an object of class mt_heatmap_raw
(as created by
mt_heatmap_raw). The class of y
must match the class of
x
, unless y
is NULL
.
either a character value specifying which variable codes the
two conditions (in x[[use2]]
) that should be compared - or a vector
@@ -99,57 +103,84 @@
condition
is specified,
y
will be ignored (unless x
and y
are of class
heatmap_raw
).a character string specifying which trajectory data should be used.
a character vector specifying the trajectory variables used to create the heatmap. The first two entries are used as x and y-coordinates, the third, if provided, will be added as color information.
an optional character string specifying where the data that
contain the condition variable can be found. Defaults to "data" as
x[["data"]]
usually contains all non mouse-tracking trial data.
a character string giving the name of the file. If
NULL
(the default), the R standard device is used for plotting.
Otherwise, the plotting device is inferred from the file extension. Only
supports devices tiff, png,
pdf.
numeric vector specifying the corners (xmin, ymin, xmax, ymax)
of the plot region. By default (bounds = NULL
), bounds are
determined based on the data input.
an integer specifying the number of pixels along the x-dimension.
An xres
of 1000 implies an 1000*N px, where N is determined so that
the trajectories aspect ratio is preserved (provided the bounds
are
unchanged).
a numeric value by which the output resolution of the image is increased or decreased. Only applies if device is one of tiff, png, or pdf.
a numeric value specifying the standard deviation of the gaussian smoothing. If zero, smoothing is omitted.
a character vector specifying the colors used to color
cases of image1 > image2, image1 ~ image2, image1 < image2
,
respectively. Note that the colors are used in that specific order.
Defaults to c("#00863F", "#FFFFFF", "#FF1900") which specifies
a green-black-red color gradient.
integer specifying the number of shades for the color
gradient between the first and second, and the second and third color in
colors
.
logical specifying whether resulting image should be plotted
(plot = TRUE
, the default). If (plot = FALSE
), an object of
class mt_object_raw
is returned.
arguments passed to mt_heatmap_raw.
logical indicating whether function should report its progress.
mt_diffmap(KH2017, condition="Condition",
- xres=400, smooth_radius=6, n_shades=5)
+ mt_diffmap(KH2017, condition="Condition",
+ xres=400, smooth_radius=6, n_shades=5)
#> Determine joint bounds
#> Calculating heatmap for x
#> Calculating heatmap for y
@@ -192,7 +223,7 @@ Examples
#> creating heatmap: 400 x 245 px
#> heatmap created in 2s
-
+
a mousetrap data object created using one of the mt_import
functions (see mt_example for details). Alternatively, a trajectory
array can be provided directly (in this case use
will be ignored).
a character string specifying which trajectory data should be used.
a character string specifying where the resulting data should be stored.
a character vector specifying which trajectory variables should be used. Can be of length 2 or 3 for two-dimensional or three-dimensional trajectories respectively.
numeric vector specifying the relative importance of the
variables specified in dimensions
. Defaults to a vector of 1s
implying equal importance. Technically, each variable is rescaled so that
the standard deviation matches the corresponding value in weights
.
To use the original variables, set weights = NULL
.
boolean specifying the way dissimilarity between the
trajectories is measured (see Details). If TRUE
(the default),
mt_distmat
measures the average dissimilarity and then sums the
results. If FALSE
, mt_distmat
measures dissimilarity once
(by treating the various points as independent dimensions).
an integer specifying the distance metric.
minkowski_p = 1
computes the city-block distance, minkowski_p
= 2
(the default) computes the Euclidian distance, minkowski_p = 3
the cubic distance, etc.
logical specifying whether trajectory points containing NAs should be removed. Removal is done column-wise. That is, if any trajectory has a missing value at, e.g., the 10th recorded position, the 10th position is removed for all trajectories. This is necessary to compute distance between trajectories.
A mousetrap data object (see mt_example) with an additional + + +
A mousetrap data object (see mt_example) with an additional
object added (by default called distmat
) containing the distance
matrix. If a trajectory array was provided directly as data
, only
the distance matrix will be returned.
# Length normalize trajectories
-mt_example <- mt_length_normalize(mt_example)
-
-# Compute distance matrix
-mt_example <- mt_distmat(mt_example, use="ln_trajectories")
-
+ # Length normalize trajectories
+mt_example <- mt_length_normalize(mt_example)
+
+# Compute distance matrix
+mt_example <- mt_distmat(mt_example, use="ln_trajectories")
+
mt_example
mt_example
mt_example_raw
mt_example_raw
Kieslich, P. J., & Henninger, F. (2017). Mousetrap: An integrated, open-source mouse-tracking package. Behavior Research -Methods, 49(5), 1652-1667. doi: 10.3758/s13428-017-0900-z
+Methods, 49(5), 1652-1667. doi:10.3758/s13428-017-0900-zDale, R., Kehoe, C., & Spivey, M. J. (2007). Graded motor responses in the time course of categorizing atypical exemplars. Memory & Cognition, -35(1), 15-28. doi: 10.3758/BF03195938
+35(1), 15-28. doi:10.3758/BF03195938mt_exclude_finish(
- data,
- use = "trajectories",
- save_as = use,
- dimensions = c("xpos", "ypos"),
- timestamps = "timestamps",
- verbose = FALSE
-)
mt_exclude_finish(
+ data,
+ use = "trajectories",
+ save_as = use,
+ dimensions = c("xpos", "ypos"),
+ timestamps = "timestamps",
+ verbose = FALSE
+)
a mousetrap data object created using one of the mt_import
functions (see mt_example for details). Alternatively, a trajectory
array can be provided directly (in this case use
will be ignored).
a character string specifying which trajectory data should be used.
a character string specifying where the resulting trajectory data should be stored.
a character vector specifying the dimensions in the trajectory array that contain the mouse positions.
a character string specifying the trajectory dimension containing the timestamps.
logical indicating whether function should report its progress.
A mousetrap data object (see mt_example) from which a + + +
A mousetrap data object (see mt_example) from which a
potential phase without mouse movement at the end of the trial was removed.
If the trajectory array was provided directly as data
, only the
trajectory array will be returned.
mt_example <- mt_exclude_finish(mt_example,
- save_as="mod_trajectories")
-
+ mt_example <- mt_exclude_finish(mt_example,
+ save_as="mod_trajectories")
+
mt_exclude_initiation(
- data,
- use = "trajectories",
- save_as = use,
- dimensions = c("xpos", "ypos"),
- timestamps = "timestamps",
- reset_timestamps = TRUE,
- verbose = FALSE
-)
mt_exclude_initiation(
+ data,
+ use = "trajectories",
+ save_as = use,
+ dimensions = c("xpos", "ypos"),
+ timestamps = "timestamps",
+ reset_timestamps = TRUE,
+ verbose = FALSE
+)
a mousetrap data object created using one of the mt_import
functions (see mt_example for details). Alternatively, a trajectory
array can be provided directly (in this case use
will be ignored).
a character string specifying which trajectory data should be used.
a character string specifying where the resulting trajectory data should be stored.
a character vector specifying the dimensions in the trajectory array that contain the mouse positions.
a character string specifying the trajectory dimension containing the timestamps.
logical indicating whether the timestamps should be reset after removing the initial phase without movement (see Details).
logical indicating whether function should report its progress.
A mousetrap data object (see mt_example) from which the + + +
A mousetrap data object (see mt_example) from which the
initial phase without mouse movement was removed. If the trajectory array
was provided directly as data
, only the trajectory array will be
returned.
mt_example <- mt_exclude_initiation(mt_example,
- save_as="mod_trajectories")
-
+ mt_example <- mt_exclude_initiation(mt_example,
+ save_as="mod_trajectories")
+
mt_export_long(
- data,
- use = "trajectories",
- use_variables = NULL,
- use2 = "data",
- use2_variables = NULL,
- ...
-)
-
-mt_export_wide(
- data,
- use = "trajectories",
- use_variables = NULL,
- use2 = "data",
- use2_variables = NULL,
- ...
-)
mt_export_long(
+ data,
+ use = "trajectories",
+ use_variables = NULL,
+ use2 = "data",
+ use2_variables = NULL,
+ ...
+)
+
+mt_export_wide(
+ data,
+ use = "trajectories",
+ use_variables = NULL,
+ use2 = "data",
+ use2_variables = NULL,
+ ...
+)
a mousetrap data object created using one of the mt_import
functions (see mt_example for details). Alternatively, a trajectory
array can be provided directly (in this case use
will be ignored).
a character string specifying which data should be exported. The
corresponding data are selected from data using data[[use]]
.
Usually, this value corresponds to either "trajectories" or
"tn_trajectories", depending on whether the raw or the time-normalized
trajectories should be exported.
a character vector specifying which mouse-tracking variables should be exported. This corresponds to the labels of the trajectory array dimensions. If unspecified, all variables will be exported.
an optional character string specifying where the other trial
data can be found. Defaults to "data" as data[["data"]]
usually
contains all non mouse-tracking trial data. Alternatively, a data.frame can
be provided directly.
an optional character string (or vector) specifying the
variables (in data[[use2]]
) that should be merged with the data.
additional arguments passed on to mt_reshape (such as
subset
).
mt_export_long
: Export mouse-tracking data in long format
mt_export_wide
: Export mouse-tracking data in wide format
mt_export_long()
: Export mouse-tracking data in long format
mt_export_wide()
: Export mouse-tracking data in wide format
# Export data in long format
-# (and include information about condition and subject_nr)
-mt_data_long <- mt_export_long(mt_example,
- use2_variables=c("subject_nr","Condition"))
-
-# Export data in wide format
-# (and include information about condition and subject_nr)
-mt_data_wide <- mt_export_wide(mt_example,
- use2_variables=c("subject_nr","Condition"))
-
+ # Export data in long format
+# (and include information about condition and subject_nr)
+mt_data_long <- mt_export_long(mt_example,
+ use2_variables=c("subject_nr","Condition"))
+
+# Export data in wide format
+# (and include information about condition and subject_nr)
+mt_data_wide <- mt_export_wide(mt_example,
+ use2_variables=c("subject_nr","Condition"))
+
mt_heatmap(
- x,
- use = "trajectories",
- dimensions = c("xpos", "ypos"),
- filename = NULL,
- ...,
- upscale = 1,
- plot_dims = FALSE,
- verbose = TRUE
-)
mt_heatmap(
+ x,
+ use = "trajectories",
+ dimensions = c("xpos", "ypos"),
+ filename = NULL,
+ ...,
+ upscale = 1,
+ plot_dims = FALSE,
+ verbose = TRUE
+)
usually an object of class mousetrap
. Alternatively, a
trajectory array or an object of class mt_heatmap_raw
.
a character string specifying which trajectory data should be used.
a character vector specifying the trajectory variables used to create the heatmap. The first two entries are used as x and y-coordinates, the third, if provided, will be added as color information.
a character string giving the name of the file. If
NULL
(the default), the R standard device is used for plotting.
Otherwise, the plotting device is inferred from the file extension. Only
supports devices tiff, png,
pdf.
arguments passed to mt_heatmap_raw.
a numeric value by which the output resolution of the image is increased or decreased. Only applies if device is one of tiff, png, or pdf.
adds the coordinates of the four image corners to the plot.
Helps setting bounds
.
logical indicating whether function should report its progress.
mt_heatmap(KH2017, xres=500, n_shades=5, mean_image=0.2)
+ mt_heatmap(KH2017, xres=500, n_shades=5, mean_image=0.2)
#> spatializing trajectories
#> calculate image
#> smooth image
@@ -143,7 +158,7 @@ Examples
#> creating heatmap: 500 x 308 px
#> heatmap created in 1s
-
+
mt_heatmap_ggplot(
- data,
- use = "trajectories",
- dimensions = c("xpos", "ypos"),
- use2 = "data",
- facet_row = NULL,
- facet_col = NULL,
- ...
-)
mt_heatmap_ggplot(
+ data,
+ use = "trajectories",
+ dimensions = c("xpos", "ypos"),
+ use2 = "data",
+ facet_row = NULL,
+ facet_col = NULL,
+ ...
+)
a mousetrap data object created using one of the mt_import
functions (see mt_example for details). Alternatively, a trajectory
array can be provided directly (in this case use
will be ignored).
a character string specifying which trajectory data should be used.
a character vector specifying the trajectory variables used to create the heatmap. The first two entries are used as x and y-coordinates, the third, if provided, will be added as color information.
an optional character string specifying where the data that
contain the variables used for faceting can be found (in case these
arguments are specified). Defaults to "data" as data[["data"]]
usually contains all non mouse-tracking trial data.
an optional character string specifying a variable in
data[[use2]]
that should be used for (row-wise) faceting.
an optional character string specifying a variable in
data[[use2]]
that should be used for (column-wise) faceting.
arguments passed to mt_heatmap_raw.
mt_heatmap_ggplot(KH2017, xres=500, n_shades=5, mean_image=0.2)
+ mt_heatmap_ggplot(KH2017, xres=500, n_shades=5, mean_image=0.2)
#> spatializing trajectories
#> calculate image
#> smooth image
#> enhance image by 26.5
+#> Warning: Removed 1612 rows containing missing values (`geom_tile()`).
-
+
mt_heatmap_raw(
- data,
- use = "trajectories",
- dimensions = c("xpos", "ypos"),
- variable = NULL,
- bounds = NULL,
- xres = 1000,
- upsample = 1,
- norm = FALSE,
- colors = c("black", "blue", "white"),
- n_shades = c(1000, 1000),
- smooth_radius = 1.5,
- low_pass = 200,
- auto_enhance = TRUE,
- mean_image = 0.15,
- mean_color = 0.25,
- aggregate_lwd = 0,
- aggregate_col = "black",
- n_trajectories = NULL,
- seed = NULL,
- verbose = TRUE
-)
mt_heatmap_raw(
+ data,
+ use = "trajectories",
+ dimensions = c("xpos", "ypos"),
+ variable = NULL,
+ bounds = NULL,
+ xres = 1000,
+ upsample = 1,
+ norm = FALSE,
+ colors = c("black", "blue", "white"),
+ n_shades = c(1000, 1000),
+ smooth_radius = 1.5,
+ low_pass = 200,
+ auto_enhance = TRUE,
+ mean_image = 0.15,
+ mean_color = 0.25,
+ aggregate_lwd = 0,
+ aggregate_col = "black",
+ n_trajectories = NULL,
+ seed = NULL,
+ verbose = TRUE
+)
a mousetrap data object created using one of the mt_import
functions (see mt_example for details). Alternatively, a trajectory
array can be provided directly (in this case use
will be ignored).
a character string specifying which trajectory data should be used.
a character vector specifying the trajectory variables used to create the heatmap. The first two entries are used as x and y-coordinates, the third, if provided, will be added as color information.
boolean or numeric vector matching the number of trajectories
that if provided will be used as color information. variable
is only
considered when length(dimensions) < 3
.
numeric vector specifying the corners (xmin, ymin, xmax, ymax)
of the plot region. By default (bounds = NULL
), bounds are
determined based on the data input.
an integer specifying the number of pixels along the x-dimension.
An xres
of 1000 implies an 1000*N px, where N is determined so that
the trajectories aspect ratio is preserved (provided the bounds
are
unchanged).
a numeric value by which the number of points used to represent individual trajectories are increased or decreased. Values of smaller than one will improve speed but also introduce a certain level of granularity.
a logical specifying whether the data should be warped into
standard space. If norm = TRUE
, this overrules bounds
.
a character vector specifying two or three colors used to color the background, the foreground (trajectories), and the values of a third dimension (if specified).
an integer specifying the number of shades for the color
gradient between the first and second, and the second and third color in
colors
.
a numeric value specifying the standard deviation of the gaussian smoothing. If zero, smoothing is omitted.
an integer specifying the allowed number of counts per pixel. This arguments limits the maximum pixel color intensity.
boolean. If TRUE
(the default), the image is
adjusted so that the mean color intensity matches mean_image
and
mean_color
.
a numeric value between 0 and 1 specifying the average foreground color intensity across the entire image. Defaults to 0.1.
a numeric value between 0 and 1 specifying the average
third dimension's color intensity across the entire image. Defaults to 0.1.
Only relevant if a third dimension is specified in colors
.
an integer specifying the width of the aggregate
trajectory. If aggregate_lwd
is 0 (the default), the aggregate
trajectory is omitted.
a character value specifying the color of the aggregate trajectory.
an optional integer specifying the number of
trajectories used to create the image. By default, all trajectories are
used. If n_trajectories
is specified and smaller than the number of
trajectories in the trajectory array, then n_trajectories
are
randomly sampled.
an optional integer specifying the seed used for the trajectory sampling.
logical indicating whether function should report its progress.
An object of class mt_object_raw
containing in a matrix format
+
+
+
An object of class mt_object_raw
containing in a matrix format
the image's pixel information, the aggregate trajectory, and the colors.
mt_import_long(
- raw_data,
- xpos_label = "xpos",
- ypos_label = "ypos",
- zpos_label = NULL,
- timestamps_label = "timestamps",
- add_labels = NULL,
- mt_id_label = "mt_id",
- mt_seq_label = "mt_seq",
- reset_timestamps = TRUE,
- verbose = TRUE
-)
mt_import_long(
+ raw_data,
+ xpos_label = "xpos",
+ ypos_label = "ypos",
+ zpos_label = NULL,
+ timestamps_label = "timestamps",
+ add_labels = NULL,
+ mt_id_label = "mt_id",
+ mt_seq_label = "mt_seq",
+ reset_timestamps = TRUE,
+ verbose = TRUE
+)
a data.frame in long format, containing the raw data.
a character string specifying the column containing the x-positions.
a character string specifying the column containing the y-positions.
an optional character string specifying the column containing the z-positions.
a character string specifying the column containing the timestamps. If no timestamps are found in the data, a timestamps variable with increasing integers will be created (assuming equidistant time steps).
a character vector specifying columns containing additional mouse-tracking variables.
a character string (or vector) specifying the name of the column that provides a unique ID for every trial (the trial identifier). If @@ -118,22 +130,31 @@
a character string specifying the column that indicates
the order of the logged coordinates within a trial. If no column of the
specified name is found in the data.frame, the coordinates will be imported
in the order in which they were stored in raw_data
.
logical indicating if the first timestamp should be
subtracted from all timestamps within a trial. Default is TRUE
as it
is recommended for all following analyses in mousetrap.
logical indicating whether function should report its progress.
# Create data in long format for test purposes
-mt_data_long <- mt_export_long(mt_example,
- use2_variables=c("subject_nr","Condition"))
-
-# Import the data using mt_import_long
-mt_data <- mt_import_long(mt_data_long)
-
-
-if (FALSE) {
-# Import a hypothetical dataset that contains the
-# custom mouse-tracking variables angle and velocity
-mt_data <- mt_import_long(exp_data,
- add_labels= c("angle", "velocity"))
-}
-
+ # Create data in long format for test purposes
+mt_data_long <- mt_export_long(mt_example,
+ use2_variables=c("subject_nr","Condition"))
+
+# Import the data using mt_import_long
+mt_data <- mt_import_long(mt_data_long)
+
+
+if (FALSE) {
+# Import a hypothetical dataset that contains the
+# custom mouse-tracking variables angle and velocity
+mt_data <- mt_import_long(exp_data,
+ add_labels= c("angle", "velocity"))
+}
+
mt_import_mousetrap(
- raw_data,
- xpos_label = "xpos",
- ypos_label = "ypos",
- timestamps_label = "timestamps",
- mt_id_label = NULL,
- split = ",",
- duplicates = "remove_first",
- unordered = "warn",
- reset_timestamps = TRUE,
- digits = NULL,
- verbose = FALSE
-)
mt_import_mousetrap(
+ raw_data,
+ xpos_label = "xpos",
+ ypos_label = "ypos",
+ timestamps_label = "timestamps",
+ mt_id_label = NULL,
+ split = ",",
+ duplicates = "remove_first",
+ unordered = "warn",
+ reset_timestamps = TRUE,
+ digits = NULL,
+ verbose = FALSE
+)
a data.frame containing the raw data.
a character string specifying the name of the column(s) in which the x-positions are stored (see Details).
a character string specifying the name of the column(s) in which the y-positions are stored (see Details).
a character string specifying the name of the column(s) in which the timestamps are stored (see Details).
an optional character string (or vector) specifying the name of the column that provides a unique ID for every trial (the trial @@ -113,32 +121,49 @@
a character string indicating how the different timestamps and coordinates within a trial are separated.
a character string indicating how duplicate timestamps within a trial are handled (see Details).
a character string indicating how unordered (i.e., non-monotonically increasing) timestamps within a trial are handled (see Details).
logical indicating if the first timestamp should be
subtracted from all timestamps within a trial. Default is TRUE
as it
is recommended for all following analyses in mousetrap.
an optional integer. If specified, timestamps will be rounded. Potentially useful if timestamps are recorded with submillisecond precision.
logical indicating whether function should report its progress.
A mousetrap data object (see mt_example). -If mouse-tracking data were recorded using the mousetrap plug-ins for + + +
A mousetrap data object (see mt_example).
+ + +If mouse-tracking data were recorded using the mousetrap plug-ins for OpenSesame, the unit of the timestamps is milliseconds.
Kieslich, P. J., & Henninger, F. (2017). Mousetrap: An integrated, open-source mouse-tracking package. Behavior Research -Methods, 49(5), 1652-1667. doi: 10.3758/s13428-017-0900-z
+Methods, 49(5), 1652-1667. doi:10.3758/s13428-017-0900-zmt_data <- mt_import_mousetrap(mt_example_raw)
-
+ mt_data <- mt_import_mousetrap(mt_example_raw)
+
mt_import_wide(
- raw_data,
- xpos_label = "X",
- ypos_label = "Y",
- zpos_label = NULL,
- timestamps_label = "T",
- add_labels = NULL,
- mt_id_label = NULL,
- pos_sep = "_",
- pos_ids = NULL,
- reset_timestamps = TRUE,
- verbose = TRUE
-)
mt_import_wide(
+ raw_data,
+ xpos_label = "X",
+ ypos_label = "Y",
+ zpos_label = NULL,
+ timestamps_label = "T",
+ add_labels = NULL,
+ mt_id_label = NULL,
+ pos_sep = "_",
+ pos_ids = NULL,
+ reset_timestamps = TRUE,
+ verbose = TRUE
+)
a data.frame containing the raw data.
a character string specifying the core of the column labels containing the x-positions (e.g., "X" for "X_1", "X_2", ...).
a character string specifying the core of the column labels containing the y-positions (e.g., "Y" for "Y_1", "Y_2", ...).
a character string specifying the core of the column labels containing the z-positions.
an optional character string specifying the core of the column labels containing the timestamps. If no timestamps are found in the data, a timestamps variable with increasing integers will be created (assuming equidistant time steps).
a character vector specifying the core of columns containing additional mouse-tracking variables.
an optional character string (or vector) specifying the name of the column that provides a unique ID for every trial (the trial @@ -123,25 +135,36 @@
a character string indicating the character that connects the core label and the position, (e.g., "_" for "X_1", "Y_1", ...).
the vector of IDs used for indexing the x-coordinates, y-coordinates etc. (e.g., 1:101 for time-normalized trajectories from MouseTracker). If unspecified (the default), column labels for the respective variable will be extracted using grep (see Details).
logical indicating if the first timestamp should be
subtracted from all timestamps within a trial. Default is TRUE
as it
is recommended for all following analyses in mousetrap.
logical indicating whether function should report its progress.
# Create data in wide format for test purposes
-mt_data_wide <- mt_export_wide(mt_example,
- use2_variables=c("subject_nr", "Condition"))
-
-# Import the data using mt_import_wide
-mt_data <- mt_import_wide(mt_data_wide,
- xpos_label="xpos", ypos_label="ypos",
- timestamps_label="timestamps")
+ # Create data in wide format for test purposes
+mt_data_wide <- mt_export_wide(mt_example,
+ use2_variables=c("subject_nr", "Condition"))
+
+# Import the data using mt_import_wide
+mt_data <- mt_import_wide(mt_data_wide,
+ xpos_label="xpos", ypos_label="ypos",
+ timestamps_label="timestamps")
#> No mt_id_label provided. A new trial identifying variable called mt_id was created.
#> No pos_ids provided. The following variables were found using grep:
#> 465 variables found for timestamps.
#> 465 variables found for xpos.
#> 465 variables found for ypos.
-
+
mt_length_normalize(
- data,
- use = "trajectories",
- dimensions = c("xpos", "ypos"),
- save_as = "ln_trajectories",
- n_points = 20
-)
mt_length_normalize(
+ data,
+ use = "trajectories",
+ dimensions = c("xpos", "ypos"),
+ save_as = "ln_trajectories",
+ n_points = 20
+)
a mousetrap data object created using one of the mt_import
functions (see mt_example for details). Alternatively, a trajectory
array can be provided directly (in this case use
will be ignored).
a character string specifying which trajectory data should be used.
a character string specifying which trajectory variables should be used. Can be of length 2 or 3 for two-dimensional or three-dimensional data.
a character string specifying where the resulting trajectory data should be stored.
an integer or vector of integers specifying the number of points used to represent the spatially rescaled trajectories. If a single integer is provided, the number of points will be constant across trajectories. Alternatively, a vector of integers can provided that specify the number of points for each trajectory individually.
A mousetrap data object (see mt_example) with an additional + + +
A mousetrap data object (see mt_example) with an additional
array (by default called ln_trajectories
) containing the length
normalized trajectories. If a trajectory array was provided directly as
data
, only the length normalized trajectories will be returned.
mt_map(
- data,
- use = "ln_trajectories",
- save_as = "prototyping",
- dimensions = c("xpos", "ypos"),
- prototypes = mousetrap::mt_prototypes,
- weights = rep(1, length(dimensions)),
- pointwise = TRUE,
- na_rm = FALSE,
- minkowski_p = 2,
- use2 = "data",
- grouping_variables = NULL
-)
mt_map(
+ data,
+ use = "ln_trajectories",
+ save_as = "prototyping",
+ dimensions = c("xpos", "ypos"),
+ prototypes = mousetrap::mt_prototypes,
+ weights = rep(1, length(dimensions)),
+ pointwise = TRUE,
+ na_rm = FALSE,
+ minkowski_p = 2,
+ use2 = "data",
+ grouping_variables = NULL
+)
a mousetrap data object created using one of the mt_import
functions (see mt_example for details). Alternatively, a trajectory
array can be provided directly (in this case use
will be ignored).
a character string specifying which trajectory data should be used.
a character string specifying where the resulting data should be stored.
a character vector specifying which trajectory variables should be used. Can be of length 2 or 3 for two-dimensional or three-dimensional trajectories respectively.
a trajectory array containing the prototypes the trajectories are mapped to. As a starting point, the trajectories stored in mt_prototypes can be used. See Details and Examples for selecting prototypes and creating new ones.
numeric vector specifying the relative importance of the
variables specified in dimensions
. Defaults to a vector of 1s
implying equal importance. Technically, each variable is rescaled so that
the standard deviation matches the corresponding value in weights
.
To use the original variables, set weights = NULL
.
boolean specifying the way dissimilarity between the
trajectories is measured (see Details). If TRUE
(the default),
mt_distmat
measures the average dissimilarity and then sums the
results. If FALSE
, mt_distmat
measures dissimilarity once
(by treating the various points as independent dimensions).
logical specifying whether trajectory points containing NAs should be removed. Removal is done column-wise. That is, if any trajectory has a missing value at, e.g., the 10th recorded position, the 10th position is removed for all trajectories. This is necessary to compute distance between trajectories.
an integer specifying the distance metric.
minkowski_p = 1
computes the city-block distance, minkowski_p
= 2
(the default) computes the Euclidian distance, minkowski_p = 3
the cubic distance, etc.
an optional character string specifying where the data that
contain the variables used for grouping can be found (in case
grouping_variables
are specified). Defaults to "data" as
data[["data"]]
usually contains all non mouse-tracking trial data.
a character string (or vector) specifying one or
more variables in use2
. If specified, prototypes will be rescaled
separately to match the coordinate system of the trajectories for each
level of the variable(s). If unspecified (the default), the prototypes are
rescaled in the same way across all trajectories.
A mousetrap data object (see mt_example) with an additional + + +
A mousetrap data object (see mt_example) with an additional
data.frame (by default called prototyping
) that contains the
best fitting prototype for each trajectory (the number of the prototype is
specified under prototype
, the label of the prototype under
@@ -161,7 +184,7 @@
Wulff, D. U., Kieslich, P. J., Henninger, F., Haslbeck, J. M. B., & -Schulte-Mecklenbeck, M. (2021). Movement tracking of cognitive +Schulte-Mecklenbeck, M. (2023). Movement tracking of psychological processes: A tutorial using mousetrap. PsyArXiv. -doi: 10.31234/osf.io/v685r
+doi:10.31234/osf.io/v685rWulff, D. U., Haslbeck, J. M. B., & Schulte-Mecklenbeck, M. (2022). Measuring the (dis-)continuous mind: What movement trajectories reveal about cognition. Manuscript in preparation.
@@ -187,48 +210,48 @@# Length normalize trajectories
-KH2017 <- mt_length_normalize(KH2017)
-
-# Map trajectories onto standard prototype set
-KH2017 <- mt_map(KH2017,
- use="ln_trajectories")
-
-
-# Plot prototypes
-mt_plot(mt_prototypes,facet_col="mt_id") +
- ggplot2::facet_grid(.~factor(mt_id,levels=unique(mt_id)))
+ # Length normalize trajectories
+KH2017 <- mt_length_normalize(KH2017)
+
+# Map trajectories onto standard prototype set
+KH2017 <- mt_map(KH2017,
+ use="ln_trajectories")
+
+
+# Plot prototypes
+mt_plot(mt_prototypes,facet_col="mt_id") +
+ ggplot2::facet_grid(.~factor(mt_id,levels=unique(mt_id)))
-
-# Plot trajectories per assigned prototype
-mt_plot(KH2017,use="ln_trajectories",
- use2="prototyping",facet_col="prototype_label")
+
+# Plot trajectories per assigned prototype
+mt_plot(KH2017,use="ln_trajectories",
+ use2="prototyping",facet_col="prototype_label")
-
-
-# Map trajectories onto reduced prototype set
-KH2017 <- mt_map(KH2017,
- use="ln_trajectories",
- prototypes=mt_prototypes[c("straight","curved","cCoM"),,],
- save_as="prototyping_red")
-
-
-# Map trajectories onto extended prototype set
-
-# Add additional prototypes
-mt_prototypes_ext <- mt_add_trajectory(mt_prototypes,
- xpos = c(0,1,-1,1,-1), ypos = c(0,1.5,1.5,1.5,1.5), id = "dCoM3"
-)
-mt_prototypes_ext <- mt_add_trajectory(mt_prototypes_ext,
- xpos = c(0,0,-1), ypos = c(0,1.5,1.5), id = "neutral"
-)
-
-# Map trajectories
-KH2017 <- mt_map(KH2017,
- use="ln_trajectories", prototypes=mt_prototypes_ext,
- save_as="prototyping_ext")
-
-
+
+
+# Map trajectories onto reduced prototype set
+KH2017 <- mt_map(KH2017,
+ use="ln_trajectories",
+ prototypes=mt_prototypes[c("straight","curved","cCoM"),,],
+ save_as="prototyping_red")
+
+
+# Map trajectories onto extended prototype set
+
+# Add additional prototypes
+mt_prototypes_ext <- mt_add_trajectory(mt_prototypes,
+ xpos = c(0,1,-1,1,-1), ypos = c(0,1.5,1.5,1.5,1.5), id = "dCoM3"
+)
+mt_prototypes_ext <- mt_add_trajectory(mt_prototypes_ext,
+ xpos = c(0,0,-1), ypos = c(0,1.5,1.5), id = "neutral"
+)
+
+# Map trajectories
+KH2017 <- mt_map(KH2017,
+ use="ln_trajectories", prototypes=mt_prototypes_ext,
+ save_as="prototyping_ext")
+
+
mt_measures(
- data,
- use = "trajectories",
- save_as = "measures",
- dimensions = c("xpos", "ypos"),
- timestamps = "timestamps",
- flip_threshold = 0,
- hover_threshold = NULL,
- hover_incl_initial = TRUE,
- initiation_threshold = 0,
- verbose = FALSE
-)
mt_measures(
+ data,
+ use = "trajectories",
+ save_as = "measures",
+ dimensions = c("xpos", "ypos"),
+ timestamps = "timestamps",
+ flip_threshold = 0,
+ hover_threshold = NULL,
+ hover_incl_initial = TRUE,
+ initiation_threshold = 0,
+ verbose = FALSE
+)
a mousetrap data object created using one of the mt_import
functions (see mt_example for details). Alternatively, a trajectory
array can be provided directly (in this case use
will be ignored).
a character string specifying which trajectory data should be used.
a character string specifying where the calculated measures should be stored.
a character vector specifying the two dimensions in the
trajectory array that contain the mouse positions. Usually (and by
default), the first value in the vector corresponds to the x-positions
(xpos
) and the second to the y-positions (ypos
).
a character string specifying the trajectory dimension containing the timestamps.
a numeric value specifying the distance that needs to be exceeded in one direction so that a change in direction counts as a flip. If several thresholds are specified, flips will be returned in separate variables for each threshold value (the variable name will be suffixed with the threshold value).
an optional numeric value. If specified, hovers
(and hover_time
) will be calculated as the number (and total time)
@@ -116,109 +128,151 @@
logical indicating if the calculation of hovers should include a potential initial phase in the trial without mouse movements (this initial phase is included by default).
a numeric value specifying the distance from the start point of the trajectory that needs to be exceeded for calculating the initiation time. By default, it is 0, meaning that any movement counts as movement initiation.
logical indicating whether function should report its progress.
A mousetrap data object (see mt_example) where an additional + + +
A mousetrap data object (see mt_example) where an additional
data.frame has been added (by default called "measures") containing
the per-trial mouse-tracking measures. Each row in the data.frame
corresponds to one trajectory (the corresponding trajectory is identified
via the rownames and, additionally, in the column "mt_id"). Each column in
the data.frame corresponds to one of the measures. If a trajectory array
was provided directly as data
, only the measures data.frame will be
-returned.
-The following measures are computed for each trajectory (the labels
+returned.
The following measures are computed for each trajectory (the labels
relating to x- and y-positions will be adapted depending on the values
specified in dimensions
). Please note that additional information is
provided in the Details section.
Trial ID (can be used for merging measures data.frame with other trial-level data)
Maximum x-position
Minimum x-position
Maximum y-position
Minimum y-position
Signed Maximum absolute deviation from the direct path
connecting start and end point of the trajectory (straight line).
If the MAD
occurs above the direct path, this is denoted by
a positive value; if it occurs below, by a negative value.
Time at which the maximum absolute deviation was reached first
Maximum deviation above the direct path
Time at which the maximum deviation above was reached first
Maximum deviation below the direct path
Time at which the maximum deviation below was reached first
Average deviation from direct path
Area under curve, the geometric area between the actual trajectory and the direct path where areas below the direct path have been subtracted
Number of directional changes along x-axis (exceeding the
distance specified in flip_threshold
)
Number of directional changes along y-axis (exceeding the
distance specified in flip_threshold
)
Number of crossings of the y-axis
Number of crossings of the x-axis
Response time, time at which tracking stopped
Time at which first mouse movement was initiated
Total time without mouse movement across the entirety of the trial
Total time of all periods without movement in a trial
(whose duration exceeds the value specified in hover_threshold
)
Number of periods without movement in a trial (whose duration
exceeds the value specified in hover_threshold
)
Total distance covered by the trajectory
Maximum velocity
Time at which maximum velocity occurred first
Minimum velocity
Time at which minimum velocity occurred first
Maximum acceleration
Time at which maximum acceleration occurred first
Minimum acceleration
Time at which minimum acceleration occurred first
mt_example <- mt_derivatives(mt_example)
-mt_example <- mt_deviations(mt_example)
-mt_example <- mt_measures(mt_example)
-
-# Merge measures with trial data
-mt_example_results <- dplyr::inner_join(
- mt_example$data, mt_example$measures,
- by="mt_id")
-
+ mt_example <- mt_derivatives(mt_example)
+mt_example <- mt_deviations(mt_example)
+mt_example <- mt_measures(mt_example)
+
+# Merge measures with trial data
+mt_example_results <- dplyr::inner_join(
+ mt_example$data, mt_example$measures,
+ by="mt_id")
+
mt_plot(
- data,
- use = "trajectories",
- use2 = "data",
- x = "xpos",
- y = "ypos",
- color = NULL,
- linetype = NULL,
- alpha = NA,
- size = 0.5,
- facet_row = NULL,
- facet_col = NULL,
- wrap_var = NULL,
- wrap_ncol = NULL,
- points = FALSE,
- return_type = "plot",
- mt_id = "mt_id",
- only_ggplot = NULL,
- ...
-)
-
-mt_plot_aggregate(
- data,
- use = "trajectories",
- use2 = "data",
- x = "xpos",
- y = "ypos",
- color = NULL,
- linetype = NULL,
- alpha = NA,
- size = 0.5,
- facet_row = NULL,
- facet_col = NULL,
- wrap_var = NULL,
- wrap_ncol = NULL,
- points = FALSE,
- return_type = "plot",
- subject_id = NULL,
- only_ggplot = NULL,
- ...
-)
mt_plot(
+ data,
+ use = "trajectories",
+ use2 = "data",
+ x = "xpos",
+ y = "ypos",
+ color = NULL,
+ linetype = NULL,
+ alpha = NA,
+ size = 0.5,
+ facet_row = NULL,
+ facet_col = NULL,
+ wrap_var = NULL,
+ wrap_ncol = NULL,
+ points = FALSE,
+ return_type = "plot",
+ mt_id = "mt_id",
+ only_ggplot = NULL,
+ ...
+)
+
+mt_plot_aggregate(
+ data,
+ use = "trajectories",
+ use2 = "data",
+ x = "xpos",
+ y = "ypos",
+ color = NULL,
+ linetype = NULL,
+ alpha = NA,
+ size = 0.5,
+ facet_row = NULL,
+ facet_col = NULL,
+ wrap_var = NULL,
+ wrap_ncol = NULL,
+ points = FALSE,
+ return_type = "plot",
+ subject_id = NULL,
+ only_ggplot = NULL,
+ ...
+)
a mousetrap data object created using one of the mt_import
functions (see mt_example for details). Alternatively, a trajectory
array can be provided directly (in this case use
will be ignored).
a character string specifying which trajectories should be plotted. The corresponding trajectories are selected from data using @@ -122,45 +124,71 @@
a character string specifying where the data that contain the
variables used for determining the color
and linetype
can be
found (in case these arguments are specified). Defaults to "data" as
data[["data"]]
usually contains all non mouse-tracking trial data.
a character string specifying which dimension in the trajectory array should be displayed on the x-axis (defaults to xpos).
a character string specifying which dimension in the trajectory array should be displayed on the y-axis (defaults to ypos).
an optional character string specifying which variable in
data[[use2]]
should be used for coloring the trajectories.
an optional character string specifying which variable in
data[[use2]]
should be used for varying the linetype of the
trajectories.
an optional numeric value between 0 and 1 that can be used to make the plotted lines (and points) semitransparent.
an optional numeric value that can be used to vary the width of the plotted trajectory lines.
an optional character string specifying a variable in
data[[use2]]
that should be used for (row-wise) faceting.
an optional character string specifying a variable in
data[[use2]]
that should be used for (column-wise) faceting.
an optional character string specifying variable(s) in
data[[use2]]
that should be used for wrapping.
an optional integer specifying the number of columns if wrapping is used.
logical. If TRUE
, points will be added to the plot using
geom_point.
a character string specifying which type of object should
be returned. If "plot"
(the default), a new ggplot is created and
@@ -168,21 +196,30 @@
"mapping"
, only the ggplot object containing the mapping but without
any geoms is returned. If "geoms"
, only the geoms are returned,
which allows adding the plotted trajectories to an existing ggplot.a character string specifying the internal label used for the
trial identifier (passed on to the group aesthetic). Only relevant for
mt_plot
.
Deprecated. Please use return_type
instead.
additional arguments passed on to mt_reshape (such as
subset
).
a character string specifying which column contains the
subject identifier. Only relevant for mt_plot_aggregate
. If
specified, aggregation will be performed within subjects first. Note that
aggregation will be performed separately for each level, including all
subjects for whom data are available.
mt_plot
: Plot individual trajectory data
mt_plot_aggregate
: Plot aggregated trajectory data
mt_plot()
: Plot individual trajectory data
mt_plot_aggregate()
: Plot aggregated trajectory data
## Plot individual example trajectories
-
-# Time-normalize trajectories
-mt_example <- mt_time_normalize(mt_example)
-
-# Plot all time-normalized trajectories
-# varying the color depending on the condition
-mt_plot(mt_example, use="tn_trajectories",
- color="Condition")
+ ## Plot individual example trajectories
+
+# Time-normalize trajectories
+mt_example <- mt_time_normalize(mt_example)
+
+# Plot all time-normalized trajectories
+# varying the color depending on the condition
+mt_plot(mt_example, use="tn_trajectories",
+ color="Condition")
-
-# ... setting alpha < 1 for semi-transparency
-mt_plot(mt_example, use="tn_trajectories",
- color="Condition", alpha=.2)
+
+# ... setting alpha < 1 for semi-transparency
+mt_plot(mt_example, use="tn_trajectories",
+ color="Condition", alpha=.2)
-
-# ... with custom colors
-mt_plot(mt_example, use="tn_trajectories",
- color="Condition") +
- ggplot2::scale_color_brewer(type="qual")
+
+# ... with custom colors
+mt_plot(mt_example, use="tn_trajectories",
+ color="Condition") +
+ ggplot2::scale_color_brewer(type="qual")
-
-# Create separate plots per Condition
-mt_plot(mt_example, use="tn_trajectories",
- facet_col="Condition")
+
+# Create separate plots per Condition
+mt_plot(mt_example, use="tn_trajectories",
+ facet_col="Condition")
-
-# Create customized plot by setting the return_type option to "mapping"
-# to setup an empty plot. In a next step, a geom is added.
-# In this example, only points are plotted.
-mt_plot(mt_example, use="tn_trajectories",
- color="Condition", return_type="mapping") +
- ggplot2::geom_point()
+
+# Create customized plot by setting the return_type option to "mapping"
+# to setup an empty plot. In a next step, a geom is added.
+# In this example, only points are plotted.
+mt_plot(mt_example, use="tn_trajectories",
+ color="Condition", return_type="mapping") +
+ ggplot2::geom_point()
-
-# Plot velocity profiles based on the averaged trajectories
-# varying the color depending on the condition
-mt_example <- mt_derivatives(mt_example)
-mt_example <- mt_average(mt_example, interval_size=100)
-mt_plot(mt_example, use="av_trajectories",
- x="timestamps", y="vel", color="Condition")
+
+# Plot velocity profiles based on the averaged trajectories
+# varying the color depending on the condition
+mt_example <- mt_derivatives(mt_example)
+mt_example <- mt_average(mt_example, interval_size=100)
+mt_plot(mt_example, use="av_trajectories",
+ x="timestamps", y="vel", color="Condition")
-
-
-## Plot aggregate trajectories for KH2017 data
-
-# Time-normalize trajectories
-KH2017 <- mt_time_normalize(KH2017)
-
-# Plot aggregated time-normalized trajectories per condition
-mt_plot_aggregate(KH2017, use="tn_trajectories",
- color="Condition")
+
+
+## Plot aggregate trajectories for KH2017 data
+
+# Time-normalize trajectories
+KH2017 <- mt_time_normalize(KH2017)
+
+# Plot aggregated time-normalized trajectories per condition
+mt_plot_aggregate(KH2017, use="tn_trajectories",
+ color="Condition")
-
-# ... first aggregating trajectories within subjects
-mt_plot_aggregate(KH2017, use="tn_trajectories",
- color="Condition", subject_id="subject_nr")
+
+# ... first aggregating trajectories within subjects
+mt_plot_aggregate(KH2017, use="tn_trajectories",
+ color="Condition", subject_id="subject_nr")
-
-# ... adding points for each position to the plot
-mt_plot_aggregate(KH2017, use="tn_trajectories",
- color="Condition", points=TRUE)
+
+# ... adding points for each position to the plot
+mt_plot_aggregate(KH2017, use="tn_trajectories",
+ color="Condition", points=TRUE)
-
-if (FALSE) {
-
-# Create combined plot of individual and aggregate trajectories
-# by first plotting the individual trajectories using mt_plot.
-# In a next step, the aggregate trajectories are added using the
-# mt_plot_aggregate function with the return_type argument set to "geom".
-mt_plot(KH2017, use="tn_trajectories", color="Condition", alpha=.05) +
- mt_plot_aggregate(KH2017, use="tn_trajectories",
- color="Condition", return_type="geom", size=2)
-}
-
+
+if (FALSE) {
+
+# Create combined plot of individual and aggregate trajectories
+# by first plotting the individual trajectories using mt_plot.
+# In a next step, the aggregate trajectories are added using the
+# mt_plot_aggregate function with the return_type argument set to "geom".
+mt_plot(KH2017, use="tn_trajectories", color="Condition", alpha=.05) +
+ mt_plot_aggregate(KH2017, use="tn_trajectories",
+ color="Condition", return_type="geom", size=2)
+}
+
mt_plot_add_rect(rect, color = "black", fill = NA, ...)
mt_plot_add_rect(rect, color = "black", fill = NA, ...)
x
), y-position (y
), width (w
), and
height (h
) needs to be provided. If columns are not labeled, the
order x, y, w, h
is assumed.
+
+
argument passed on to geom_rect. Specifies the color of the border of the rectangles.
argument passed on to geom_rect. Specifies the
color of the interior of the rectangles. If NA
(the default),
rectangles are unfilled.
additional arguments passed on to geom_rect.
# Load ggplot2
-library(ggplot2)
-
-# Import, flip, and time-normalize raw trajectories
-mt_example <- mt_import_mousetrap(mt_example_raw)
-mt_example <- mt_remap_symmetric(mt_example,remap_xpos="no")
-mt_example <- mt_time_normalize(mt_example)
-
-# Create rectangles matrix
-rectangles <- matrix(
- # (The matrix is n x 4, and contains
- # all relevant data for every button,
- # (i.e. x, y, width and height values)
- # in separate rows)
- c(
- -840, 525, 350, -170,
- 840, 525, -350, -170
- ),
- ncol=4, byrow=TRUE)
-
-# Plot all time-normalized trajectories
-# varying the color depending on the condition
-# and add rectangles
-mt_plot(mt_example,
- use="trajectories",
- x="xpos", y="ypos", color="Condition"
-) + mt_plot_add_rect(rect=rectangles)
+ # Load ggplot2
+library(ggplot2)
+
+# Import, flip, and time-normalize raw trajectories
+mt_example <- mt_import_mousetrap(mt_example_raw)
+mt_example <- mt_remap_symmetric(mt_example,remap_xpos="no")
+mt_example <- mt_time_normalize(mt_example)
+
+# Create rectangles matrix
+rectangles <- matrix(
+ # (The matrix is n x 4, and contains
+ # all relevant data for every button,
+ # (i.e. x, y, width and height values)
+ # in separate rows)
+ c(
+ -840, 525, 350, -170,
+ 840, 525, -350, -170
+ ),
+ ncol=4, byrow=TRUE)
+
+# Plot all time-normalized trajectories
+# varying the color depending on the condition
+# and add rectangles
+mt_plot(mt_example,
+ use="trajectories",
+ x="xpos", y="ypos", color="Condition"
+) + mt_plot_add_rect(rect=rectangles)
-
-
+
+
mt_plot_per_trajectory(
- file,
- data,
- use = "trajectories",
- x = "xpos",
- y = "ypos",
- xlim = NULL,
- ylim = NULL,
- axes_exact = FALSE,
- points = FALSE,
- rect = NULL,
- color = "black",
- fill = NA,
- verbose = FALSE,
- ...
-)
mt_plot_per_trajectory(
+ file,
+ data,
+ use = "trajectories",
+ x = "xpos",
+ y = "ypos",
+ xlim = NULL,
+ ylim = NULL,
+ axes_exact = FALSE,
+ points = FALSE,
+ rect = NULL,
+ color = "black",
+ fill = NA,
+ verbose = FALSE,
+ ...
+)
a character string specifying the name of the PDF file. Passed on to pdf.
a mousetrap data object created using one of the mt_import
functions (see mt_example for details). Alternatively, a trajectory
array can be provided directly (in this case use
will be ignored).
a character string specifying which trajectories should be plotted. The corresponding trajectories are selected from data using @@ -100,42 +104,65 @@
a character string specifying which dimension in the trajectory array should be displayed on the x-axis (defaults to xpos).
a character string specifying which dimension in the trajectory array should be displayed on the y-axis (defaults to ypos).
optional argument specifying the limits for the x axis (passed on to coord_cartesian). If not specified (the default), sensible axis limits will be computed.
optional argument specifying the limits for the y axis (passed on to coord_cartesian). If not specified (the default), sensible axis limits will be computed.
logical. If TRUE
, axes will be set without offset
exactly at the limits of the x and y axes (which can be specified using
xlim
and ylim
]).
logical. If TRUE
, points will be added to the plot using
geom_point.
optional argument passed on to mt_plot_add_rect. If specified, rectangles (usually representing the response buttons) will be plotted for each trajectory plot.
optional argument passed on to mt_plot_add_rect. Only
relevant if rect
is specified.
optional argument passed on to mt_plot_add_rect. Only
relevant if rect
is specified.
logical indicating whether function should report its progress.
additional arguments passed on to pdf.
if (FALSE) {
-mt_plot_per_trajectory(mt_example,
- file="trajectories.pdf",
- use="trajectories")
-}
-
+ if (FALSE) {
+mt_plot_per_trajectory(mt_example,
+ file="trajectories.pdf",
+ use="trajectories")
+}
+
mt_plot_riverbed(
- data,
- use = "tn_trajectories",
- y = "xpos",
- y_range = NULL,
- y_bins = 250,
- facet_row = NULL,
- facet_col = NULL,
- facet_data = "data",
- grid_colors = c("gray30", "gray10"),
- na.rm = FALSE
-)
mt_plot_riverbed(
+ data,
+ use = "tn_trajectories",
+ y = "xpos",
+ y_range = NULL,
+ y_bins = 250,
+ facet_row = NULL,
+ facet_col = NULL,
+ facet_data = "data",
+ grid_colors = c("gray30", "gray10"),
+ na.rm = FALSE
+)
mousetrap data object containing the data to be plotted.
character string specifying the set of trajectories to use in the plot. The steps of this set will constitute the x axis. Defaults to 'tn_trajectories', which results in time steps being plotted on the x axis.
variable in the mousetrap data object to be plotted on the output's y dimension. Defaults to 'xpos', the cursor's x coordinate.
numerical vector containing two values that represent the upper and lower ends of the y axis. By default, the range is calculated from the data provided.
number of bins to distribute along the y axis (defaults to 250).
an optional character string specifying a variable in
data[[facet_data]]
that should be used for (row-wise) faceting. If
specified, separate riverbed plots for each level of the variable will be
created.
an optional character string specifying a variable in
data[[facet_data]]
that should be used for (column-wise) faceting.
If specified, separate riverbed plots for each level of the variable will
be created.
a character string specifying where the (optional) data containing the faceting variables can be found.
a character string or vector of length 2 specifying the
grid color(s). If a single value is provided, this will be used as the grid
color. If a vector of length 2 is provided, the first value will be used as
the color for the major grid lines, the second value for the minor grid
lines. If set to NA
, no grid lines are plotted.
logical specifying whether missing values should be removed. This is not done by default, because generally riverbed plots are generated from preprocess trajectories (e.g., time-normalized trajectories) that all have the same length (i.e., the same number of steps).
# Time-normalize trajectories
-KH2017 <- mt_time_normalize(KH2017)
-
-# Create riverbed plot for all trials
-mt_plot_riverbed(KH2017)
+ # Time-normalize trajectories
+KH2017 <- mt_time_normalize(KH2017)
+
+# Create riverbed plot for all trials
+mt_plot_riverbed(KH2017)
-
-if (FALSE) {
-# Create separate plots for typical and atypical trials
-mt_plot_riverbed(mt_example, facet_col="Condition")
-
-
-# Create riverbed plot for all trials with custom x and y axis labels
-mt_plot_riverbed(mt_example) +
- ggplot2::xlab("Time step") + ggplot2::ylab("X coordinate")
-
-# Note that it is also possible to replace the
-# default scale for fill with a custom scale
-mt_plot_riverbed(mt_example, facet_col="Condition") +
- ggplot2::scale_fill_gradientn(colours=grDevices::heat.colors(9),
- name="Frequency", trans="log", labels=scales::percent)
-}
-
+
+if (FALSE) {
+# Create separate plots for typical and atypical trials
+mt_plot_riverbed(mt_example, facet_col="Condition")
+
+
+# Create riverbed plot for all trials with custom x and y axis labels
+mt_plot_riverbed(mt_example) +
+ ggplot2::xlab("Time step") + ggplot2::ylab("X coordinate")
+
+# Note that it is also possible to replace the
+# default scale for fill with a custom scale
+mt_plot_riverbed(mt_example, facet_col="Condition") +
+ ggplot2::scale_fill_gradientn(colours=grDevices::heat.colors(9),
+ name="Frequency", trans="log", labels=scales::percent)
+}
+
mt_prototypes
mt_prototypes
Mouse- and hand-trajectories often occur in types. In such cases, movement
trajectory data should be analyzed in terms of discrete type assignments
-(Wulff et al., 2021). To this end mt_map can be used to map mouse- or
+(Wulff et al., 2023). To this end mt_map can be used to map mouse- or
hand-trajectory to the closest of several predefined prototypes.
mt_prototypes
provides a core set of prototypes that has been shown to
represent well a large fraction of empirical movement trajectories (Wulff et
@@ -84,9 +84,9 @@
Wulff, D. U., Kieslich, P. J., Henninger, F., Haslbeck, J. M. -B., & Schulte-Mecklenbeck, M. (2021). Movement tracking of cognitive +B., & Schulte-Mecklenbeck, M. (2023). Movement tracking of psychological processes: A tutorial using mousetrap. PsyArXiv. -doi: 10.31234/osf.io/v685r
+doi:10.31234/osf.io/v685rWulff, D. U., Haslbeck, J. M. B., Schulte-Mecklenbeck, M. (2022). Measuring the (dis-)continuous mind: What movement trajectories reveal about cognition. Manuscript in preparation.
@@ -104,7 +104,7 @@mt_qeffect(
- data,
- compare,
- use = "measures",
- measure = "MAD",
- direction = "upward",
- n_steps = 100,
- return_data = FALSE,
- ...
-)
mt_qeffect(
+ data,
+ compare,
+ use = "measures",
+ measure = "MAD",
+ direction = "upward",
+ n_steps = 100,
+ return_data = FALSE,
+ ...
+)
a mousetrap data object created using one of the mt_import
functions (see mt_example for details). Alternatively, a trajectory
array can be provided directly (in this case use
will be ignored).
either a vector, the label of a variable in , or a mousetrap object.
a character string specifying which trajectory data should be used.
a character value specifying the variable used to calculate the effect between
a character value.
an integer.
boolean.
additional arguments passed on to points.
Nothing, when image is plotted using an external device. Otherwise an + + +
Nothing, when image is plotted using an external device. Otherwise an
object of class mt_object_raw
containing in a matrix format the
image's pixel information.
# Plot regular heatmap
-#SpiveyEtAl2005 = mt_import_long(SpiveyEtAl2005_raw,'x','y',NULL,'t',
-#mt_id_label = c('ptp','trial'))
-#heatmap = mt_heatmap_raw(SpiveyEtAl2005,xres = 2000)
-#mt_heatmap(heatmap,file = NULL)
-
-# compute measures
-#SpiveyEtAl2005 = mt_measures(SpiveyEtAl2005)
-
-# Plot heatmap using velocity
-#mt_heatmap(SpiveyEtAl2005)
-
+ # Plot regular heatmap
+#SpiveyEtAl2005 = mt_import_long(SpiveyEtAl2005_raw,'x','y',NULL,'t',
+#mt_id_label = c('ptp','trial'))
+#heatmap = mt_heatmap_raw(SpiveyEtAl2005,xres = 2000)
+#mt_heatmap(heatmap,file = NULL)
+
+# compute measures
+#SpiveyEtAl2005 = mt_measures(SpiveyEtAl2005)
+
+# Plot heatmap using velocity
+#mt_heatmap(SpiveyEtAl2005)
+
mt_remap_symmetric(
- data,
- use = "trajectories",
- save_as = use,
- dimensions = c("xpos", "ypos"),
- remap_xpos = "left",
- remap_ypos = "up"
-)
mt_remap_symmetric(
+ data,
+ use = "trajectories",
+ save_as = use,
+ dimensions = c("xpos", "ypos"),
+ remap_xpos = "left",
+ remap_ypos = "up"
+)
a mousetrap data object created using one of the mt_import
functions (see mt_example for details). Alternatively, a trajectory
array can be provided directly (in this case use
will be ignored).
a character string specifying which trajectory data should be used.
a character string specifying where the resulting trajectory data should be stored.
a character vector specifying the two dimensions in the trajectory array that contain the mouse positions, the first value corresponding to the x-positions, the second to the y-positions.
character string indicating the direction in which to remap values on the x axis. If set to "left" (as per default), trajectories with an endpoint on the right (i.e. with a positive x-value) will be remapped to the left. The alternatives are "right" which has the reverse effect, and "no", which disables remapping on the horizontal dimension.
character string defining whether tracks directed downwards on the y axis should be remapped so that they end with a positive y value. This will be performed if this parameter is set to "up" (which is the default), and the reverse occurs if the parameter is set to "down". If it is set to "no", y-values remain untouched.
A mousetrap data object (see mt_example) with remapped + + +
A mousetrap data object (see mt_example) with remapped
trajectories. If the trajectory array was provided directly as data
,
only the trajectory array will be returned.
# Remap trajectories so that all trajectories
-# end in the top-left corner
-mt_example <- mt_import_mousetrap(mt_example_raw)
-mt_example <- mt_remap_symmetric(mt_example)
-
-# Only flip trajectories vertically so that all
-# trajectories end in the upper half of the screen
-mt_example <- mt_import_mousetrap(mt_example_raw)
-mt_example <- mt_remap_symmetric(mt_example,
- remap_xpos="no", remap_ypos="up")
-
+ # Remap trajectories so that all trajectories
+# end in the top-left corner
+mt_example <- mt_import_mousetrap(mt_example_raw)
+mt_example <- mt_remap_symmetric(mt_example)
+
+# Only flip trajectories vertically so that all
+# trajectories end in the upper half of the screen
+mt_example <- mt_import_mousetrap(mt_example_raw)
+mt_example <- mt_remap_symmetric(mt_example,
+ remap_xpos="no", remap_ypos="up")
+
mt_resample(
- data,
- use = "trajectories",
- save_as = "rs_trajectories",
- dimensions = c("xpos", "ypos"),
- timestamps = "timestamps",
- step_size = 10,
- exact_last_timestamp = TRUE,
- constant_interpolation = NULL,
- verbose = FALSE
-)
mt_resample(
+ data,
+ use = "trajectories",
+ save_as = "rs_trajectories",
+ dimensions = c("xpos", "ypos"),
+ timestamps = "timestamps",
+ step_size = 10,
+ exact_last_timestamp = TRUE,
+ constant_interpolation = NULL,
+ verbose = FALSE
+)
a mousetrap data object created using one of the mt_import
functions (see mt_example for details). Alternatively, a trajectory
array can be provided directly (in this case use
will be ignored).
a character string specifying which trajectory data should be used.
a character string specifying where the resulting trajectory data should be stored.
a character vector specifying the dimensions in the
trajectory array that should be resampled. If "all"
, all trajectory
dimensions except the timestamps will be resampled.
a character string specifying the trajectory dimension containing the timestamps.
an integer specifying the size of the constant time interval. The unit corresponds to the unit of the timestamps.
logical indicating if the last timestamp should
always be appended (which is the case by default). If FALSE
, the
last timestamp is only appended if it is a multiple of the step_size.
an optional integer. If specified, constant
instead of linear interpolation will be performed for all adjacent
timestamps whose difference exceeds the number specified for
constant_interpolation
. The unit corresponds to the unit of the
timestamps.
logical indicating whether function should report its progress.
A mousetrap data object (see mt_example) with an additional + + +
A mousetrap data object (see mt_example) with an additional
array (by default called rs_trajectories
) containing the resampled
trajectories. If a trajectory array was provided directly as data
,
only the resampled trajectories will be returned.
mt_example <- mt_resample(mt_example,
- save_as="rs_trajectories",
- step_size=50)
-
+ mt_example <- mt_resample(mt_example,
+ save_as="rs_trajectories",
+ step_size=50)
+
mt_reshape(
- data,
- use = "trajectories",
- use_variables = NULL,
- use2 = "data",
- use2_variables = NULL,
- subset = NULL,
- subject_id = NULL,
- aggregate = FALSE,
- aggregate_subjects_only = FALSE,
- .funs = "mean",
- trajectories_long = TRUE,
- convert_df = TRUE,
- mt_id = "mt_id",
- mt_seq = "mt_seq",
- aggregation_function = NULL
-)
mt_reshape(
+ data,
+ use = "trajectories",
+ use_variables = NULL,
+ use2 = "data",
+ use2_variables = NULL,
+ subset = NULL,
+ subject_id = NULL,
+ aggregate = FALSE,
+ aggregate_subjects_only = FALSE,
+ .funs = "mean",
+ trajectories_long = TRUE,
+ convert_df = TRUE,
+ mt_id = "mt_id",
+ mt_seq = "mt_seq",
+ aggregation_function = NULL
+)
a mousetrap data object created using one of the mt_import
functions (see mt_example for details). Alternatively, a trajectory
array can be provided directly (in this case use
will be ignored).
a character string specifying which data should be reshaped. The
corresponding data are selected from data using data[[use]]
.
@@ -96,45 +98,63 @@
a character vector specifying which mouse-tracking variables should be reshaped. Corresponds to the column names in case a data.frame with mouse-tracking measures is provided. Corresponds to the labels of the array dimensions in case a trajectory array is provided. If unspecified, all variables will be reshaped.
an optional character string specifying where the other trial
data can be found. Defaults to "data" as data[["data"]]
usually
contains all non mouse-tracking trial data. Alternatively, a data.frame can
be provided directly.
an optional character string (or vector) specifying the
variables (in data[[use2]]
) that should be merged with the data. If
aggregate==TRUE
, the trajectories / measures will be aggregated
separately for each of the levels of these variables using
summarize_at.
a logical expression (passed on to subset) indicating
elements or rows to keep. If specified, data[[use2]]
will be
subsetted using this expression, and, afterwards, data[[use]]
will
be filtered accordingly.
an optional character string specifying which column
contains the subject identifier in data[[use2]]
. If specified and
aggregate==TRUE
, aggregation will be performed within subjects
first.
logical indicating whether data should be aggregated. If
use2_variables
are specified, aggregation will be performed
separately for each of the levels of the use2_variables
.
logical indicating whether data should only be
aggregated per subject (if subject_id
is specified and
aggregate==TRUE
).
the aggregation function(s) passed on to
summarize_at
. By default, the mean
is
calculated.
logical indicating if the reshaped trajectories
should be returned in long or wide format. If TRUE
, every recorded
@@ -144,6 +164,8 @@
xpos_1
,
xpos_2
, ...). Only relevant if data[[use]]
contains
trajectories.logical indicating if the reshaped data should be converted
to a data.frame
using as.data.frame
. This will
@@ -153,22 +175,31 @@
a character string specifying the name of the column that will
contain the trial identifier in the reshaped data. The values for the trial
identifier correspond to the rownames
of data[[use]]
and
data[[use2]]
.
a character string specifying the name of the column that will
contain the integers indicating the order of the mouse positions per
trajectory in the reshaped data. Only relevant if data[[use]]
contains trajectories and trajectories_long==TRUE
.
Deprecated. Please use .funs
instead.
# Time-normalize trajectories
-mt_example <- mt_time_normalize(mt_example)
-
-# Reshape time-normalized trajectories data into long format
-# adding Condition variable
-trajectories_long <- mt_reshape(mt_example,
- use="tn_trajectories",
- use2_variables="Condition"
- )
-
-# Reshape time-normalized trajectories data into wide format
-# only keeping xpos and ypos
-# and adding Condition variable
-trajectories_wide <- mt_reshape(mt_example,
- use="tn_trajectories", use_variables = c("xpos","ypos"),
- use2_variables = "Condition",
- trajectories_long = FALSE
- )
-
+ # Time-normalize trajectories
+mt_example <- mt_time_normalize(mt_example)
+
+# Reshape time-normalized trajectories data into long format
+# adding Condition variable
+trajectories_long <- mt_reshape(mt_example,
+ use="tn_trajectories",
+ use2_variables="Condition"
+ )
+
+# Reshape time-normalized trajectories data into wide format
+# only keeping xpos and ypos
+# and adding Condition variable
+trajectories_wide <- mt_reshape(mt_example,
+ use="tn_trajectories", use_variables = c("xpos","ypos"),
+ use2_variables = "Condition",
+ trajectories_long = FALSE
+ )
+
mt_sample_entropy(
- data,
- use = "tn_trajectories",
- save_as = "measures",
- dimension = "xpos",
- m = 3,
- r = NULL,
- use_diff = TRUE,
- verbose = FALSE
-)
mt_sample_entropy(
+ data,
+ use = "tn_trajectories",
+ save_as = "measures",
+ dimension = "xpos",
+ m = 3,
+ r = NULL,
+ use_diff = TRUE,
+ verbose = FALSE
+)
a mousetrap data object created using one of the mt_import
functions (see mt_example for details). Alternatively, a trajectory
array can be provided directly (in this case use
will be ignored).
a character string specifying which trajectory data should be used.
a character string specifying where the calculated measures should be stored.
a character string specifying the dimension based on which sample entropy should be calculated. By default (xpos), the x-positions are used.
an integer passed on to the sample entropy function (see Details).
a numeric value passed on to the sample entropy function (see Details).
logical indicating if the differences of the dimension values should be computed before calculating sample entropy (which is done by default, see Details).
logical indicating whether function should report its progress.
A mousetrap data object (see mt_example).
-If a data.frame with label specified in save_as
(by default
+
+
+
A mousetrap data object (see mt_example).
+ + +If a data.frame with label specified in save_as
(by default
"measures") already exists, the sample entropy values are added as
-additional column.
-If not, an additional data.frame will be added.
-If a trajectory array was provided directly as data
, only the
+additional column.
If not, an additional data.frame will be added.
+ + +If a trajectory array was provided directly as data
, only the
data.frame will be returned.
# Calculate sample entropy based on time-normalized
-# trajectories and merge results with other meausres
-# derived from raw trajectories
-mt_example <- mt_measures(mt_example)
-mt_example <- mt_time_normalize(mt_example,
- save_as="tn_trajectories", nsteps=101)
-mt_example <- mt_sample_entropy(mt_example,
- use="tn_trajectories", save_as="measures",
- dimension="xpos", m=3)
-
+ # Calculate sample entropy based on time-normalized
+# trajectories and merge results with other meausres
+# derived from raw trajectories
+mt_example <- mt_measures(mt_example)
+mt_example <- mt_time_normalize(mt_example,
+ save_as="tn_trajectories", nsteps=101)
+mt_example <- mt_sample_entropy(mt_example,
+ use="tn_trajectories", save_as="measures",
+ dimension="xpos", m=3)
+
mt_scale_trajectories(
- data,
- use = "trajectories",
- save_as = use,
- var_names,
- center = TRUE,
- scale = TRUE,
- within_trajectory = FALSE,
- prefix = "z_",
- transform = NULL
-)
mt_scale_trajectories(
+ data,
+ use = "trajectories",
+ save_as = use,
+ var_names,
+ center = TRUE,
+ scale = TRUE,
+ within_trajectory = FALSE,
+ prefix = "z_",
+ transform = NULL
+)
a mousetrap data object created using one of the mt_import
functions (see mt_example for details). Alternatively, a trajectory
array can be provided directly (in this case use
will be ignored).
a character string specifying which trajectory data should be used.
a character string specifying where the resulting trajectory data should be stored.
character vector giving the labels of the to be standardized variables.
logical specifying whether variables should be centered (i.e.,
mean = 0
). Can be a logical vector, in which case the values of
scale
are mapped to the variables specified in var_names
.
logical or numeric specifying the scaling of the variables. When
logical, scale = TRUE
normalizes the trajectory variable to sd = 1,
@@ -98,6 +108,8 @@
scale
are mapped to the variables specified in
var_names
.logical specifying whether trajectory variables
should be scaled within or across trajectories. If within_trajectory
@@ -107,18 +119,25 @@
Arguments
only true in the aggregate (i.e., across all trajectories). Can be a
logical vector, in which case the values of scale
are mapped to the
variables specified in var_names
.
character string added to the names of the new standardized
variables. If prefix = ""
, the original variables will be
overwritten.
function that takes a numeric matrix as argument and returns
a numeric matrix of same size with transformed values. If NULL
the
original values are passed on to standardization.
A mousetrap data object (see mt_example) with an additional + + +
A mousetrap data object (see mt_example) with an additional
variable containing the standardized trajectory variable added to the
trajectory array). If the trajectory array was provided directly as
data
, only the trajectory array will be returned.
# Calculate derivatives
-mt_example <- mt_derivatives(mt_example)
-
-# Standardize velocity across trajectories
-mt_example <- mt_scale_trajectories(mt_example,var_names = "vel")
-
+ # Calculate derivatives
+mt_example <- mt_derivatives(mt_example)
+
+# Standardize velocity across trajectories
+mt_example <- mt_scale_trajectories(mt_example,var_names = "vel")
+
mt_spatialize(
- data,
- use = "trajectories",
- dimensions = c("xpos", "ypos"),
- save_as = "sp_trajectories",
- n_points = 20
-)
mt_spatialize(
+ data,
+ use = "trajectories",
+ dimensions = c("xpos", "ypos"),
+ save_as = "sp_trajectories",
+ n_points = 20
+)
a mousetrap data object created using one of the mt_import
functions (see mt_example for details). Alternatively, a trajectory
array can be provided directly (in this case use
will be ignored).
a character string specifying which trajectory data should be used.
a character string specifying which trajectory variables should be used. Can be of length 2 or 3 for two-dimensional or three-dimensional data.
a character string specifying where the resulting trajectory data should be stored.
an integer or vector of integers specifying the number of points used to represent the spatially rescaled trajectories. If a single integer is provided, the number of points will be constant across trajectories. Alternatively, a vector of integers can provided that specify the number of points for each trajectory individually.
A mousetrap data object (see mt_example) with an additional + + +
A mousetrap data object (see mt_example) with an additional
array containing the spatialized trajectories. If a trajectory array was
provided directly as data
, only the spatialized trajectories will be
returned.
mt_standardize(
- data,
- use = "measures",
- use_variables = NULL,
- within = NULL,
- prefix = "z_",
- center = TRUE,
- scale = TRUE
-)
mt_standardize(
+ data,
+ use = "measures",
+ use_variables = NULL,
+ within = NULL,
+ prefix = "z_",
+ center = TRUE,
+ scale = TRUE
+)
a mousetrap data object created using one of the mt_import functions (see mt_example for details).
a character string specifying which data should be used. By
default points to the measures
data.frame created using
mt_measures.
a vector specifying which variables should be standardized. If unspecified, all variables will be standardized.
an optional character string specifying one or more variables
in data[["data"]]
. If specified, all measures will be standardized
separately for each level of the variable (or for each combination of
levels, if more than one variable is specified).
a character string that is inserted before each standardized variable. If an empty string is specified, the original variables are replaced.
argument passed on to scale.
argument passed on to scale.
A mousetrap data object (see mt_example) + + +
A mousetrap data object (see mt_example) including the standardized measures.
mt_example <- mt_measures(mt_example)
-
-# Standardize MAD and AD per subject
-mt_example <- mt_standardize(mt_example,
- use_variables=c("MAD", "AD"),
- within="subject_nr", prefix="z_")
-
-# Standardize MAD and AD per subject and Condition
-mt_example <- mt_standardize(mt_example,
- use_variables=c("MAD", "AD"),
- within=c("subject_nr", "Condition"),
- prefix="z_")
-
+ mt_example <- mt_measures(mt_example)
+
+# Standardize MAD and AD per subject
+mt_example <- mt_standardize(mt_example,
+ use_variables=c("MAD", "AD"),
+ within="subject_nr", prefix="z_")
+
+# Standardize MAD and AD per subject and Condition
+mt_example <- mt_standardize(mt_example,
+ use_variables=c("MAD", "AD"),
+ within=c("subject_nr", "Condition"),
+ prefix="z_")
+
mt_subset(data, subset, check = "data")
mt_subset(data, subset, check = "data")
a mousetrap data object created using one of the mt_import functions (see mt_example for details).
a logical expression (passed on to subset) indicating
the rows to keep. Missing values are taken as FALSE
.
a character string specifying which data should be used for checking the subset condition.
A mousetrap data object (see mt_example) with filtered + + +
A mousetrap data object (see mt_example) with filtered data and trajectories.
# Subset based on trial data
-mt_example_atypical <- mt_subset(mt_example, Condition=="Atypical")
-
-# Subset based on mouse-tracking measure (MAD)
-mt_example <- mt_measures(mt_example)
-mt_example_mad_sub <- mt_subset(mt_example, MAD<400, check="measures")
-
+ # Subset based on trial data
+mt_example_atypical <- mt_subset(mt_example, Condition=="Atypical")
+
+# Subset based on mouse-tracking measure (MAD)
+mt_example <- mt_measures(mt_example)
+mt_example_mad_sub <- mt_subset(mt_example, MAD<400, check="measures")
+
mt_time_normalize(
- data,
- use = "trajectories",
- save_as = "tn_trajectories",
- dimensions = c("xpos", "ypos"),
- timestamps = "timestamps",
- nsteps = 101,
- verbose = FALSE
-)
mt_time_normalize(
+ data,
+ use = "trajectories",
+ save_as = "tn_trajectories",
+ dimensions = c("xpos", "ypos"),
+ timestamps = "timestamps",
+ nsteps = 101,
+ verbose = FALSE
+)
a mousetrap data object created using one of the mt_import
functions (see mt_example for details). Alternatively, a trajectory
array can be provided directly (in this case use
will be ignored).
a character string specifying which trajectory data should be used.
a character string specifying where the resulting trajectory data should be stored.
a character vector specifying the dimensions in the
trajectory array that should be time-normalized. If "all"
, all
trajectory dimensions except the timestamps will be time-normalized.
a character string specifying the trajectory dimension containing the timestamps.
an integer specifying the number of equally sized time steps.
logical indicating whether function should report its progress.
A mousetrap data object (see mt_example) with an additional + + +
A mousetrap data object (see mt_example) with an additional
array (by default called tn_trajectories
) containing the
time-normalized trajectories. In this array, another dimension (called
steps
) has been added with increasing integer values indexing the
@@ -144,9 +159,9 @@
mt_example <- mt_time_normalize(mt_example,
- save_as="tn_trajectories", nsteps=101)
-
+ mt_example <- mt_time_normalize(mt_example,
+ save_as="tn_trajectories", nsteps=101)
+
an object of class mt_heatmap_raw.
further arguments passed to or from other methods.
read_mt(file, columns = "all", add_trialid = FALSE, add_filename = FALSE)
read_mt(file, columns = "all", add_trialid = FALSE, add_filename = FALSE)
a character string specifying the filename of the .mt file.
either 'all' or a character vector specifying the to be extracted variables. Defaults to 'all' in which case all existing variables will be extracted.
boolean specifying whether an additional column containing the trial number should be added.
boolean specifying whether an additional column containing the file name should be added.
A data.frame with one row per trial. Variables are ordered + + +
A data.frame with one row per trial. Variables are ordered according to columns, x-coordinates, y-coordinates, and timestamps.
if (FALSE) {
-# Read a single raw data file from MouseTracker
-# (stored in the current working directory)
-mt_data_raw <- read_mt("example.mt")
-
-# Use read_bulk to read all raw data files ending with ".mt" that are
-# stored in the folder "raw_data" (in the current working directory)
-library(readbulk)
-mt_data_raw <- read_bulk("raw_data", fun=read_mt, extension=".mt")
-
-# Import the data into mousetrap
-mt_data <- mt_import_wide(mt_data_raw)
-}
-
-
+ if (FALSE) {
+# Read a single raw data file from MouseTracker
+# (stored in the current working directory)
+mt_data_raw <- read_mt("example.mt")
+
+# Use read_bulk to read all raw data files ending with ".mt" that are
+# stored in the folder "raw_data" (in the current working directory)
+library(readbulk)
+mt_data_raw <- read_bulk("raw_data", fun=read_mt, extension=".mt")
+
+# Import the data into mousetrap
+mt_data <- mt_import_wide(mt_data_raw)
+}
+
+
scale_within(
- data,
- variables = NULL,
- within = NULL,
- prefix = "",
- center = TRUE,
- scale = TRUE
-)
scale_within(
+ data,
+ variables = NULL,
+ within = NULL,
+ prefix = "",
+ center = TRUE,
+ scale = TRUE
+)
a data.frame.
a character string (or vector) specifying one or more
variables that scale is applied to. If unspecified,
scale_within
will be applied to all variables in data.
an optional character string specifying the name of one or more
variables in data
. If specified, scale is applied separately
for each of the levels of the variable (or for each combination of levels,
if more than one variable is specified). Alternatively, a vector directly
containing the level values.
a character string that is inserted before each scaled variable. By default (empty string) the original variables are replaced.
argument passed on to scale.
argument passed on to scale.
The original data.frame including the centered and / or scaled + + +
The original data.frame including the centered and / or scaled variables.
ChickWeight_scaled <- scale_within(
- ChickWeight, variables="weight",
- within="Chick", prefix="z_")
-
+ ChickWeight_scaled <- scale_within(
+ ChickWeight, variables="weight",
+ within="Chick", prefix="z_")
+