Anotate Movement

Anotate dataframes by adding movement related data/computations as columns

add_angular_diff()

Add angular difference wrt reference direction to movement or eye tracker data frame

add_direction()

Add movement direction to movement data frame

add_dist()

Add column with distance to stationary target

add_dist2()

Add column with distance to moving target

add_fixation2target()

Add target fixations to eyetracker data

add_gaze_elevation()

Add gaze elevation to (head) movement or eye tracker data frame

add_in_view()

Add column indicating if a stationary or moving target is in foveal view

add_orientation2target()

Add direction of the orientation of a reference object relative to a stationary target (in 2D, XZ).

add_orientation2target2()

Add direction of the orientation of a reference object relative to a target movement (in 2D, XZ).

add_rot()

Add rotation matrix to movement or eye tracker data frame

add_rot_eye()

Helper function that takes an eye tracker data frame and adds a new column R with the rotation matrices.

add_rot_move()

Helper function that takes a movement data frame and adds a new column R with the rotation matrices.

add_speed()

Add movement speed to movement data frame

add_vector2target()

Add vector of a reference object relative to a stationary target

add_vector2target2()

Add gaze vector of a reference object relative to a target movement

Extract Movement

Extract common computations from data

extract_at_distance()

Extract at specific distance from a reference position, using any extract function

extract_at_time()

Extract value of inner column at specified time

extract_direction()

Extract mean direction between a min_time and max_time as unit vector.

extract_displacement()

Extract net displacement between a min_time and max_time.

extract_durations()

Extract durations of discrete values in a movement tibble

extract_fixation()

Extract ratio of target fixation between a min_time and max_time. You can supply timestamps to min_time and max_time (e.g timestamp of begin escape) to average over only a period, or use the entire duration of the provided data frame.

extract_fruit_task()

Extract fruit picking between a min_time and max_time. You can supply timestamps to min_time and max_time (e.g timestamp of begin escape) to average over only a period. In this case, you can also retrieve the collection rate by setting rate to 1.

extract_frequent_label()

Extracts the most frequent label in a time series tibble.

extract_gaze_elevation()

Extract gaze elevation between a min_time and max_time.

extract_movement_dist()

Extract (min, max or mean) 2D distance between movement trajectory and reference position.

extract_movement2_dist()

Extract (min, max or) 2D distance between two movement trajectories.

extract_orientation()

Extract direction of the orientation of a reference object relative to a stationary target (in 2D, XZ) between a min_time and max_time.

extract_orientation2()

Extract direction of the orientation of a reference object relative to a target movement (in 2D, XZ) between a min_time and max_time.

extract_path_length()

Extract 2D Path Length from Movement Data

extract_pupil()

Extract pupil diameter statistics between a min_time and max_time

extract_recording_duration()

Extract recording duration of a movement tibble

extract_sequence()

Extract value sequence of inner column between a min_time and max_time.

extract_speed()

Extract speed (peak or average speed) between a min_time and max_time.

extract_speed_angular()

Extract angular speed (peak or average speed) for a direction vector between a min_time and max_time.

extract_timemask()

Extract a timemask from a dataframe for use in extract_with_timemask

extract_with_timemask()

Wrap extract_* functions with a mask on time.

extract_time_bins()

Extract number of time bins in a movement tibble

extract_timestamp_duplicates()

Extract duplicated time stamps.

Movement Processing

Guess times; validate, prepare, resample or summarise movement data

average_timeseries()

Average a list of resampled time series (movement, fruit collection or eyetracking) data frames

check_valid_movement()

Check whether movement data frame contains valid tracker information

combine_movement()

Combine and resample two movement data frames

convert_qualisys2vrthreat()

This function extracts one body point position data from a nested qualisys tibble, and converts it to a standalone movement tibble, which can be processed with standard vrthreat functions. Use join_data to integrate qualisys data into a trial results tibble first.

correct_movement_timing()

Correct movement timing

get_first_fruit_collection()

Get time of first fruit collection

get_fruit_time()

Get fruit appearance or collect time for the n-th fruit This function returns the exact time stamp of this fruit.

guess_first_view()

Guess first time an object is in foveal view

guess_escape_begin_time()

Guess start of escape

guess_escape_end_time()

Guess end of escape time

guess_escape_abortion()

Guess escape abortion position and time

guess_move_from_pos()

Guess First Move From Position

guess_move_at_pos()

Guess First or Last Move From or To Position

guess_pos_at_time()

Guess/interpolate position at a point in time

guess_threat_speed()

Estimate actual threat speed from movement data

guess_time_at_dist2()

Guess time at a distance between two movement data frames

find_movement_latencies()

Find the temporal latency between two movement trajectories

prepare_gaze_data()

Prepare gaze data for further processing

reorient_movement()

Reorient movement data by affine transformation

reorient_movement_to_start()

Reorient movement data frame such that initial values match start position and orientation

reorient_qualisys2unity()

Reorient movement data from Qualisys to Unity

reorient_unity2qualisys()

