# Pattern notebook

## TV 3

The sample size:

```(len (ssi sb (= \$tv 3)))
```
 15

How many subjects answered each quiz question correctly:

```(.sum (getl quiz (ssi sb (= \$tv 3))))
```
I value
better-amount 14
better-prob 15
immediate 11
faster-completion 15

The number of subjects who answered every question correctly:

```(setv s-tv3-all-correct (list
(get quiz.index (.all (getl quiz (ssi sb (= \$tv 3))) 1))))
(len s-tv3-all-correct)
```
 10

Number of I choices, all TV 3 subjects (recall that there are 60 trials):

```(.order (kwc .sum (= (getl ts (ssi sb (= \$tv 3)) "choice") "I") :level "sn"))
```
sn choice
s037 0
s038 0
s040 0
s041 0
s032 1
s035 2
s033 3
s036 3
s028 5
s026 11
s039 14
s031 20
s030 27
s029 30
s027 35

Number of I choices, only lab subjects who answered every quiz question correctly:

```(.order (kwc .sum (= (getl ts s-tv3-all-correct "choice") "I") :level "sn"))
```
sn choice
s017 1
s019 1
s021 1
s016 6
s003 8
s026 11
s024 27
s030 27
s029 30
s027 35

Quantiles of the above (expressed as proportions out of 60):

```(rd 2 (.quantile
(kwc .mean (= (getl ts s-tv3-all-correct "choice") "I") :level "sn")
[.25 .5 .75]))
```
I value
0.25 0.04
0.50 0.16
0.75 0.45

For comparison, the corresponding quantiles in the 49 subjects of Luhmann, Ishida, and Hajcak (2011) are .17, .43, and .63.

Also for comparison, here's the MTurk subjects:

```(.order (kwc .sum (= (getl ts (ssi sb (< \$tv 3)) "choice") "I") :level "sn"))
```
sn choice
s022 0
s017 1
s019 1
s021 1
s023 3
s018 4
s016 6
s003 8
s006 14
s024 27

So it looks like lab subjects are taking more I options, but maybe still not enough.

Choices of I after D has become available are still rare. This is the complete list:

```(ss ts (& (> \$rt \$dwait) (= \$choice "I")))
```
sn block trial dwait choice rt won tt
s024 3 1 11.568 I 13.188 4 6
s030 2 1 6.392 I 11.830 0 3
s030 3 3 7.716 I 9.756 0 8
s030 16 3 14.593 I 14.729 0 47
s039 9 2 6.995 I 8.186 4 25
s039 10 3 6.849 I 9.395 0 29
s043 8 3 10.697 I 13.431 0 23
s045 5 1 5.285 I 5.550 4 12
s045 5 2 6.241 I 6.707 4 13
s045 6 3 7.265 I 7.368 0 17
s049 1 1 8.650 I 9.954 0 0

## TV 4

For TV 4, I changed the gamble amounts and probabilities and switched to hypothetical rewards. For TV 5, I reworded the first quiz question.

```(.order (kwc .sum (= (getl ts (ssi sb (>= \$tv 4)) "choice") "I") :level "sn"))
```
sn choice
s049 2
s046 17
s048 18
s047 32
s044 33
s045 33
s042 36
s043 42
```(rd 2 (.quantile
(kwc .mean (= (getl ts (ssi sb (>= \$tv 4)) "choice") "I") :level "sn")
[.25 .5 .75]))
```
I value
0.25 0.30
0.50 0.54
0.75 0.56
```(learn-scatter (ssi sb (.isin \$tv [4 5])))
```

Here, black dots are I choices and white dots are D choices.

## TV 6

Same as TV 5, but with real rewards again.

```(.order (kwc .sum (= (getl ts (ssi sb (= \$tv 6)) "choice") "I") :level "sn"))
```
sn choice
s054 1
s057 2
s055 8
s060 22
s050 24
s052 25
s059 27
s053 32
s058 36
s062 36
s051 39
```(rd 2 (.quantile
(kwc .mean (= (getl ts (ssi sb (= \$tv 6)) "choice") "I") :level "sn")
[.25 .5 .75]))
```
I value
0.25 0.25
0.50 0.42
0.75 0.57

Maybe a little less than TV 5, but not bad.

```(learn-scatter (ssi sb (= \$tv 6)))
```

## TV 7

Now we're randomly assigning all 4 conditions.

Choices of I after D has become available:

```(setv v (kwc .sum :level "sn" (wc
(getl ts (ssi sb (.isin \$tv [7 8 9])))
(& (> \$rt \$dwait) (= \$choice "I")))))
(kwc .sort-values :!ascending (get v (> v 0)))
```
sn value
s081 30
s095 14
s164 11
s160 8
s222 8
s245 7
s080 7
s147 6
s082 6
s244 5
s123 5
s214 4
s102 4
s237 4
s242 4
s161 4
s097 3
s088 3
s234 3
s104 2
s107 2
s127 2
s134 2
s143 2
s151 2
s165 2
s182 2
s209 2
s066 2
s152 1
s158 1
s068 1
s071 1
s077 1
s243 1
s235 1
s233 1
s083 1
s232 1
s093 1
s230 1
s220 1
s100 1
s218 1
s216 1
s105 1
s181 1
s178 1
s207 1
s200 1
s128 1
s130 1
s133 1
s195 1
s138 1
s139 1
s140 1
s142 1
s190 1
s184 1
s114 1

