prepare.netfacs: Take data that are not currently in format and turn them into...

View source: R/prepare_netfacs.R

prepare.netfacsR Documentation

Take data that are not currently in format and turn them into the correct format for netfacs function

Description

The netfacs function requires data to be entered with the element data as a matrix of each element by each event, with occurrence marked as 1 and non-occurrence marked as 0.
This is often not the case, so this function transforms data in other routine formats to have the right look.
Specifically, users can define whether they want to enter 'photos', which indicates that all elements in an event are simply strung together in a vector; or they define 'video', in which case it is assumed that each element has a start and an end point in a specified video

Usage

prepare.netfacs(
  elements,
  type = c("video", "photo"),
  video.id = NULL,
  start.time = NULL,
  duration = NULL,
  separator = ",",
  frame.duration = NULL
)

Arguments

elements

vector with either one element per index (for videos) or all elements that occurred in the whole event (for photos)

type

either 'video' or 'photo'. If 'photo', the function separates the string and returns a matrix of the correct dimensions. If 'video', the function creates a matrix using the highest common factor of all 'durations' and for each of those 'frames' assigns whether each element was present or absent

video.id

name of the video, so all cases are treated together. For photos, can be entered so that photos can be matched to IDs after

start.time

for videos, time when the element is first active

duration

for videos, how long is the element active for

separator

for photos, how are elements separated in the list

frame.duration

for videos, how long is a 'frame' supposed to last? If NULL, frame duration is the shortest 'duration' of any element specified

Details

The assumption for this function is that for photos, elements are stored like this:
'AU1/AU2/AU3/AU4'
'AU1/AU3/AU4'
'AU1/AU2'

For videos, the assumption is that they are stored in a data frame like this:
element = AU1, video.id = 1, start.time = 0.5, duration = 2sec

Value

Function returns a list with element.matrix (the matrix of elements and when they occurred) and video.info (the supporting information, e.g. video names, durations, frames etc)

Examples

# for a photo
au.photos <- c(
  "AU1/AU5/AU9",
  "AU1/AU2",
  "AU1/AU2/AU10",
  "AU1/AU2",
  "AU5/AU17/AU18",
  "AU6/AU12"
)
au.names <- c("photo1", "photo2", "photo3", "photo4", "photo5", "photo6")
au.prepared <- prepare.netfacs(
  elements = au.photos,
  type = "photo",
  video.id = au.names,
  separator = "/"
)
au.prepared$element.matrix
au.prepared$video.info

# for a video
aus <- c(
  "AU1", "AU5", "AU9",
  "AU1", "AU2",
  "AU1", "AU2", "AU10",
  "AU1", "AU2",
  "AU5", "AU17", "AU18",
  "AU6", "AU12"
)
video.names <- c(
  rep("video1", 3),
  rep("video2", 2),
  rep("video3", 3),
  rep("video4", 2),
  rep("video5", 3),
  rep("video6", 2)
)
start.times <- c(
  0.1, 0.2, 0.3,
  0.1, 0.3,
  0.1, 0.4, 0.4,
  0.1, 0.2,
  0.1, 0.5, 0.6,
  0.1, 0.2
)
durations <- rep(0.3, times = length(start.times))
frame.dur <- 0.05
au.prepared <- prepare.netfacs(
  elements = aus,
  type = "video",
  video.id = video.names,
  start.time = start.times,
  duration = durations,
  frame.duration = frame.dur
)
head(au.prepared$element.matrix)
head(au.prepared$video.info)

NetFACS documentation built on March 18, 2022, 7:40 p.m.