Learn R Programming

Politeness

Politeness is a universal dimension of langauge (Lakoff, 1973; Brown & Levinson, 1987). In practically all communication, a speaker can choose to be more or less polite to their audience. In this package, we provide tools for researchers to measure the markers and effects of politeness in natural language.

Installation

You can install politeness directly, like so:

 install.packages("politeness")

Many of the politeness features containted in this package use dependency parsing. We rely on the popular python library SpaCy, which is simple to install, although the procedure can vary for different machines. Our software depends on a convenient wrapper function, spacyr, that also includes several intallation tools. If you do not have SpaCy installed, a reduced set of features is provided (i.e. those that do not require dependency tags) but this only recommended for initial tests, rather than final analyses.

Please confirm that your machine can run SpaCy and spacyr first! This step can be difficult for some machines, and we defer to the existing documentation for that software as a guide.

Citation

If you find this package useful, please cite us, using the following reference from our R Journal publication.

Yeomans, M., Kantor, A. & Tingley, D. (2018). Detecting Politeness in Natural Language. The R Journal, 10(2), 489-502.

Note that this publication was written using a very early version (0.2.4) of the package. For the most up-to-date description of the functionality, please see the vignette in this repository.

Example

In the package we have included a dataset, phone_offers. It was collected from an experiment in which participants were told to write offers asking to buy a smartphone from a seller on Craigslist. We randomly manipulated their instructions so that their task was to write in a warm or tough style. The dataset includes the text of their messages, as well as the condition assignment.

data("phone_offers")

politeness::politeness(phone_offers$message)

# install.packages("spacyr")
#spacyr::spacy_initialize(python_executable = "PYTHON_PATH")
#politeness::politeness(phone_offers$message, parser="spacy")

politeness::politenessPlot(politeness::politeness(phone_offers$message),
                           split=phone_offers$condition,
                           split_levels = c("Warm","Tough"),
                           split_name = "Condition")

Copy Link

Version

Install

install.packages('politeness')

Monthly Downloads

411

Version

0.9.4

License

MIT + file LICENSE

Maintainer

Mike Yeomans

Last Published

March 10th, 2025

Functions in politeness (0.9.4)

cleanpunct

Cleaning weird encodings
politenessDNM

Politeness Features
politenessPlot

Politeness plot
exampleTexts

Find polite text
politenessProjection

Politeness projection
politenessModel

Pre-Trained Politeness Classifier
receptive_polite

Pre-Trained Receptiveness Data
findPoliteTexts

Find polite text
receptive_train

Pre-Trained Receptiveness Data
cleantext

Clean Text
ctxpand

Contraction Expander
receptiveness

Conversational Receptiveness
spacyParser

Spacy Parser
foldset

Fold Assignment for Cross-Validation
slogodds

Variance-Weighted Log Odds
textcounter

Text Counter
trainModel

Train a model with politeness features
uk2us

UK to US Conversion dictionary
usWords

UK to US conversion
modelPlot

LASSO Coefficient Plot
receptive_names

This is the list of variables to be extracted for the receptiveness algorithm For internal use only, within the receptiveness() function.
receptive_model

A pre-trained model for detecting conversational receptiveness. Estimated with glmnet using annotated data from a previous paper. Primarily for use within the receptiveness() function.
getTokenSets

Extracting Tokens from Natural Language
feature_table

Table of Politeness Features
featurePlot

Feature plot
politeness

Politeness Features
polite_train

Pre-Trained Politeness
noLeadDash

Cleaning leading punctuation
bowl_offers

Purchase offers for bowl
phone_offers

#' Positive Emotions List #' #' Positive words. #' #' @format A list of 2006 positively-valenced words #' "positive_list"
dictWrap

Dictionary Wrapper