aggregating-looks: Aggregate looks

Description Usage Arguments Details Value Examples

Description

Aggregate the number of looks to each response type over some grouping variables like Subject, Time, Condition.

Usage

1
2
3
aggregate_looks(data, resp_def, formula)

aggregate_looks2(data, resp_def, resp_var, ...)

Arguments

data

a long data frame of looking data

resp_def

a response definition or a list of response definition.

formula

an aggregation formula. The lefthand terms will be grouping variables, and the righthand term is the column with eyetracking responses.

resp_var

Name of the column that contains eyetracking responses

...

Grouping columns.

Details

This function is the main tool for preparing eyetracking data for a growth curve analysis. For example, an aggregation formula like Subject + Time ~ Gaze would provide the number of looks to each image over time for each subject.

aggregate_looks() uses an aggregation formula like stats::aggregate(), whereas aggregate_looks2() uses column names.

Value

a dataframe of the grouping columns along with the number of looks to each response type, the proportion (and standard error) of looks to the primary response, and the proportion (and standared error) of missing data.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
target_def <- create_response_def(
  label = "looks to target",
  primary = "Target",
  others = c("PhonologicalFoil", "SemanticFoil", "Unrelated"),
  elsewhere = "tracked",
  missing = NA)

four_image_data %>%
  aggregate_looks(target_def, Subject + TrialNo ~ GazeByImageAOI)

four_image_data %>%
  aggregate_looks(target_def, Subject ~ GazeByImageAOI) %>%
  str()

# With column names
four_image_data %>%
  aggregate_looks2(target_def, GazeByImageAOI, Subject, TrialNo)

four_image_data %>%
  aggregate_looks2(target_def, GazeByImageAOI, Subject) %>%
  str()

phonological_def <- create_response_def(
  label = "looks to phonological foil",
  primary = "PhonologicalFoil",
  others = c("Target", "SemanticFoil", "Unrelated"),
  elsewhere = "tracked",
  missing = NA)

# Aggregate looks to multiple response definitions at once
defs <- list(target_def, phonological_def)
four_image_data %>%
  aggregate_looks(defs, Subject + BlockNo ~ GazeByImageAOI) %>%
  dplyr::select(.response_def, Subject, BlockNo, Primary:PropNA) %>%
  dplyr::mutate_at(c("Prop", "PropSE", "PropNA"), round, 3)

# Compute a growth curve
growth_curve <- four_image_data %>%
  adjust_times(Time, TargetOnset, Subject, BlockNo, TrialNo) %>%
  aggregate_looks(target_def, Time ~ GazeByImageAOI) %>%
  filter(-1000 <= Time, Time <= 2000)

library(ggplot2)
ggplot(growth_curve) +
  aes(x = Time, y = Prop) +
  geom_hline(size = 2, color = "white", yintercept = .25) +
  geom_vline(size = 2, color = "white", xintercept = 0) +
  geom_pointrange(aes(ymin = Prop - PropSE, ymax = Prop + PropSE)) +
  labs(y = "Proportion of looks to target",
       x = "Time relative to target onset [ms]") +
  theme_grey(base_size = 14)

tjmahr/littlelisteners documentation built on June 3, 2021, 2:10 p.m.