Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #6

Merged
merged 78 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
df00196
Removed dplyr dependencies
M1V0 Sep 26, 2024
eaddc6d
Update README.md
M1V0 Sep 26, 2024
8b78113
add option to suppress messages
M1V0 Sep 26, 2024
b511479
Writing tutorial for eyetools
M1V0 Sep 26, 2024
6af4b97
Update eyetools.Rmd
M1V0 Sep 26, 2024
0845580
added further content
M1V0 Sep 27, 2024
57f6537
Update AOI_seq.R
M1V0 Sep 27, 2024
cc598ac
remove dependencies
M1V0 Sep 27, 2024
58d4e7d
include error catches
M1V0 Sep 27, 2024
a740aaa
Update AOI_seq.R
M1V0 Sep 27, 2024
1b83d59
tidied up functions
M1V0 Sep 27, 2024
7a427d7
vignette updates
M1V0 Sep 27, 2024
4bd7e40
Update eyetools.Rmd
M1V0 Sep 27, 2024
2fac9ab
remove mutate()
M1V0 Sep 27, 2024
2f2d937
update man/
M1V0 Sep 27, 2024
1ea6445
Update test-AOI_seq.R
M1V0 Sep 27, 2024
1e66ce1
Create Animating-eyetools-data.Rmd
M1V0 Sep 27, 2024
15a1bd3
Update fixation_dispersion.R
M1V0 Sep 27, 2024
e64cfef
Update eyetools.Rmd
M1V0 Oct 7, 2024
0270178
site updates
M1V0 Oct 7, 2024
2df8e79
update vignette
tombeesley Oct 8, 2024
666f717
paring down package size
M1V0 Oct 9, 2024
66acf90
removed redundancy in code
M1V0 Oct 9, 2024
f5e0583
paring down package size
M1V0 Oct 9, 2024
39d6802
Update fixation_dispersion.R
M1V0 Oct 9, 2024
633dd00
Update Animating-eyetools-data.Rmd
M1V0 Oct 9, 2024
9e276c5
removed fix_data/raw_data for just data
M1V0 Oct 9, 2024
e8197b5
updates for build checks
M1V0 Oct 9, 2024
1939eaf
added data
M1V0 Oct 9, 2024
a6cb3ac
Delete sketch_pad_file.R
tombeesley Oct 9, 2024
f1678ac
Merge branch 'develop' of https://github.com/tombeesley/eyetools into…
tombeesley Oct 9, 2024
8bde238
Update eyetools.Rmd
M1V0 Oct 9, 2024
5ff8b47
update datafiles
M1V0 Oct 9, 2024
9f3d4f3
enabled multi-ppt input; check for fixation data
M1V0 Oct 10, 2024
460b111
improved ppt checks
M1V0 Oct 10, 2024
00dfb45
enabled multi-ppt check
M1V0 Oct 10, 2024
0e47f09
enabled multi-ppt check
M1V0 Oct 10, 2024
02c5072
made changes to the main vignette page
tombeesley Oct 10, 2024
89a53e4
improved multi-ppt check
M1V0 Oct 11, 2024
d0dad90
enabled multi-ppt check
M1V0 Oct 11, 2024
72f22e8
Update AOI_time.R
M1V0 Oct 11, 2024
12eb4f7
enabled multi-ppt check
M1V0 Oct 11, 2024
a60489d
enabled multi-ppt format (no col drop)
M1V0 Oct 11, 2024
be7748d
enabled multi-ppt input
M1V0 Oct 14, 2024
0f32b27
Update smoother.R
M1V0 Oct 14, 2024
4c1885d
enabled multi-ppt input
M1V0 Oct 14, 2024
f022b29
fixes to multi-ppt
M1V0 Oct 14, 2024
577bb19
updated/fixed multi-ppt input
M1V0 Oct 15, 2024
0fc95a8
Add AOIs for HCL data
M1V0 Oct 15, 2024
8b903c7
Update eyetools.Rmd
M1V0 Oct 15, 2024
d975cfb
Fixed span bug
M1V0 Oct 15, 2024
b4a5af8
Update .Rbuildignore
M1V0 Oct 15, 2024
630ec15
Update eyetools.Rmd
M1V0 Oct 15, 2024
1cde473
Update eyetools.Rmd
M1V0 Oct 15, 2024
92c6ae7
Update interpolate.R
M1V0 Oct 15, 2024
8f6a367
updates and build check
M1V0 Oct 15, 2024
e8501c9
build updates
M1V0 Oct 15, 2024
4f98eae
build updates
M1V0 Oct 15, 2024
5807307
updated examples for all functions
M1V0 Oct 15, 2024
88fca95
updated data files
M1V0 Oct 15, 2024
69ce0ed
build update
M1V0 Oct 15, 2024
7cbc84d
Update check_ppt_n.R
M1V0 Oct 15, 2024
ab52cda
Update plot_seq.R
M1V0 Oct 16, 2024
c8af31f
Convert plot_spatial to data/data_type
M1V0 Oct 16, 2024
a777f1d
Update plot_spatial.R
M1V0 Oct 16, 2024
434aa7c
updates for CRAN checks
M1V0 Oct 16, 2024
3168327
updates to function descriptions
M1V0 Oct 16, 2024
7ca672f
Cran-ready update
M1V0 Oct 16, 2024
4e336d0
CRAN checks
M1V0 Oct 16, 2024
77214cf
change trialNumber to trial for consistency
M1V0 Oct 16, 2024
8d2176c
fixed interpolate report function
M1V0 Oct 16, 2024
2a5ed9d
added in interpolate report
M1V0 Oct 16, 2024
a3f8939
Update interpolate.R
M1V0 Oct 17, 2024
d567e43
Added AOI_time proportion parameter
M1V0 Oct 17, 2024
013c4cc
Update eyetools.Rmd
M1V0 Oct 17, 2024
10913aa
added plot option to smoother()
M1V0 Oct 17, 2024
64a28c5
Update Animating-eyetools-data.Rmd
M1V0 Oct 17, 2024
29751ce
updates to documentation
M1V0 Oct 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 5 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
^.*\.Rproj$
^\.Rproj\.user$
^fix_dispersion_old\.R$
^_pkgdown\.yml$
^docs$
^pkgdown$
^\.github$
^vignettes/articles$
^index\.Rmd$
^_config\.yml$
^README\.Rmd$
^inst/extdata$
115,910 changes: 0 additions & 115,910 deletions 102_EG_dec.csv

