rrrsa is an R package for running RSA models -- Bayesian models of pragmatic inference. rrrsa was created by Ben Peloquin in collaboration with Michael C. Frank and has been optimized for analysis of experimental data such as those presented in Frank, et al. (Under Review) and Peloquin & Frank (2016). For other, more flexible variants of RSA models, please see http://forestdb.org/models/scalar-implicature.html.
You can install the latest version of rrrsa by installing devtools and running:
install.packages("devtools")
devtools::install_github("benpeloquin7/rrrsa")
Rational speech act (RSA) models frame language understanding as a special case of social cognition in which speakers and listeners reason about one another recursively. A pragmatic listener rational speaker
Data from "Rational speech act models of pragmatic reasoning in reference games" (Frank, et al., Under Reivew) and "Determining the alternatives in scalar implicature" (Peloquin & Frank, 2016) are also included in this package. Examples using data from these studies are included below.
rrrsa provides users with access to all model components. The following sections demonstrate how this functionality can be used.
rsa.informativity() takes three arguments, literal semantics alpha level (default 1), and cost (default 0). This function returns the surprisal of an utterance minus cost, multiplied by alpha.
rsa.utility takes an input vector of literal listener semantics and outputs a normalized vector of speaker likelihoods. If costs are not specified the default 0's vector is used. If alpha is not specified a default value of
In the RSA framework one full recursion consists of a pragmatic listner rational speaker literal listener literal listener values in which columns corresond to items (words) and rows correspond to semantic quantity (stars in Peloquin & Frank, under review). Optional arguments include a costs vector which whould be the same length as ncol and an optional priors vector which should the same length as nrows. rsa.fullRecursion provides safety checking for these cases. Output corresponds with pragmatic listener posterior predictions.
rsa.reason is really a wrapper function for rsa.fullRecursion which provides an additional depth parameter which specifies the recursive depth during reasoning. If depth is not provided, default value is
Run RSA on a tidied data frame and avoid running individual model components individually with rsa.runDf. An RSA-ready, tidied data frame must contian columns for semantic quantity, item and semantics, where each row corresponds with unique item/quantity combination. A user should specify their naming convention for these items in the quantityVarName, itemVarName and semanticsVarName arguments. The costVarName and priorsVarName args correspond with costs and/or priors data. Users can specify values for alpha and depth hyperparamenters. runDf will return a data frame with a new model predictions preds column appended.
For more specific examples of rrrsa and example analysis using data from Frank, et al. (Under Review) and Peloquin & Frank (2016) please see:
vignette("summary", package="rrrsa")