-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBestPestParticipant.R
103 lines (86 loc) · 2.6 KB
/
BestPestParticipant.R
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# TODO: Make histogram of all participants' thresholds
# and standard deviations?
# TODO: Figure out a meaningful analysis of results
# TODO: Make data structure for gaze data
# TODO: Figure out a way to determine whether gaze was ok close to wanted positions
# Per-trial: See max gaze deviation after lo-pass filter (filter out gaze tracker noise). If above threshold, discard trial.
# Per-participant: Calculate mean and standard deviation for thresholds
# PARTICIPANT has members id, T1, T2, T3, T4
MakeParticipant = function(id, T1, T2, T3, T4)
{
participant = list("id" = id, "T1" = T1, "T2" = T2, "T3" = T3, "T4" = T4)
return(participant)
}
GetTrialMatrix = function(participant)
{
trials = ConcatenateTrials(participant$T1, participant$T2, participant$T3, participant$T4)
return(trials)
}
GetThresholdsMatrix = function(participant)
{
# Assuming threshold value is the last in each trial
p = participant
threshold = ConcatenateTrials(tail(p$T1, 1),tail(p$T2, 1),tail(p$T3, 1),tail(p$T4, 1))
return(c("id" = p$id, threshold))
}
PlotStimulusValues = function(participant)
{
trials = GetTrialMatrix(participant)
plot(trials$Stimulus,
col = ifelse(trials$Trial == "T1" | trials$Trial == "T3", 'black', 'red'),
main=paste("Participant ", participant$id),
xlab="Observation",
ylab="Stimulus level",
ylim=c(0,140))
}
PlotThresholdValues = function(participant)
{
thresholds = GetThresholdsMatrix(participant)
plot(thresholds$Stimulus,
col = 'black',
main=paste("Participant ", thresholds$id),
xlab="Trial",
ylab="Stimulus level threshold",
ylim=c(0,140))
}
PlotThresholdValuesMultiple = function(participants)
{
par(mfrow=c(length(participants),2))
for(i in 1:length(participants))
{
PlotThresholdValues(participants[i])
}
}
ConcatenateTrials = function(T1, T2, T3, T4)
{
T1 = cbind(T1, "T1")
T2 = cbind(T2, "T2")
T3 = cbind(T3, "T3")
T4 = cbind(T4, "T4")
colnames(T1)[ncol(T1)] = "Trial"
colnames(T2) = colnames(T1)
colnames(T3) = colnames(T1)
colnames(T4) = colnames(T1)
output = rbind(T1, T2, T3, T4)
#names(output) = ["Stimulus", "Response", "TrialNumber"]
return (output)
}
GetThresholdStats = function(participant)
{
thresholds = GetThresholdsMatrix(participant)$Stimulus
meanVal = mean(thresholds)
stdev = sd(thresholds)
stats = list("Thresholds" = thresholds, "Mean" = meanVal, "SD"=stdev)
return(stats)
}
ExtractIDs = function(...)
{
ps = list(...)
output = integer()
output[1] = 12
for(i in 1:length(ps))
{
output[i] = ps[i]$id
}
return(output)
}