This file was deleted.

120 changes: 0 additions & 120 deletions 102_training.csv

This file was deleted.

Binary file removed 5000_rows_works_PC.RDS
Binary file not shown.
31 changes: 18 additions & 13 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
Type: Package
Package: eyetools
Title: Tools for eye data analysis
Version: 0.6.1
Title: Tools for Eye Data Analysis
Version: 0.7.0
Authors@R: c(
person("Beesley", "Tom", email = "t.beesley@lancaster.ac.uk", role = c("aut", "cre")),
person("Ivory", "Matthew", email = "matthew.ivory@lancaster.ac.uk", role = "aut"))
Description: A set of tools for eye data processing. The intended flow is
from data processing, to fixation analysis, to data visualisation and
trial level summaries.
person("Beesley", "Tom", , "matthew.ivory@lancaster.ac.uk", role = c("aut", "cre")),
person("Ivory", "Matthew", , "matthew.ivory@lancaster.ac.uk", role = "aut")
)
Description: A set of tools for easier eye data processing.
It enables automation of actions across the pipeline starting from combining binocular data, repairing missing data,
through to event-related processing (fixations, saccades, time in AOIs), to data visualisation. These tools take relatively raw (trial, time, x, and y form) data
and can be used to return fixations, saccades, and AOI entries and time spent in AOIs.
As the tools rely on this basic data format, the functions can work with data from any eye tracking device.
License: GPL-3
cph: Tom Beesley
URL: https://tombeesley.github.io/eyetools/
Depends:
R (>= 2.10)
Imports:
dplyr,
ggforce,
ggplot2,
glue,
hdf5r,
lifecycle,
magick,
magrittr,
pbapply,
rdist,
rlang,
Expand All @@ -29,11 +32,13 @@ Imports:
Suggests:
knitr,
rmarkdown,
testthat (>= 3.0.0)
VignetteBuilder: knitr
testthat (>= 3.0.0),
tidyverse
VignetteBuilder:
knitr
Config/testthat/edition: 3
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
URL: https://tombeesley.github.io/eyetools/
Config/testthat/edition: 3
Language: en-GB
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ export(plot_seq)
export(plot_spatial)
export(saccade_VTI)
export(smoother)
import(dplyr)
import(ggforce)
import(ggplot2)
import(hdf5r)
import(rlang)
importFrom(glue,glue)
importFrom(lifecycle,deprecated)
importFrom(magick,image_read)
importFrom(magrittr,"%>%")
importFrom(pbapply,pblapply)
importFrom(rlang,.data)
importFrom(stats,aggregate)
Expand Down
9 changes: 9 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
# eyetools 0.7.0
* added support for multi-participant data in most functions
* standardised expected data input to functions
* added optional parameter for proportion of time spent to AOI_time()
* fixed smoother() span parameter
* added plots to smoother()
* improved handling of variable order in all functions