Reorient movement data from Unity to Qualisys

resample_eyetracker()

Resample an eyetracker data frame to new time index.

resample_filter_pos()

Resample and median-filter position and rotation columns in a movement data frame

resample_fruit_task()

Resample a fruit collection frame to new time index.

resample_movement()

Resample a movement data frame.

summarise_movement()

Summarise movement data frame for each unique time stamp

translate_movement_to_ref()

Translate positions in movement data frame to reference position.

Label Processing

Manage label columns (i.e columns containing strings) in dataframes.

add_ngram()

Add n-grams to a tibble containing label data

clean_labels()

Clean labels

find_all_labels()

Find all unique labels across trials

map_labels()

Construct a label column from an existing one via a mapping.

merge_labels()

Merge by concatenating labels from different columns

reduce_label_sequence()

Reduce a tibble by replacing rows where a label is repeated consecutively with just the first row.

Trial Processing

Manage trial data at a high level

apply_replacements()

Apply replacements using replacement data frame.

average_timeseries_cols()

Average time series data columns within group

check_tracker_cols()

Check movement data columns

correct_movement_timing_cols()

Correct movement timing across columns

create_threat_name()

Create threat name column from episode name

fix_old_names()

Fixes names in older versions of the output. Specifically, deletes the occurance of "vrthreat_" in any column names.

get_label_distribution()

Get distribution of labels or similar categorical data across a trial results dataframe.

remove_tutorials()

Remove tutorial trials - i.e. episode either containing "Tutorial" or "Practice"

reorient_movement_cols()

Reorient movement data columns by affine transformation

reorient_movement_cols_to_start()

Reorient movement columns to starting position.

reorient_qualisys2unity_cols()

Reorient movement data columns from Qualisys into Unity

resample_eyetracker_cols()

Resample eyetracker data columns

resample_fruit_task_cols()

Resample fruit task data columns

resample_movement_cols()

Resample and relocate movement data columns

summarise_movement_cols()

Summarise movement data columns to ensure unique time stamps

translate_ref_movement_cols()

Translate movement cols as per reference column

process_trial_results()

Proprocess a trial results tibble

Scenario Processing

Extract scenario related data from .json files

find_fruit_position()

Find fruit position

find_initial_threat_position()

Find initial threat position from programmatic scenario planner

find_safe_position()

Find safe position

find_scenario_position()

Find scenario position

find_start_position()

Find Start marker position and rotation

find_unity_threat_name()

Find Unity's internal threat name

find_weapon_position()

Find weapon position

flatten_scenario_data()

Flatten a nested "scene json" list into a tidy data frame

get_time_of_first_event()

Get Time Of First Sequence Event

get_time_of_first_event_multi()

Get Time Of First Sequence Event across multiple sequence columns

generate_position_list()

Generate position list

Questionnaire

Manage quest data

read_quest_data()

Read and score questionnaire data

read_quest_raw()

Read raw (csv) questionnaire data

replace_redcapid_ppid()

Replace Redcap id in questionnaires by VR ppid

sub_sum_quest()

Get sum of a questionnaire subscale

sum_mssq()

Get MSSQ subscale score (Motion Sickness; Golding, 2006)

sum_quest()

Get sum of a questionnaire if questionnaire exists

Audio Processing

Help play and annotate sounds

detect_sound()

Automatically detect sounds in audio recording using a volume/duration threshold

detect_sound_cols()

Automatically detect sounds across an entire data frame

get_audio_section()

Get audio section

join_sound_classification()

Join a sound classification file into trial_results tibble

play_audio_from_threat()

Play audio recording from threat appearance to the end

play_audio_section()

Play audio section

read_sound_classification()

Read manual sound detection file

sound_classification_manual()

Manually classify sounds

sound_detection_manual()

Manually detect sounds

write_audio_section()

Write audio section

IO functions

Save figures and read data from Unity, Json, CSV into R.

clean_scenario_data()

Clean Scenario Data Column

create_out_folders()

Create output folders under an experiment name

load_trial_results()

Load and Optionally Clean Trial Results

join_data()

Join CSV Files to Trial Results

read_csv_files()

Read CSV Files

read_json_files()

Read JSON Files

read_log_messages()

Read log messages

read_log_messages_weapons()

Read and Join Weapon Log Messages

read_participant_details()

Read participant details from files

read_study_data()

Read complete study data

read_trial_results()

Read Trial Results

remove_study_path()

Remove study path from file path

remove_tld()

Remove top-level directory in a full file path.

save_fig()

Wrapper around ggsave to save figures.

split_path()

Split a path name into into its components

standardise_path()

Standardise file path

update_file_pointers()

Update file pointers

Data Interfacing

Interface with STAN

array2STAN()

Convert 1-3 dimensional array to STAN format

Maths

Mathematical helper functions

angle_between()

This uses R base functions to calculate the angle between two vectors in degrees, accounting for rounding errors to avoid NaNs.

angle_diff_deg()

Calculate angle difference in degrees, respecting angles <0 or >360.

