Package 'animovement'

Title: An R toolbox for analysing animal movement across space and time
Description: An R toolbox for analysing animal movement across space and time.
Authors: Mikkel Roald-Arbøl [aut, cre]
Maintainer: Mikkel Roald-Arbøl <[email protected]>
License: MIT + file LICENSE
Version: 0.4.1
Built: 2024-11-13 13:27:46 UTC
Source: https://github.com/roaldarbol/animovement

Help Index


Calculate kinematics

Description

[Experimental]

Calculate kinematics.

Usage

calculate_kinematics(data)

Arguments

data

Data frame

Value

A data frame with kinematics calculated


Calculate summary statistics

Description

[Experimental]

Calculate summary statistics for tracks

Usage

calculate_statistics(
  data,
  measures = "median_mad",
  straightness = c("A", "B", "C", "D")
)

Arguments

data

A kinematics data frame

measures

Measures of central tendency and dispersion. Options are median_mad (default) and mean_sd. See description for more information.

straightness

Which method to calculate path straightness. Choose between "A" (default), "B", "C"... or a combination (e.g. "c("A","B")"). See description for details about the different calculations.

Value

An data frame data frame with kinematics calculated


Clean kinematics

Description

[Experimental]

Usage

clean_kinematics(data)

Arguments

data

tidy movement data frame with kinematics

Value

a clean kinematics data frame


Group every N observations together

Description

[Experimental]

Sometimes your sampling rate is too high; group_every allows you to down-sample by creating "bins" which can subsequently be summarised on. When using n, data needs to be regularly sampled; if there are gaps in time, the bin duration will differ. Works well with calculate_summary() for movement data.

Usage

group_every(data, seconds = NULL, n = NULL)

Arguments

data

Input data frame

seconds

Number of seconds to bin together

n

Number of observations to include in each bin/group

Value

Grouped data frame, with new "bin" variable.

Examples

## Group by every 5 seconds
df_time <- data.frame(
  time = seq(from = 0.02, to = 100, by = 1/30), # time at 30Hz, slightly offset
  y = rnorm(3000)) # random numbers

df_time |>
  group_every(seconds = 5) |> # group for every 5 seconds
  dplyr::summarise(time = min(time), # summarise for time and y
                   mean_y = mean(y)) |>
  dplyr::mutate(time = floor(time)) # floor to get the round second number

# Group every n observations
df <- data.frame(
  x = seq(1:1000),
  y = rnorm(1000))

df |>
  group_every(n = 30) |> # group every 30 observations together
  dplyr::summarise(mean_x = mean(x),
                   mean_y = mean(y))

Read AnimalTA data

Description

[Experimental]

Usage

read_animalta(path, detailed = FALSE)

Arguments

path

An AnimalTA data frame

detailed

Animal export either raw (default) or detailed data files. We only have limited support for detailed data.

Value

a movement dataframe


Read centroid tracking data from Bonsai

Description

[Experimental]

Usage

read_bonsai(path)

Arguments

path

Path to a Bonsai data file

Value

a movement dataframe


Read DeepLabCut data

Description

[Experimental]

Read csv files from DeepLabCut (DLC). The function recognises whether it is a single- or multi-animal dataset.

Usage

read_deeplabcut(path, multianimal = NULL)

Arguments

path

Path to a DeepLabCut data file

multianimal

By default, whether a file is multi-animal is detected automatically. This gives an option to ensure it. logical TRUE/FALSE.

Value

a movement dataframe


Read idtracker.ai data

Description

[Experimental]

Usage

read_idtracker(path, path_probabilities = NULL, version = 6)

Arguments

path

Path to an idtracker.ai data frame

path_probabilities

Path to a csv file with probabilities. Only needed if you are reading csv files as they are included in h5 files.

version

idtracker.ai version. Currently only v6 output is implemented

Value

a movement dataframe


Read LightningPose data

Description

[Experimental]

Read csv files from LightningPose (LP).

Usage

read_lightningpose(path)

Arguments

path

Path to a LightningPose data file

Value

a movement dataframe


Read movement data

Description

[Experimental]

Usage

read_movement(data)

Arguments

data

A movement data frame

Value

a movement dataframe


Read SLEAP data

Description

[Experimental]

Usage

read_sleap(path)

Arguments

path

A SLEAP analysis data frame in HDF5 (.h5) format

Value

a movement dataframe


Read trackball data

Description

[Experimental]

Read trackball data from a variety of setups and configurations.

Usage

read_trackball(
  paths,
  setup = c("of_free", "of_fixed", "fictrac"),
  sampling_rate,
  col_time = "time",
  col_dx = "x",
  col_dy = "y",
  ball_calibration = NULL,
  ball_diameter = NULL,
  distance_scale = NULL,
  distance_unit = NULL,
  verbose = FALSE
)

Arguments

paths

Two file paths, one for each sensor (although one is allowed for a fixed setup, of_fixed).

setup

Which type of experimental setup was used. Expects either of_free, of_fixed or fictrac (soon).

sampling_rate

Sampling rate tells the function how long time it should integrate over. A sampling rate of 60(Hz) will mean windows of 1/60 sec are used to integrate over.

col_time

Which column contains the information about time. Can be specified either by the column number (numeric) or the name of the column if it has one (character). Should either be a datetime (POSIXt) or seconds (numeric).

col_dx

Column name for x-axis values

col_dy

Column name for y-axis values

ball_calibration

When running an of_fixed experiment, you may (but it is not necessary) provide a calibration factor. This factor is the number recorded after a 360 degree spin. You can use the calibrate_trackball function to get this number. Alternatively, provide the ball_diameter and a distance_scale (e.g. mouse dpcm).

ball_diameter

When running a of_fixed experiment, the ball diameter is needed together with either ball_calibration or distance_scale.

distance_scale

If using computer mice, you might be getting unit-less data out. However, computer mice have a factor called "dots-per-cm", which you can use to convert your estimates into centimeters.

distance_unit

Which unit should be used. If distance_scale is also used, the unit will be for the scaled data. E.g. for trackball data with optical flow sensors, you can use the mouse dots-per-cm (dpcm) of 394 by setting distance_unit = "cm" and distance_scale = 394.

verbose

If FALSE (default), suppress most warning messages.

Value

a movement dataframe


Read treadmill data

Description

[Experimental]

Usage

read_treadmill(data)

Arguments

data

A treadmill data frame

Value

a movement dataframe


Read TRex data

Description

[Experimental]

Usage

read_trex(path)

Arguments

path

Path to a TRex data frame in CSV format.

Value

a movement dataframe


Smooth tracks

Description

[Experimental]

Filtering/smoothing tracks is standard practice to root out noise in movement data. Here we provide some filter functions to do this. The function expects the data to be in the standard format, containing at least x, y and time variables.

Usage

smooth_track(data, method = c("rolling_median"), window_width = 5)

Arguments

data

Data frame

method

Which smoothing method to use. Currently only rolling mean is implemented ("rolling_mean").

window_width

How many observations to use for rolling window filters (e.g. "rolling_mean" or "rolling_median").

Value

A movement data frame