# eyetools 0.6.1
* added new functions: compare_algorithms(), conditional_transform(), fixation_VTI(), hdf5_to_csv()

# eyetools 0.6.0

Expand Down
105 changes: 71 additions & 34 deletions R/AOI_seq.R
Original file line number Diff line number Diff line change
@@ -1,63 +1,97 @@
#' Sequence analysis of area of interest entries
#'
#' Analyses the sequence of entries into defined AOI regions across trials. Works with fixation data or raw data as the input.
#' Analyses the sequence of entries into defined AOI regions across trials. Can only be used with fixation data with a "fix_n" column denoting fixation events.
#'
#' @param data A dataframe with fixation data (from fix_dispersion) or raw data.
#'
#' @param data A dataframe with fixation data (from fixation_dispersion). Either single or multi participant data
#' @param AOIs A dataframe of areas of interest (AOIs), with one row per AOI (x, y, width_radius, height).
#' @param AOI_names An optional vector of AOI names to replace the default "AOI_1", "AOI_2", etc.
#' @param sample_rate Optional sample rate of the eye-tracker (Hz) for use with raw_data. If not supplied, the sample rate will be estimated from the time column and the number of samples.
#' @param long Whether to return the AOI fixations in long or wide format. Defaults to long
#' @return a long format dataframe containing the sequence of entries into AOIs on each trial
#' @param participant_ID the variable that determines the participant identifier. If no column present, assumes a single participant
#' @return a dataframe containing the sequence of entries into AOIs on each trial.
#'
#' If long is TRUE, then each AOI entry is returned on a new row, if FALSE, then a row per trial is returned with all AOI entries in one character string
#' @export
#'
#' @examples
#' fix_d <- fixation_dispersion(example_raw_WM)
#' AOI_seq(fix_d, AOIs_WM)
#' data <- combine_eyes(HCL)
#' fix_d <- fixation_dispersion(data, participant_ID = "pNum")
#'
#' AOI_seq(fix_d, AOIs = HCL_AOIs, participant_ID = "pNum")
#'
#' @importFrom stats setNames complete.cases
#' @importFrom utils stack