calculate_2d_angle_deg()

Calculate 2D angle between positive z-axis and a line from reference to target position in degrees

calculate_2d_dist()

Calculate 2D Euclidean distance between two positions

cart2sph()

Transform cartesian to spherical coordinates

create_resampling_index()

Create resampling index at desired sample rate

cummean_na()

Calculate cummean with previous neighbour interpolation

eulunity2rot()

Convert rotation in Unity Euler angles (in degrees) into 3D rotation matrix

rot2eulunity()

Convert a 3x3 rotation matrix to Unity-style Euler angles (in degrees)

eulunity2quaternion()

Convert rotation in Unity Euler angles (in degrees) into a quaternion

quaternion2eulunity()

Convert a 3D rotation quaternion into Unity Euler angles (in degrees)

quaternion2rot()

Convert a 3D rotation quaternion into a Rotation Matrix

rot2quaternion()

Convert a 3x3 rotation matrix to a rotation quaternion

find_argmax()

Find index of maximum, avoiding warnings and errors

find_argmin()

Find index of minimum, avoiding warnings and errors

find_max()

Find maximum, avoiding warnings

find_min()

Find minimum, avoiding warnings

median_quaternion()

Compute the geometric median rotation from a list of quaternions

orthdist()

Perpendicular distance of p3 from p1 along p1p2

proj_vec2vec()

Project vector x onto vector y

proj_vec2plane()

Project 3D-vector x into the plane spanned by y and z

rot2centralangle()

Compute central angle between two rotation matrices, for a direction vector

reorient_eulunity()

Apply a rotation matrix R to rot_x rot_y and rot_z columns

timeseries_mean()

Compute the mean across a vector x respecting time t, using trapezium rule.

vec2rot()

Find a rotation matrix that maps one vector onto the other

Statistical Modelling

Fit statistical models to data

fit_mdl()

Fit (generalised) linear model, checking for convergence, and obtain marginal means

fit_mdl_robust()

Fit (generalised) linear random effects model robustly, checking for convergence

fit_lmer_model()

Safely fit a linear mixed-effects model using lme4::lmer

Plotting functions

Scale, theme and plot 3D movement

plot_3D_movement()

Plot 3D movements for one trial

scale_pastel()

Pastel colored ggplot scale

scale_vrthreat_endstate()

VR Threat End State ggplot scale

scale_vrthreat_planningtime()

VR Threat Planning Time ggplot scale

scale_vrthreat_scenariotype()

VR Threat Scenario Type ggplot scale

theme_vrthreat()

VR Threat ggplot theme #'

plot_action_heatmaps()

Produce a heatmap of movement data filtered by actions and action labels

plot_community_bubbles()

Plot a graph using community bubbles

Validation

Validate inputs and generate expressive warnings

validate_has_columns()

Validate if given tibble has required columns.

validate_has_gaze_direction()

Ensures if given tibble has gaze_direction_x, gaze_direction_y and gaze_direction_z columns

validate_has_gaze_or_rotation()

Ensures if given tibble has either rot_x, rot_y and rot_z columns or gaze_direction_x, gaze_direction_y and gaze_direction_z columns

validate_has_position_or_rotation()

Ensures if given tibble has either rot_x, rot_y and rot_z columns or pos_x, pos_y and pos_z columns

validate_has_position()

Ensures if given tibble has pos_x, pos_y and pos_z columns

validate_has_rotation()

Ensures if given tibble has rot_x, rot_y and rot_z columns

validate_has_time()

Validate if given tibble has a time column, checks if all NA and ensures minimum length

validate_numeric()

Validates that the argument is numeric. Fail quietly if NA_real_

validate_option()

Validates that an option parameter is one of the allowed values.

validate_positional_list()

Ensures if given list has pos_x, pos_y and pos_z columns of the same length. Ensures minimum number of rows

validate_skip_on_null()

Check for NULLs

validate_tibble_non_empty()

Validate tibble, ensure minimum length and check for fully NA columns

validate_time_interval()

Validate if given tibble has enough timestamps in

validate_overlap()

Check if two data frames with time column overlap in time

validate_vector_lengths()

Ensure every vector has the same length or has length 1

Utility

Deal with unity file management

compare_colnames()

Compare Column Names Between Two Data Frames

create_file_paths()

Create Directory Paths Recursively

create_weapon_details()

Extract and annotate weapon-related details from raw event messages

find_hierarchy_object()

Find Hierarchy Object

find_hierarchy_object_any()

Find Hierarchy Object Matching Any Name

find_log_message()

Find messages in a session log and assign to trials

identify_na_columns()

Identify Columns with Missing Values

prepare_for_public_release()

Prepare trial results tibble for public release

remove_missing_columns()

Remove Columns with All Missing Values

test_source_fun_run_tests_rep_coverage()

Source Functions, Run Tests, and Report Coverage

Constants

Constants

example_data

Example Data containing player movement and eye tracking

fruit_gameobject_names

Common fruit object names used in VRthreat Unity