mt_scale_trajectories centers and / or standardizes selected trajectory variables within or across trajectories.

mt_scale_trajectories(
  data,
  use = "trajectories",
  save_as = use,
  var_names,
  center = TRUE,
  scale = TRUE,
  within_trajectory = FALSE,
  prefix = "z_",
  transform = NULL
)

Arguments

data

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).

use

a character string specifying which trajectory data should be used.

save_as

a character string specifying where the resulting trajectory data should be stored.

var_names

character vector giving the labels of the to be standardized variables.

center

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.

scale

logical or numeric specifying the scaling of the variables. When logical, scale = TRUE normalizes the trajectory variable to sd = 1, whereas scale = FALSE leaves the variable on its original scale. When numeric, the trajectory variables are scaled by (i.e., divided by) the specific value in scale. Can also be a numeric vector, in which case the values of scale are mapped to the variables specified in var_names.

within_trajectory

logical specifying whether trajectory variables should be scaled within or across trajectories. If within_trajectory == TRUE, scaling trajectories to mean = 0 and sd = 1 means that every to be standardized trajectory variable will have mean = 0 and sd = 1. If within_trajectory == FALSE (the default), mean = 0 and sd = 1 are 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.

prefix

character string added to the names of the new standardized variables. If prefix = "", the original variables will be overwritten.

transform

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.

Value

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.

See also

mt_standardize for standardizing mouse-tracking measures per level of other variables.

Author

Dirk U. Wulff

Examples

# Calculate derivatives
mt_example <- mt_derivatives(mt_example)

# Standardize velocity across trajectories
mt_example <- mt_scale_trajectories(mt_example,var_names = "vel")