The wordbankr package allows you to access data in the Wordbank database from R. This vignette shows some examples of how to use the data loading functions and what the resulting data look like.

There are three different data views that you can pull out of Wordbank: by-administration, by-item, and administration-by-item.

The get_administration_data function gives by-administration information, for either a specific language and form or for all instruments:

english_ws_admins <- get_administration_data("English", "WS")
head(english_ws_admins)
## Source: local data frame [6 x 10]
## 
##   data_id   age comprehension production language  form birth_order
##     (dbl) (int)         (int)      (int)    (chr) (chr)      (fctr)
## 1       1    24           337        337  English    WS       First
## 2       2    19           384        384  English    WS      Second
## 3       3    24            76         76  English    WS       First
## 4       4    18            19         19  English    WS       First
## 5       5    24           480        480  English    WS       First
## 6       6    19           313        313  English    WS       First
## Variables not shown: ethnicity (fctr), sex (fctr), mom_ed (fctr)
all_admins <- get_administration_data()
head(all_admins)
## Source: local data frame [6 x 10]
## 
##   data_id   age comprehension production language  form birth_order
##     (dbl) (int)         (int)      (int)    (chr) (chr)      (fctr)
## 1       1    24           337        337  English    WS       First
## 2       2    19           384        384  English    WS      Second
## 3       3    24            76         76  English    WS       First
## 4       4    18            19         19  English    WS       First
## 5       5    24           480        480  English    WS       First
## 6       6    19           313        313  English    WS       First
## Variables not shown: ethnicity (fctr), sex (fctr), mom_ed (fctr)

The get_item_data function gives by-item information, for either a specific language and form or for all instruments:

spanish_wg_items <- get_item_data("Spanish", "WG")
head(spanish_wg_items)
## Source: local data frame [6 x 11]
## 
##   item_id definition language  form  type category lexical_category
##     (chr)      (chr)    (chr) (chr) (chr)    (chr)            (chr)
## 1  item_1         am  Spanish    WG  word   sounds            other
## 2  item_2         ay  Spanish    WG  word   sounds            other
## 3  item_3     beemee  Spanish    WG  word   sounds            other
## 4  item_4     cuacua  Spanish    WG  word   sounds            other
## 5  item_5     guagua  Spanish    WG  word   sounds            other
## 6  item_6       miau  Spanish    WG  word   sounds            other
## Variables not shown: lexical_class (chr), uni_lemma (chr),
##   complexity_category (chr), num_item_id (dbl)
all_items <- get_item_data()
head(all_items)
## Source: local data frame [6 x 11]
## 
##   item_id       definition              language  form    type category
##     (chr)            (chr)                 (chr) (chr)   (chr)    (chr)
## 1  item_1       be careful British Sign Language    WG phrases       NA
## 2  item_2         bring me British Sign Language    WG phrases       NA
## 3  item_3     change nappy British Sign Language    WG phrases       NA
## 4  item_4        come here British Sign Language    WG phrases       NA
## 5  item_5 daddy/mummy home British Sign Language    WG phrases       NA
## 6  item_6        donttouch British Sign Language    WG phrases       NA
## Variables not shown: lexical_category (chr), lexical_class (chr),
##   uni_lemma (chr), complexity_category (chr), num_item_id (dbl)

If you are only looking at total vocabulary size, admins is all you need, since it has both productive and receptive vocabulary sizes calculated. If you are looking at specific items or subsets of items, you need to load instrument data, using the get_instrument_data function. Pass it an instrument language and form, along with a list of items you want to extract (by item_id).

eng_ws_canines <- get_instrument_data(instrument_language = "English",
                                      instrument_form = "WS",
                                      items = c("item_26", "item_46"))
head(eng_ws_canines)
## Source: local data frame [6 x 3]
## 
##   data_id    value num_item_id
##     (dbl)    (chr)       (dbl)
## 1       1 produces          26
## 2       2 produces          26
## 3       3 produces          26
## 4       4 produces          26
## 5       5 produces          26
## 6       6 produces          26

By default get_instrument_table returns a data frame with columns of the administration’s data_id, the item’s num_item_id (numerical item_id), and the corresponding value. To include administration information, you can set the administrations argument to TRUE, or pass the result of get_administration_data as administrations (that way you can prevent the administration data from being loaded multiple times). Similarly, you can set the iteminfo argument to TRUE, or pass it result of get_item_data.

Loading the data is fast if you need only a handful of items, but the time scales about linearly with the number of items, and can get quite slow if you need many or all of them. So, it’s a good idea to filter down to only the items you need before calling get_instrument_data.

As an example, let’s say we want to look at the production of animal words on English Words & Sentences over age. First we get the items we want:

animals <- get_item_data("English", "WS") %>%
  filter(category == "animals")

Then we get the instrument data for those items:

animal_data <- get_instrument_data(instrument_language = "English",
                                   instrument_form = "WS",
                                   items = animals$item_id,
                                   administrations = english_ws_admins)

Finally, we calculate how many animals words each child produces and the median number of animals of each age bin:

animal_summary <- animal_data %>%
  mutate(produces = value == "produces") %>%
  group_by(age, data_id) %>%
  summarise(num_animals = sum(produces, na.rm = TRUE)) %>%
  group_by(age) %>%
  summarise(median_num_animals = median(num_animals, na.rm = TRUE))
  
ggplot(animal_summary, aes(x = age, y = median_num_animals)) +
  geom_point()