gaze_smoothing: smooth gaze points

Usage Arguments Examples

Usage

1
gaze_smoothing(data, windowSize, method)

Arguments

data
windowSize
method

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
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (data, windowSize, method) 
{
    data$GazePointXSmoothed <- rep(NA, nrow(data))
    data$GazePointYSmoothed <- rep(NA, nrow(data))
    movingAverageVectorX <- c()
    movingAverageVectorY <- c()
    movingAverageHelper <- function(method, numbers) {
        if (method == "mean") {
            mean(numbers)
        }
        else {
            median(numbers)
        }
    }
    for (i in 1:nrow(data)) {
        if ((!is.na(data$GazePointX[i])) & (!is.na(data$GazePointY[i])) & 
            (!is.na(data$Validity[i]))) {
            for (j in (-(windowSize - 1)/2):((windowSize - 1)/2)) {
                if ((i + j >= 1) & (i + j <= nrow(data))) {
                  if (!is.na(data$Validity[i + j])) {
                    movingAverageVectorX <- append(movingAverageVectorX, 
                      data$GazePointX[i + j])
                    movingAverageVectorY <- append(movingAverageVectorY, 
                      data$GazePointY[i + j])
                  }
                }
            }
            data$GazePointXSmoothed[i] <- movingAverageHelper(method, 
                movingAverageVectorX)
            data$GazePointYSmoothed[i] <- movingAverageHelper(method, 
                movingAverageVectorY)
            movingAverageVectorX <- c()
            movingAverageVectorY <- c()
        }
    }
    return(data)
  }

rwoldford/EyeFixR documentation built on May 12, 2019, 4:37 a.m.