Skip to content

Repository files navigation

LexOPS

Lifecycle: stableVersion: 0.4.0DOI: 10.3758/s13428-020-01389-1

LexOPS is an R package for generating matched stimuli for factorial design experiments. You can use the functions on any dataframe, but there is an inbuilt database of example features for English words for psycholinguistics studies in English (LexOPS::lexops).

Installation

LexOPS can be installed as an R package with:

devtools::install_github("JackEdTaylor/LexOPS@*release")

How to Use

📖 In-depth walkthrough of the package: https://jackedtaylor.github.io/LexOPSdocs/

🎓 Paper about the package: Taylor, Beith, and Sereno (2020)

TL;DR

LexOPS makes it easy to generate matched stimuli in a reproducible way. The functions work on any dataframe, but there is an inbuilt dataset, LexOPS::lexops, containing psycholinguistic variables for English words.

The “Generate Pipeline”

The following example pipeline generates 50 words per condition (200 in total), for a study with a 2 x 2, syllables (1, 2) by concreteness (low, high) design. Words are matched by length exactly, and by word frequency within a tolerance of ±0.2 Zipf.

library(LexOPS)
stim<-lexops|>
split_by(Syllables.CMU, 1:1~2:2) |>
split_by(CNC.Brysbaert, 1:2~4:5) |>
control_for(Zipf.SUBTLEX_UK, -0.2:0.2) |>
control_for(Length) |>
generate(n=50, match_null="balanced")
#> Generated 50/50 (100%). 157 total iterations, 0.32 success rate.

A preview of what was generated:

# create a table of the first 5 rows of the outputstim|>
head(5) |>knitr::kable()
item_nrA1_B1A1_B2A2_B1A2_B2match_null
1gistyankiffytofuA1_B2
2oomphspeckhyperrabbiA2_B1
3worstvoiceluckycoverA1_B1
4suavestoopavaillilacA2_B2
5shrewdstarchbygonecondomA2_B1

Review Generated Stimuli

The plot_design() function produces a plot summarising the generated stimuli.

plot_design(stim)

Convert to Long Format

The long_format() function coerces the generated stimuli into long format.

# present the same 20 words as in the earlier table
long_format(stim) |>
head(20) |>knitr::kable()
item_nrconditionmatch_nullstringZipf.SUBTLEX_UKLengthSyllables.CMUCNC.Brysbaert
1A1_B1A1_B2gist2.974489411.81
1A1_B2A1_B2yank2.933782414.10
1A2_B1A1_B2iffy2.928732421.68
1A2_B2A1_B2tofu3.045984424.86
2A1_B1A2_B1oomph3.074134511.52
2A1_B2A2_B1speck3.011706514.46
2A2_B1A2_B1hyper3.208953522.00
2A2_B2A2_B1rabbi3.315872524.64
3A1_B1A1_B1worst4.915294511.54
3A1_B2A1_B1voice4.887075514.13
3A2_B1A1_B1lucky5.030973521.76
3A2_B2A1_B1cover4.863260524.23
4A1_B1A2_B2suave2.910580511.48
4A1_B2A2_B2stoop3.045984514.63
4A2_B1A2_B2avail2.877579521.33
4A2_B2A2_B2lilac3.017955524.69
5A1_B1A2_B1shrewd3.244739611.92
5A1_B2A2_B1starch3.291232614.29
5A2_B1A2_B1bygone3.091935621.69
5A2_B2A2_B1condom3.225935624.87

Shiny App

The package has an interactive shiny app, which supports most code functionality, with useful additional features like visualising distributions and relationships. It’s a friendly front-end to the package’s functions. A demo version of the LexOPS shiny app is available online at https://jackt.shinyapps.io/lexops/, but it is faster and more reliable to run it locally, with:

LexOPS::run_shiny()

Matching on Custom Dataframes

As well as the built-in dataframe LexOPS::lexops, you can generate matches from any dataframe object.

Here is an example using mtcars. We pick five automatic and five manual models of car, matched for acceleration (within ±5 qsec) and the number of carburetor barrels (carb; exactly).

mtcars|>tibble::as_tibble(rownames="car_id") |>
set_options(id_col="car_id") |>
split_by(am, 0:0~1:1) |>
control_for(qsec, -5:5) |>
control_for(carb, 0:0) |>
generate(5)
#> item_nr A1 A2 match_null
#> 1 1 Merc 280 Ford Pantera L A2
#> 2 2 Merc 230 Volvo 142E A1
#> 3 3 Hornet Sportabout Porsche 914-2 A1
#> 4 4 Cadillac Fleetwood Mazda RX4 A1
#> 5 5 Dodge Challenger Honda Civic A2

About

An R Package and Shiny App for generating matched stimuli for factiorial-design experiments.

Topics

Resources

Stars

29 stars

Watchers

7 watching

Forks

Releases

Packages

Contributors

Languages