# Recall order¶

A key advantage of free recall is that it provides information not only about what items are recalled, but also the order in which they are recalled. A number of analyses have been developed to charactize different influences on recall order, such as the temporal order in which the items were presented at study, the category of the items themselves, or the semantic similarity between pairs of items.

Each conditional response probability (CRP) analysis involves calculating the probability of some type of transition event. For the lag-CRP analysis, transition events of interest are the different lags between serial positions of items recalled adjacent to one another. Similar analyses focus not on the serial position in which items are presented, but the properties of the items themselves. A semantic-CRP analysis calculates the probability of transitions between items in different semantic relatedness bins. A special case of this analysis is when item pairs are placed into one of two bins, depending on whether they are in the same stimulus category or not. In Psifr, this is referred to as a category-CRP analysis.

## Lag-CRP¶

In all CRP analyses, transition probabilities are calculated conditional on a given transition being available. For example, in a six-item list, if the items 6, 1, and 4 have been recalled, then possible items that could have been recalled next are 2, 3, or 5; therefore, possible lags at that point in the recall sequence are -2, -1, or +1. The number of actual transitions observed for each lag is divided by the number of times that lag was possible, to obtain the CRP for each lag.

First, load some sample data and create a merged DataFrame:

```
In [1]: from psifr import fr
In [2]: df = fr.sample_data('Morton2013')
In [3]: data = fr.merge_free_recall(df, study_keys=['category'])
```

Next, call `lag_crp()`

to calculate conditional response
probability as a function of lag.

```
In [4]: crp = fr.lag_crp(data)
In [5]: crp
Out[5]:
prob actual possible
subject lag
1 -23.0 0.020833 1 48
-22.0 0.035714 3 84
-21.0 0.026316 3 114
-20.0 0.024000 3 125
-19.0 0.014388 2 139
... ... ... ...
47 19.0 0.061224 3 49
20.0 0.055556 2 36
21.0 0.045455 1 22
22.0 0.071429 1 14
23.0 0.000000 0 6
[1880 rows x 3 columns]
```

The results show the count of times a given transition actually happened
in the observed recall sequences (`actual`

) and the number of times a
transition could have occurred (`possible`

). Finally, the `prob`

column
gives the estimated probability of a given transition occurring, calculated
by dividing the actual count by the possible count.

Use `plot_lag_crp()`

to display the results:

```
In [6]: g = fr.plot_lag_crp(crp)
```

The peaks at small lags (e.g., +1 and -1) indicate that the recall sequences show evidence of a temporal contiguity effect; that is, items presented near to one another in the list are more likely to be recalled successively than items that are distant from one another in the list.

## Lag rank¶

We can summarize the tendency to group together nearby items using a lag rank analysis. For each recall, this determines the absolute lag of all remaining items available for recall and then calculates their percentile rank. Then the rank of the actual transition made is taken, scaled to vary between 0 (furthest item chosen) and 1 (nearest item chosen). Chance clustering will be 0.5; clustering above that value is evidence of a temporal contiguity effect.

```
In [7]: ranks = fr.lag_rank(data)
In [8]: ranks
Out[8]:
rank
subject
1 0.610953
2 0.635676
3 0.612607
4 0.667090
5 0.643923
... ...
43 0.554024
44 0.561005
45 0.598151
46 0.652748
47 0.621245
[40 rows x 1 columns]
In [9]: ranks.agg(['mean', 'sem'])
Out[9]:
rank
mean 0.624699
sem 0.006732
```

## Category CRP¶

If there are multiple categories or conditions of trials in a list, we can test whether participants tend to successively recall items from the same category. The category-CRP estimates the probability of successively recalling two items from the same category.

```
In [10]: cat_crp = fr.category_crp(data, category_key='category')
In [11]: cat_crp
Out[11]:
prob actual possible
subject
1 0.801147 419 523
2 0.733456 399 544
3 0.763158 377 494
4 0.814882 449 551
5 0.877273 579 660
... ... ... ...
43 0.809187 458 566
44 0.744376 364 489
45 0.763780 388 508
46 0.763573 436 571
47 0.806907 514 637
[40 rows x 3 columns]
In [12]: cat_crp[['prob']].agg(['mean', 'sem'])
Out[12]:
prob
mean 0.782693
sem 0.006262
```

The expected probability due to chance depends on the number of categories in the list. In this case, there are three categories, so a category CRP of 0.33 would be predicted if recalls were sampled randomly from the list.