# Bayesian hierarchical model of working-memory capacity

Working memory (WM) is the name of the memory system that stores information for time periods in the order of seconds (see Baddeley & Hitch, 1974; Cowan, 2001). WM is considered to be limited both in terms of duration (how long information is stored) and capacity (how much information is stored). The nature of WM capacity limitation is a source of current debate, with some researchers arguing for “item-based” storage (WM stores up to a fixed number of discrete perceptual objects; e.g, Luck & Vogel, 1997; Rouder et al., 2008), and others advocating “resource-based” storage (storage is allocated flexibly depending on the stimulus; e.g., Bays & Hussain, 2008; Keshvari et al., 2013). However, item-based storage has long been the dominant view, and the average number of items stored in WM, denoted , remains a popular dependent variable in the cognitive sciences.

A simple way of measuring is to apply either of the formulae proposed by Pashler (1988) and Cowan (2001) to the data from a change-detection task. On each trial, the subject is briefly presented with a stimulus containing several distinct items, and after a few seconds, a second stimulus is presented. The second stimulus contains at least one item from the original stimulus (the “probed” item), which may or may not have changed in some way, and the subject indicates whether a change occurred. The choice of formula depends on whether the second stimulus also contains the remaining items from the original stimulus: if so, Pashler’s formula should be used; if not, Cowan’s should be used.

These formulae are easy to implement and widely used, but there are a number problems with them. First, using these formulae, can only be calculated from trials with the same set size; experiments typically use various set sizes, so estimates of must be calculated separately for each set size and then combined, rather than calculating one estimate from all the data. Second, since can never exceed the set size, it is systematically underestimated whenever the set size is smaller than the true . Third, the formulae can yield impossible (negative) values of . Fourth, cannot be calculated at all when performance is at ceiling or floor.

To remedy these issues, Morey (2011) formalised a Bayesian hierarchical model for the measurement of WM capacity from change-detection tasks. The model largely deals with the problems listed above, and is much more efficient (it recovers parameters more accurately) than traditional approaches when the data are few. I have implemented a version of this model in PyMC 3 (Salvatier, Wiecki, & Fonnesbeck, 2016). Since it isn’t *exactly* the same as the model described by Morey—who provides his own software (Morey & Morey, 2011)—I describe its logic in detail below. My version is a bit simpler than Morey’s, since it doesn’t explicitly model the covariance between parameters, and only applies to the Cowan style of change-detection tasks. It should be easy to modify the code to apply to Pashler-style tasks, or indeed any other variation, provided the decision rule can be specified.

## The model

In a similar way to signal detection theory (SDT), the model uses the number of hits (correct indication of a stimulus change), , and the number of false alarms (incorrect indication of a stimulus change), . These are binomial random variables with the probability distributions

where is the hit probability, is the number of change trials, is the false-alarm probability, is the number of no-change trials, indexes the subject, and indexes the set size.

Again like SDT, and are determined by a decision process incorporating latent variables with clear psychological interpretations. The decision process is different, however. The model assumes that with probability , the subject stores items from the stimulus in WM. If the probed item is one of these stored items, the subject responds correctly with a probability of 1. If the probed item is not stored, the subject guesses “change” with probability . On the remaining trials (), the subject suffers an attentional lapse, storing none of the items in memory, and again guessing “change” with probability (see Rouder et al., 2008).

The relationships between the response probabilities ( and ) and the latent variables (, , and ) can be determined easily by considering the all the possible outcomes of a trial in the experiment and determining their associated probabilities. Those are summarised graphically as follows:

Here, represents the probability that the probed item was stored on a given trial. Assuming all items are equally likely to be stored, this is 1 if , where is the set size, or if . Next, and are found by combining the appropriate paths, leading to

where

It is generally a good idea to do inference on normally distributed variables. However, cannot be normal, because negative values of are not possible; and neither can nor , because they are probabilities. Therefore, we let

These comprise the first level of unknown random variables in the hierarchical model. We could assign them normal prior distributions, as Morey (2011) does. However, to make the model more robust to outliers (see Kruschke, 2012), I have assigned them non-central student priors:

where are the degrees-of-freedom parameters, are the mean parameters, and are the standard-deviation parameters. Notice the index on , and the lack thereof on and . We next place linear models on , which we can write in vector form as follows:

where are subject-by-predictor design matrices and are vectors of coefficients, one for each predictor (column) in the design matrix.

All that’s left to do is assign hyperpriors to the parameters denoted by , , and . For , a shifted-exponential distribution is a good choice:

For , recent papers recommend a half-Cauchy distribution (Gelman, 2006; Polson & Scott, 2012):

Finally, we will assign normal hyperpriors to each of the coefficients:

where indexes the covariate.

## PyMC 3 code

## References

Banner image is *La persistencia de la memoria* by Salvador Dali.

- Baddeley, A. D., & Hitch, G. (1974). Working memory. In G.H. Bower (Ed.),
*The psychology of learning and motivation: Advances in research and theory*(Vol. 8, pp. 47–89). New York: Academic Press. - Cowan, N. (2001). The magic number 4 in short-term memory: A reconsideration of mental storage capacity.
*Behavioral and Brain Sciences*, 24, 87–114. - Gelman, A. (2006). Prior distributions for variance parameters in hierarchical models.
*Bayesian Analysis*, 1, 515–533. - Keshvari, S., van den Berg, R., & Ma, W. J. (2013). No evidence for an item limit in change detection.
*PLoS Computational Biology*, 9, e1002927. - Kruschke, J. K. (2012). Bayesian estimation supersedes the t test.
*Journal of Experimental Psychology: General*, 142, 573–603. - Luck, S. J., & Vogel, E. K. (1997). The capacity of visual working memory for features and conjunctions.
*Nature*, 390, 279–281. - Morey, R. D. (2011). A Bayesian hierarchical model for the measurement of working memory capacity.
*Journal of Mathematical Psychology*, 55, 8–24 - Morey, R. D., & Morey, C. C. (2011). WoMMBAT: A user interface for hierarchical Bayesian estimation of working memory capacity.
*Behavior Research Methods*, 43, 1044–1065. - Pashler, H. (1988). Familiarity and visual change detection.
*Perception & Psychophysics*, 44, 369–378. - Polson, N. G., & Scott, S. G. (2012). On the half-Cauchy prior for a global scale parameter.
*Bayesian Analysis*, 7, 887–902. - Rouder, J. N., Morey, R. D., Cowan, N., Zwilling, C. E., Morey, C. C., & Pratte, M. S. (2008). An assessment of fixed-capacity models of visual working memory.
*Proceedings of the National Academy of Sciences*, 105, 5976–5979. - Salvatier, J., Wiecki, T. V., & Fonnesbeck, C. (2016). Probabilistic programming in Python using PyMC3.
*PeerJ Computer Science*, 2:e55.