-
Notifications
You must be signed in to change notification settings - Fork 48
Example R script for processing UXF data
Jack Brookes edited this page May 20, 2020
·
2 revisions
Here is a commented example of an R script (written in Tidyverse style) that will process the data for a typical UXF task.
library(tidyverse)
# assume our data is stored in a folder called `data` in our R project.
# within the `data` folder is our experiment folder (i.e. name of the experiment settings profile)
# there can be multiple experiment folders, maybe you use the settings profiles for different conditions.
# within the experiment folders, is each participant folder.
# within those, is the session folder for each participant.
# e.g:
# project_folder/
# โโโ data/
# โโโ experiment_condition_1
# โ โโโ Participant01
# โ โ โโโS001
# โ โ โ โโโ (all UXF data files)
# โ โ โโโS002
# โ โ โโโ (all UXF data files)
# โ โโโ Participant02
# โ โโโS001
# โ โ โโโ (all UXF data files)
# โ โโโS002
# โ โโโ (all UXF data files)
# โโโ experiment_condition_2
# โโโ Participant03
# โ โโโS001
# โ โ โโโ (all UXF data files)
# โ โโโS002
# โ โโโ (all UXF data files)
# โโโ Participant04
# โโโS001
# โ โโโ (all UXF data files)
# โโโS002
# โโโ (all UXF data files)
# first, we load all the trial_results files.
# we do this by recursively searching all files that match a pattern.
# then reading all the files we find (with `map`) and binding them row-wise (`_dfr`)
posture_trials <- list.files(
path = "data",
pattern = "trial_results.csv",
full.names = TRUE,
recursive = TRUE
) %>%
map_dfr(read_csv)
# thats all our behavioural data!
# we can do any further processing or analysis on the `posture_trials` dataframe
# now if we want any movement data for each trial,
# we can do this by reading each filename given in the `*_movement_filename` column.
# then we can use `unnest` to give 1 row per timestep.
# (in this example, `center_eye_movement_filename`)
posture_movement <- posture_trials %>%
mutate(center_eye_movement = map(file.path("data", directory, center_eye_movement_filename), read_csv)) %>%
unnest()
# now we have 1 row per timestep.
# we can now write a function which calculates (for example) path length and summarise by it.
# grouping will give us 1 row per trial again
calculate_path_length <- function(x, y, z) {
# calculates sum of point-to-point distances.
sum(
(diff(x) ^ 2 +
diff(y) ^ 2 +
diff(z) ^ 2) ^ 0.5
)
}
posture_summary <- posture_movement %>%
group_by(experiment, ppid, session_num, trial_num, assessment_type) %>%
summarise(path_length = calculate_path_length(pos_x, pos_y, pos_z))
# that outputs 1 row per trial, with our new movement summary summary statistic column.
๐ง Core topics
- ๐ Background
- โจ UXF 2.0
- โ๏ธ Compatibility
- ๐ถ๏ธ Oculus Quest Setup
- ๐ญ Concepts
- ๐ ๏ธ Get started
- ๐ Examples
- ๐ฅ๏ธ Built-in UI
- ๐ Session generation
- โฐ Events
- ๐ Data collection
- โ๏ธ Collect custom data
- ๐ Custom Data Handler
- ๐ Remote Data Collection
- ๐๏ธ WebGL DynamoDB setup
- ๐ Processing DynamoDB CSVs
- ๐ซ HTTP Post Setup
- ๐ง Settings system
- ๐๐ฝ Tracker system
- ๐ Logging system
โ ๏ธ Common issues- ๐ผ๏ธ Multi-scene experiments
- ๐บ Videos
- ๐จโ๐ Full written tutorial
- ๐ฆ Asset links
- ๐จโ๐ซ Unity tutorial links
- ๐ Useful code snippets
- ๐ก Programming ideas
- ๐งฎ Example R processing