-
Notifications
You must be signed in to change notification settings - Fork 0
/
diceTask.R
333 lines (293 loc) · 10.7 KB
/
diceTask.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# Leon Schöppl (2021) <https://github.com/leon-schoeppl/ptt-calculator/>
# DTSv1.0
analyzeDiceTask <- function(vecA, vecC) {
library(tidyverse)
library(dplyr)
library(rapportools)
#-----------------------------------------------------------------------------
# checking that the input constitutes a Dice Task
if (!is.vector(vecA) |!is.vector(vecC)){
stop('Invalid input: Expected 2 vectors.')
}
if (length(vecA)!= length(vecC)){
stop('Invalid input: Unequal vector length.')
}
if (!all(is.logical(vecA))) {
stop('Invalid input: Vector A contains non-boolean value.')
}
if (!all(is.logical(vecC))){
stop('Invalid input: Vector C contains non-boolean value.')
}
if (length(vecA)>6){
stop('Invalid input: Vectors contain too many values.')
}
#-----------------------------------------------------------------------------
# Vectors shorter than 6 values are taken to be uncertainty tasks with an
# appropriate amount of blank sides.
aBlanks = list(c(0), c(0), c(0), c(0), c(0), c(0))
cBlanks = list(c(0), c(0), c(0), c(0), c(0), c(0))
constituents <<- NULL
numberOfConceiledSides <- (6 - length(vecA))
if (numberOfConceiledSides > 0){
for (i in 1 :numberOfConceiledSides ){ #preparation to expand the grid
additionalVariable <- list(c(0,1),c(0,1))
constituents <- c(constituents, additionalVariable)
}
constituents <- rev(expand.grid(constituents)) #grid expansion
for (i in 1 : numberOfConceiledSides){ #grid to vectors
aBlanks[[i]]<-constituents[,i]
cBlanks[[i]]<-constituents[,(i+numberOfConceiledSides)]
}
}
#-----------------------------------------------------------------------------
# function substituting 0 for undefined values resulting from division by 0.
replaceNA <- function(column){
for (i in 1 : length(column)){
if (is.na(column[i]) | is.nan(column[i])){
column[i]<-c(0)
}
}
return(column)
}
#-----------------------------------------------------------------------------
# Reads out the inputs and (if applicable) the arrays containing the variables
# for blank sides.
A <- (sum(vecA) + aBlanks[[1]] + aBlanks[[2]] + aBlanks[[3]] + aBlanks[[4]]
+ aBlanks[[5]] + aBlanks[[6]]) #irrelevant values equal 0
C <- (sum(vecC) + cBlanks[[1]] + cBlanks[[2]] + cBlanks[[3]] + cBlanks[[4]]
+ cBlanks[[5]] + cBlanks[[6]]) #irrelevant values equal 0
nA<- 6 - A # count of ¬A sides
nC<- 6 - C # count of ¬C sides
tempA <- sum(vecA) # ignoring the blank sides
tempC <- sum(vecC) # ignoring the blank sides
tempAC <- 0 # ignoring the blank sides
if (length(vecA)>0){
for (i in 1 : length(vecA)){
if (vecA[i] & vecC[i]){
tempAC <- tempAC + 1
}
}
}
# AC is the count of sides with both A and C
AC<- (tempAC + aBlanks[[1]]*cBlanks[[1]] + aBlanks[[2]]*cBlanks[[2]]
+ aBlanks[[3]]*cBlanks[[3]] + aBlanks[[4]]*cBlanks[[4]]
+ aBlanks[[5]]*cBlanks[[5]] + aBlanks[[6]]*cBlanks[[6]])
tempnAnC <- 0 # ignoring the blank sides
if(length(vecA)>0){
for (i in 1 : length(vecA)){
if (!vecA[i] & !vecC[i]){
tempnAnC <- tempnAnC + 1
}
}
}
# nAnC is the count of sides with both ¬A and ¬C
nAnC <- tempnAnC
if (numberOfConceiledSides > 0){
for (i in 1 : numberOfConceiledSides){
nAnC <- nAnC + ((1-aBlanks[[i]])*(1-cBlanks[[i]]))
}}
# CnA is the count of sides with C but ¬A
CnA <- C - AC
tempCnA <- tempC - tempAC # ignores blanks
# AnC is the count of sides with A but ¬C
AnC <- A - AC
tempAnC <- tempA - tempAC # ignores blanks
# pCgA is the probability of C given A
pCgA<-AC/A
pCgA <-replaceNA(pCgA)
# pCgnA is the probability of C given ¬A
pCgnA<-CnA/nA
pCgnA <- replaceNA(pCgnA)
# pAgC is the probability of A given C
pAgC <- AC/C
pAgC <- replaceNA(pAgC)
# pAgnC is the probability of A given ¬C
pAgnC <- AnC/nC
pAgnC <- replaceNA(pAgnC)
# pnCgA is the probability of ¬C given A
pnCgA <- AnC/A
pnCgA <- replaceNA(pnCgA)
#-----------------------------------------------------------------------------
# Calculates the uncertainty intervals for a wide range of interpretations of
# the natural language conditionals used in the experiments.
# --> interpretation
materialConditional <- ((AC + CnA + nAnC)/6)
# 'halfway' --> interpretation
fullignoreMaterialConditional <- ((tempAC + tempCnA + tempnAnC)/ 6)
# <-> interpretation
equivalent <- (AC / 6 + nAnC / 6)
# 'halfway' <-> interpretation
fullignoreEquivalent <- tempAC / 6 + tempnAnC / 6
# & interpretation
conjunction <- AC / 6
# 'halfway'& interpretation
fullignoreConjunction <- tempAC / 6
# | interpretation
conditionalP <- pCgA
# 'halfway' | interpretation
fullignoreConditionalP <- tempAC / tempA # without blanks
fullignoreConditionalP<-replaceNA(fullignoreConditionalP)
# || interpretation
biconditionalP <- AC / (6 - nAnC)
biconditionalP<-replaceNA(biconditionalP)
# 'halfway' || interpretation
fullignoreBiconditionalP <- tempAC / (6 - tempnAnC)
fullignoreBiconditionalP<-replaceNA(fullignoreBiconditionalP)
# special &l interpretation
specialLowignoredConjunction <- tempAC / (6 - numberOfConceiledSides)
specialLowignoredConjunction <- replaceNA(specialLowignoredConjunction)
#-----------------------------------------------------------------------------
# Calculates various measures of confirmation, among them delta P.
# Nozick, 1981
nozick<-pAgC -pAgnC
# Christensen, 1999 (also 'delta P')
deltaP<-pCgA-pCgnA
# Kemeny & Oppenheim, 1952
kemeny<-(pAgC-pAgnC)/(pAgC+pAgnC)
kemeny<-replaceNA(kemeny)
# Finch, 1960
finch<- (pCgA/(C/6))
finch<-replaceNA(finch)
finch <- finch - 1
# Rips, 2001
rips<-pnCgA/(nC/6)
rips<-replaceNA(rips)
rips<- 1-rips
# difference (Carnap, 1962; Eells, 1982; Jeffrey, 1992)
difference<- pCgA - C/6
# Carnap, 1962
carnap<-(AC/6)-(A/6 * C/6)
# Mortimer, 1988
mortimer<- pAgC - A/6
#-----------------------------------------------------------------------------
# prints the results
interpretationTable = data.frame(
interpretation = c("Material Implication (-->)",
"--> upper-ignored",
"--> lower-ignored",
"--> fully-ignored",
"Equivalent (<->) ",
"<-> upper-ignored",
"<-> lower-ignored",
"<-> fully-ignored",
"Conjunction (&)",
"& upper-ignored",
"& lower-ignored",
"& fully-ignored",
"Conditional Probability (|)",
"| upper-ignored",
"| lower-ignored",
"| fully-ignored",
"Biconditional (||) ",
"|| upper-ignored",
"|| lower-ignored",
"|| fully-ignored",
"special & lower-ignored"),
min = c(min(materialConditional),
min(materialConditional),
min(fullignoreMaterialConditional),
min(fullignoreMaterialConditional),
min(equivalent),
min(equivalent),
min(fullignoreEquivalent),
min(fullignoreEquivalent),
min(conjunction),
min(conjunction),
min(fullignoreConjunction),
min(fullignoreConjunction),
min(conditionalP),
min(conditionalP),
min(fullignoreConditionalP),
min(fullignoreConditionalP),
min(biconditionalP),
min(biconditionalP),
min(fullignoreBiconditionalP),
min(fullignoreBiconditionalP),
min(specialLowignoredConjunction)),
max = c(max(materialConditional),
max(fullignoreMaterialConditional),
max(materialConditional),
max(fullignoreMaterialConditional),
max(equivalent),
max(fullignoreEquivalent),
max(equivalent),
max(fullignoreEquivalent),
max(conjunction),
max(fullignoreConjunction),
max(conjunction),
max(fullignoreConjunction),
max(conditionalP),
max(fullignoreConditionalP),
max(conditionalP),
max(fullignoreConditionalP),
max(biconditionalP),
max(fullignoreBiconditionalP),
max(biconditionalP),
max(fullignoreBiconditionalP),
max(conjunction)),
stringsAsFactors = FALSE
)
print(interpretationTable)
if(length(vecA)==6){
print(
paste0("Because this task doesn't feature uncertainty, ",
"interpretations predict point values instead of intervals ",
"and halfway interpretations trivially overlap with their ",
"main versions.")
)
}
consequenceNotionTable = data.frame(
inferentialStrengthNotion = c("deltaP/ Christensen",
"Kemeny & Oppenheim",
"Difference",
"Carnap",
"Nozick",
"Mortimer",
"Finch",
"Rips"),
min = c(min(deltaP),
min(kemeny),
min(difference),
min(carnap),
min(nozick),
min(mortimer),
min(finch),
min(rips)),
max = c(max(deltaP),
max(kemeny),
max(difference),
max(carnap),
max(nozick),
max(mortimer),
max(finch),
max(rips)),
mean = c(mean(deltaP),
mean(kemeny),
mean(difference),
mean(carnap),
mean(nozick),
mean(mortimer),
mean(finch),
mean(rips)),
median = c(median(deltaP),
median(kemeny),
median(difference),
median(carnap),
median(nozick),
median(mortimer),
median(finch),
median(rips)),
stringsAsFactors = FALSE
)
print(consequenceNotionTable)
}
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# USAGE:
# Expects as input 2 equal length vectors containing 6 or fewer boolean values
# each. VecA should contain whether the side in question makes the
# antecedent of the conditional true, VecC the conditional.
# for empty boolean vectors use <- logical()
vectorA <- c(F,T,T,T)
vectorC <- c(F,F,F,T)
analyzeDiceTask(vectorA, vectorC)