AOI_seq <- function(data,
AOIs,
AOI_names = NULL,
sample_rate = NULL,
long = TRUE) {
AOI_seq <- function(data, AOIs, AOI_names = NULL, sample_rate = NULL, long = TRUE, participant_ID = "participant_ID") {

# split data by trial
proc_data <- sapply(split(data, data$trial),
AOI_seq_trial_process,
AOIs = AOIs,
AOI_names)
if(is.null(data[["fix_n"]])) stop("column 'fix_n' not detected. Are you sure this is fixation data from eyetools?")

data <- data.frame(trial = unique(data$trial),
AOI_entry_seq = proc_data)
#first check for multiple/single ppt data
test <- .check_ppt_n_in(participant_ID, data)
participant_ID <- test[[1]]
data <- test[[2]]

if (long == TRUE) {
#internal_AOI_seq carries the per-participant functionality to be wrapped in the lapply for ppt+ setup
internal_AOI_seq <- function(data, AOIs, AOI_names, sample_rate, long) {

split_list <- strsplit(data$AOI_entry_seq,';')

split_list_names <- setNames(split_list, data$trial)
# split data by trial
proc_data <- sapply(split(data, data$trial),
AOI_seq_trial_process,
AOIs = AOIs,
AOI_names)

data <- stack(split_list_names)
data <- data.frame(data[[participant_ID]][1],
trial = unique(data$trial),
AOI_entry_seq = proc_data)

data <- data.frame(trial = as.numeric(data$ind),
AOI = data$value)
colnames(data)[1] <- participant_ID #keep same column as entered

# add in entry_n by way of indexing each trial
get_row_n <- function(i) {
store <- data[data$trial == i,]
store$entry_n <- 1:nrow(store)
if (long == TRUE) {

store
}
split_list <- strsplit(data$AOI_entry_seq,';')

data <- do.call(rbind.data.frame, lapply(1:max(data$trial), get_row_n))
split_list_names <- setNames(split_list, data$trial)

}
data_long <- stack(split_list_names)

data <- data.frame(participant_ID = data[[participant_ID]][1],
trial = as.numeric(data_long$ind),
AOI = data_long$value)

#keep original name
colnames(data)[1] <- participant_ID

# add in entry_n by way of indexing each trial
get_row_n <- function(i) {
store <- data[data$trial == i,]

if (nrow(store) == 0) { store <- NULL} else {
store$entry_n <- 1:nrow(store)}

store
}

return(data)
data <- do.call(rbind.data.frame, lapply(1:max(data$trial), get_row_n))

data <- data[data$AOI != "NA",] # remove rows that are NA
}
#RETURN THE DATA TO THE SAME FORMAT IF SINGLE PPT
if (data[[participant_ID]][1] == "NOT A VALID ID") data[[participant_ID]] <- NULL

return(data)

}

data <- split(data, data[[participant_ID]])
out <- lapply(data, internal_AOI_seq, AOIs, AOI_names, sample_rate, long)
out <- do.call("rbind.data.frame", out)
rownames(out) <- NULL

out <- .check_ppt_n_out(out)

return(out)
}


Expand All @@ -73,7 +107,7 @@ AOI_seq_trial_process <- function(trial_data, AOIs, AOI_names) {
# square AOI
aoi_entries[,a] <- ((trial_data$x >= AOIs[a,1]-AOIs[a,3]/2 & trial_data$x <= AOIs[a,1]+AOIs[a,3]/2) &
(trial_data$y >= AOIs[a,2]-AOIs[a,4]/2 & trial_data$y <= AOIs[a,2]+AOIs[a,4]/2))
} else if (sum(!is.na(AOIs[a,])) == 3) {
} else if (sum(!is.na(AOIs[a,])) == 3) {
# circle AOI
aoi_entries[,a] <- sqrt((AOIs[a,1]-trial_data$x)^2+(AOIs[a,2]-trial_data$y)^2) < AOIs[a,3]
} else {
Expand All @@ -87,15 +121,18 @@ AOI_seq_trial_process <- function(trial_data, AOIs, AOI_names) {

# simplify to vector of AOI entries
aoi_seq <- rowSums(aoi_entries)
aoi_seq <- aoi_seq[aoi_seq>0] # remove fixations without aoi hits
#aoi_seq <- aoi_seq[aoi_seq>0] # remove fixations without aoi hits
find_repeat_entries <- c(TRUE, diff(aoi_seq)!=0)
aoi_seq <- aoi_seq[find_repeat_entries]
aoi_seq <- aoi_seq[aoi_seq != 0] #remove non AOI fixations

if (is.null(AOI_names)==FALSE) {
aoi_seq <- paste0(AOI_names[aoi_seq], collapse = ";")
} else {
aoi_seq <- paste0(aoi_seq, collapse = ";")
}


return(aoi_seq)

}
Expand Down
Loading
Loading