Description Usage Arguments Details Examples
View source: R/dilation_speed_outliers_to_na.R
dilation_speed_outliers_to_na
calculates the dilation speed based on
timestamps and pupil size measurements and then sets outliers to missing
(NA).
1 | dilation_speed_outliers_to_na(pupil, time, constant = 10)
|
pupil |
A numeric vector of pupil size measurements. |
time |
A vector containing the timestamps associated with the pupil size measurements. |
constant |
A numeric value specifying the threshold for outlier removal. The default is 10. |
The exact method of calculating the dilation speed is taken from Kret & Sjak-Shie (2018).
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 | # Load the "dplyr", "tidyr", and "ggplot2" packages:
library(dplyr)
library(tidyr)
library(ggplot2)
# Example 1: Artificial data
# Create some artificial data:
data <- tibble(
time = 0:5,
pupil_left = c(3.11, 3.13, 3.17, 3.7, 3.16, 3.12),
pupil_right = c(2.92, 2.95, 2.99, 3.5, 2.97, 2.95)
)
data
# Remove outliers:
mutate(data,
pupil_left = dilation_speed_outliers_to_na(pupil_left, time,
constant = 10),
pupil_right = dilation_speed_outliers_to_na(pupil_right, time,
constant = 10)
)
Example 2: Realistic data
blink
# Remove outliers:
blink <- mutate(blink,
pupil_left_new = dilation_speed_outliers_to_na(pupil_left, timestamp,
constant = 10),
pupil_right_new = dilation_speed_outliers_to_na(pupil_right, timestamp,
constant = 10)
)
# Restructure the data and plot the results to compare the pupil measurements
# before the outlier removal and after the outlier removal:
blink %>%
rename(
pupil_left_old = pupil_left,
pupil_right_old = pupil_right
) %>%
pivot_longer(
cols = starts_with("pupil"),
names_to = c("pupil", "status"),
names_pattern = "(left|right)_(old|new)",
values_to = "pupil_size"
) %>%
ggplot(aes(x = timestamp, y = pupil_size, color = status)) +
geom_point() +
facet_wrap(~ pupil)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.