Let's exclude subjects who made 3 or more such errors.

```(setv s-late (. (get v (>= v 3)) index))
(setv s-good (sorted (- (set (ssi sb (.isin \$tv [7 8 9]))) (set s-late))))
(valcounts (getl sb s-good "cond"))
```
I cond
control 37
across_force_d 41
within_pattern 39
across_pattern 41

The number of subjects who got each possible number of quiz questions wrong:

```(valcounts (pd.Series (kwc pd.Categorical
(\$ (ss sb (.isin \$tv [7 8 9])) quiz-qs-wrong)
:categories [0 1 2 3 4]
:+ordered)))
```
I value
0 94
1 48
2 29
3 3
4 3

And here's the number of subjects who got each quiz question wrong:

```(.sum (~ (getl quiz (ssi sb (.isin \$tv [7 8 9])))))
```
I value
better-amount 39
better-prob 15
immediate 33
faster-completion 40

Subjects per condition getting no quiz questions wrong and satisfying the above criteria:

```(valcounts (\$ (ss (getl sb s-good) (= \$quiz-qs-wrong 0)) cond))
```
I cond
within_pattern 20
control 21
across_force_d 21
across_pattern 23

### Plots

```(defmacro cond-trials [cond blocks trials]
`(getl ts
(ssi (getl sb s-good) (= \$cond ~cond))
~blocks
~trials))

(setv free-trials-tv7 (.sort-index (pd.concat [
(cond-trials "control" : :)
(cond-trials "within_pattern" : 1)
(cond-trials "across_pattern" (range 1 20 2) :)
(cond-trials "across_force_d" (range 1 20 2) :)])))
```

Here we have the proportion of I choices considering only free-choice trials, which are all 60 trials for control subjects, 30 trials for across-forced subjects, and 20 trials for within-forced subjects. Plots are per condition, with means marked by vertical lines.

```(defn i-prop-dotplot [cond &optional [late-only False] [perfect-quiz-only False] [diffs False]]

(setv d (getl free-trials-tv7 (ssi sb (= \$cond cond))))
(when late-only
(setv d (ss d (>= \$tt 40))))
(when perfect-quiz-only
(setv d (getl d (ssi (getl sb s-good) (= \$quiz-qs-wrong 0)))))
(setv y (if diffs
(do
(setv l (amap
(kwc .mean :level "sn" (= (\$ it "choice") "I"))
[(ss d (<= \$tt 20)) (ss d (>= \$tt 40))]))
(- (second l) (first l)))
(kwc .mean :level "sn" (= (\$ d "choice") "I"))))
(setv y (get y (!= y 0)))

(dotplot y .015)
(plt.axis [(if diffs -1.05 -.05) 1.05 0 .2])
(plt.xticks (np.arange (if diffs -1 0) 1.1 .25))
(.set-major-formatter (. (plt.gca) xaxis) (mpl.ticker.FixedFormatter
(if diffs
["-1" "-3/4" "-1/2" "-1/4" "0" "1/4" "1/2" "3/4" "1"]
(qw 0 1/4 1/2 3/4 1))))
(kwc plt.axvline (.mean y) :color "red")
(setv bounds
(try
(scikits.bootstrap.ci y np.mean)
(catch [_ IndexError]
(kwc scikits.bootstrap.ci y np.mean :method "pi"))))
(for [bound bounds]
(kwc plt.axvline bound :color "blue" :linestyle "--")))

(i-prop-dotplot "control")
```
```(i-prop-dotplot "within_pattern")
```
```(i-prop-dotplot "across_pattern")
```
```(i-prop-dotplot "across_force_d")
```

#### Difference from first to last third

```(kwc i-prop-dotplot "control" :+diffs)
```
```(kwc i-prop-dotplot "within_pattern" :+diffs)
```
```(kwc i-prop-dotplot "across_pattern" :+diffs)
```
```(kwc i-prop-dotplot "across_force_d" :+diffs)
```

The one median that's nonzero (for the control condition) is on the wrong side, since positive numbers mean more I choices in the last third of the task.

#### Last third only

```(kwc i-prop-dotplot "control" :+late-only)
```
```(kwc i-prop-dotplot "within_pattern" :+late-only)
```
```(kwc i-prop-dotplot "across_pattern" :+late-only)
```
```(kwc i-prop-dotplot "across_force_d" :+late-only)
```

## References

Luhmann, C. C., Ishida, K., & Hajcak, G. (2011). Intolerance of uncertainty and decisions about delayed, probabilistic rewards. Behavior Therapy, 42, 378–386. doi:10.1016/j.beth.2010.09.002. Retrieved from http://www.psychology.stonybrook.edu/cluhmann-/papers/luhmann-2011-bt.pdf